本文整理汇总了Python中pybvc.openflowdev.ofswitch.OFSwitch类的典型用法代码示例。如果您正苦于以下问题:Python OFSwitch类的具体用法?Python OFSwitch怎么用?Python OFSwitch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OFSwitch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: of_demo_3
def of_demo_3():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 3 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("\n")
print ("<<< Creating Controller instance")
time.sleep(rundelay)
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd, None)
print ("'Controller':")
print ctrl.brief_json()
print ("\n")
print ("<<< Get detailed information about ports on OpenFlow node '%s'"
% nodeName)
time.sleep(rundelay)
ofswitch = OFSwitch(ctrl, nodeName)
result = ofswitch.get_ports_list()
status = result.get_status()
if(status.eq(STATUS.OK)):
ports = result.get_data()
for port in ports:
result = ofswitch.get_port_detail_info(port)
status = result.get_status()
if(status.eq(STATUS.OK)):
print ("Port '%s' info:" % port)
info = result.get_data()
print json.dumps(info, indent=4)
else:
print ("\n")
print ("!!!Demo terminated, reason: %s"
% status.brief().lower())
exit(0)
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
exit(0)
print ("\n")
print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print (">>> Demo End")
print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例2: clear_flow
def clear_flow(self, options):
parser = argparse.ArgumentParser(
prog=self.prog,
description='Clear OpenFlow flows',
usage="%(prog)s clear-flow -s=SWITCHID|--switch=SWICTHID\n"
" -t=TABLEID|--table=TABLEID\n"
" [-f=FLOWID|--flow=FLOWID]\n"
"\n\n"
"Clear cached flows on the Controller\n\n"
"\n\n"
"Options:\n"
" -s, --switch switch identifier\n"
" -t, --table flow table id\n"
" -f, --flow flow id\n"
)
parser.add_argument('-s', '--switch', metavar = "SWITCHID")
parser.add_argument('-t', '--table', metavar = "TABLEID",
type=self.positive_int)
parser.add_argument('-f', '--flow', metavar = "FLOWID")
parser.add_argument('-U', action="store_true", dest="usage",
help=argparse.SUPPRESS)
args = parser.parse_args(options)
if(args.usage):
parser.print_usage()
print "\n".strip()
return
if (args.switch == None):
msg = "option -s (or --switch) is required"
parser.error(msg)
if (args.table == None):
msg = "option -t (or --table) is required"
parser.error(msg)
print "\n".strip()
print " [Controller '%s']" % self.ctrl_cfg.to_string()
ctrl = Controller(self.ctrl_cfg.ip_addr, self.ctrl_cfg.tcp_port,
self.ctrl_cfg.admin_name, self.ctrl_cfg.admin_pswd)
ofswitch = OFSwitch(ctrl, args.switch)
if(args.flow != None):
result = ofswitch.delete_flow(args.table, args.flow)
else:
result = ofswitch.delete_flows(args.table)
status = result.get_status()
print "\n".strip()
print "%s" % status.detailed()
print "\n".strip()
示例3: show_table
def show_table(self, table_id, oper, ofp):
flow_entries = []
ofswitch = OFSwitch(self.ctrl, self.switchid)
if oper:
result = ofswitch.get_operational_FlowEntries(table_id)
else:
result = ofswitch.get_configured_FlowEntries(table_id)
status = result.get_status()
if(status.eq(STATUS.OK) == True):
data = result.get_data()
flow_entries = sorted(data, key=lambda fe: fe.get_flow_priority())
elif(status.eq(STATUS.DATA_NOT_FOUND)):
print "\n".strip()
print " Requested data not found"
print "\n".strip()
exit(0)
else:
print ("\n")
print ("!!!Error, reason: %s" % status.brief().lower())
exit(0)
print "\n".strip()
s = "Device Operational" if oper else "Controller Cached"
print " Switch '%s' - %s Flows" % (self.switchid, s)
print "\n".strip()
if len(flow_entries) > 0:
for flow_entry in flow_entries:
assert(isinstance(flow_entry, FlowEntry))
if(ofp):
print " -- Flow id '%s'" % flow_entry.get_flow_id()
print " %s" % flow_entry.to_ofp_oxm_syntax()
else:
lines = flow_entry.to_yang_json(strip=True).split('\n')
for line in lines:
print " %s" % line
else:
print " No flows found"
print "\n".strip()
示例4: print
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
rundelay = 5
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Type
# IP DSCP
# IP ECN
# IPv6 Source Address
# IPv6 Destination Address
# IPv6 Flow Label
# ICMPv6 type
# ICMPv6 Code
# Metadata
eth_type = ETH_TYPE_IPv6
ip_dscp = IP_DSCP_CS7 # 'Class Selector' = 'Network'
ip_ecn = IP_ECN_CE # 'Congestion Encountered'
ipv6_src = "1234:5678:9ABC:DEF0:FDCD:A987:6543:210F/76"
ipv6_dst = "2000:2abc:edff:fe00::3456/94"
示例5: of_demo_34
def of_demo_34():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
openflow_node_ids = []
openflow_nodes = []
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 34 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
print "\n".strip()
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'"
% (ctrlIpAddr, nodeName))
grp_ids_cfg = []
grp_ids_oper = []
print "\n".strip()
print ("<<< Get OpenFlow Groups Information")
time.sleep(rundelay)
result = ofswitch.get_configured_group_ids()
status = result.get_status()
if(status.eq(STATUS.OK)):
grp_ids_cfg = result.get_data()
elif(status.eq(STATUS.DATA_NOT_FOUND)):
grp_ids_cfg = []
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.detailed())
exit(0)
result = ofswitch.get_operational_group_ids()
status = result.get_status()
if(status.eq(STATUS.OK)):
grp_ids_oper = result.get_data()
elif(status.eq(STATUS.DATA_NOT_FOUND)):
grp_ids_oper = []
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.detailed())
exit(0)
# Show current state of the Group Table in the Controller's
# configuration and operational data stores
print_groups(grp_ids_cfg, grp_ids_oper)
# Create new group
group_id = 13
group_type = OFPGT_SELECT
group_name = "Example of 'load balancing' group"
weight1 = 60
weight2 = 30
weight3 = 10
out_port1 = 110
out_port2 = 111
out_port3 = 112
print "\n".strip()
print ("<<< Create Group")
print "\n".strip()
print (" Group Type : %s\n"
" Group ID : %s\n"
" Group Name : \"%s\"" % (group_type.strip('group-').upper(),
group_id, group_name))
print (" Buckets :")
print (" [0] weight : %s"
% weight1)
print (" actions: Output (%s)"
% out_port1)
print (" [1] weight : %s"
% weight2)
print (" actions: Output (%s)"
% out_port2)
print (" [2] weight : %s"
% weight3)
print (" actions: Output (%s)"
% out_port3)
time.sleep(rundelay)
#.........这里部分代码省略.........
示例6: of_demo_12
def of_demo_12():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 12 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Source Address
# Ethernet Destination Address
# ARP Operation
# ARP Source IPv4 Address
# ARP Target IPv4 Address
# ARP source hardware address
# ARP target hardware address
# NOTE: Ethernet type MUST be 2054 (0x0806) -> ARP protocol
eth_type = ETH_TYPE_ARP
eth_src = "00:ab:fe:01:03:31"
eth_dst = "ff:ff:ff:ff:ff:ff"
arp_opcode = ARP_REQUEST
arp_src_ipv4_addr = "192.168.4.1/32"
arp_tgt_ipv4_addr = "10.21.22.23/32"
arp_src_hw_addr = "12:34:56:78:98:ab"
arp_tgt_hw_addr = "fe:dc:ba:98:76:54"
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
(ctrlIpAddr, nodeName))
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Ethernet Type (%s)\n"
" Ethernet Source Address (%s)\n"
" Ethernet Destination Address (%s)\n"
" ARP Operation (%s)\n"
" ARP Source IPv4 Address (%s)\n"
" ARP Target IPv4 Address (%s)\n"
" ARP Source Hardware Address (%s)\n"
" ARP Target Hardware Address (%s)" %
(hex(eth_type), eth_src,
eth_dst, arp_opcode,
arp_src_ipv4_addr,
arp_tgt_ipv4_addr,
arp_src_hw_addr,
arp_tgt_hw_addr))
print (" Action: Output (CONTROLLER)")
time.sleep(rundelay)
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 19
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_hard_timeout(0)
flow_entry.set_flow_idle_timeout(0)
flow_entry.set_flow_priority(1010)
# --- Instruction: 'Apply-actions'
# Action: 'Output' CONTROLLER
instruction = Instruction(instruction_order=0)
action = OutputAction(order=0, port="CONTROLLER")
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)
# --- Match Fields: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# ARP Operation
# ARP Source IPv4 Address
# ARP Target IPv4 Address
# ARP Source Hardware Address
# ARP Target Hardware Address
match = Match()
match.set_eth_type(eth_type)
match.set_eth_src(eth_src)
match.set_eth_dst(eth_dst)
match.set_arp_opcode(arp_opcode)
match.set_arp_src_transport_address(arp_src_ipv4_addr)
match.set_arp_tgt_transport_address(arp_tgt_ipv4_addr)
match.set_arp_src_hw_address(arp_src_hw_addr)
match.set_arp_tgt_hw_address(arp_tgt_hw_addr)
flow_entry.add_match(match)
#.........这里部分代码省略.........
示例7: print
if status.eq(STATUS.OK) == True:
print ('OpenFlow node names (composed as "openflow:datapathid"):')
nodenames = result[1]
# for node in nodes:
# print (" %s" % node)
print json.dumps(nodenames, indent=4)
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
exit(0)
print "\n"
print ("<<< Get generic information about OpenFlow nodes")
time.sleep(rundelay)
for name in nodenames:
ofswitch = OFSwitch(ctrl, name)
result = ofswitch.get_switch_info()
status = result[0]
if status.eq(STATUS.OK) == True:
print ("'%s' info:" % name)
info = result[1]
print json.dumps(info, indent=4)
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
exit(0)
print ("\n")
print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print (">>> Demo End")
print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例8: of_demo_11
def of_demo_11():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 11 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Source Address
# Ethernet Destination Address
# IPv4 Source Address
# IPv4 Destination Address
# ICMPv4 Type
# ICMPv4 Code
# IP DSCP
# IP ECN
# Input Port
# NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol
# IP Protocol Type MUST be 1 -> ICMP
eth_type = ETH_TYPE_IPv4
eth_src = "00:00:00:11:23:ae"
eth_dst = "00:ff:20:01:1a:3d"
ipv4_src = "17.1.2.3/8"
ipv4_dst = "172.168.5.6/18"
ip_proto = IP_PROTO_ICMP
ip_dscp = IP_DSCP_CS2 # 'Class Selector' = 'Immediate'
ip_ecn = IP_ECN_CE # Congestion Encountered
icmpv4_type = 6 # Alternate Host Address
icmpv4_code = 3 # Alternate Address for Host
input_port = 10
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'"
% (ctrlIpAddr, nodeName))
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Ethernet Type (%s)\n"
" Ethernet Source Address (%s)\n"
" Ethernet Destination Address (%s)\n"
" IPv4 Source Address (%s)\n"
" IPv4 Destination Address (%s)\n"
" IP Protocol Number (%s)\n"
" IP DSCP (%s)\n"
" IP ECN (%s)\n"
" ICMPv4 Type (%s)\n"
" ICMPv4 Code (%s)\n"
" Input Port (%s)"
% (hex(eth_type), eth_src,
eth_dst, ipv4_src, ipv4_dst,
ip_proto, ip_dscp, ip_ecn,
icmpv4_type, icmpv4_code,
input_port))
print (" Action: Output (NORMAL)")
time.sleep(rundelay)
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 18
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_hard_timeout(0)
flow_entry.set_flow_idle_timeout(0)
flow_entry.set_flow_priority(1009)
# --- Instruction: 'Apply-actions'
# Action: 'Output' NORMAL
instruction = Instruction(instruction_order=0)
action = OutputAction(order=0, port="NORMAL")
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)
# --- Match Fields: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# IPv4 Source Address
# IPv4 Destination Address
# IP Protocol Number
# IP DSCP
# IP ECN
# ICMPv4 Type
#.........这里部分代码省略.........
示例9: print
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
rundelay = 5
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName))
flow_table_id = 0
flow_id_base = 12
flow_id = flow_id_base
flowEntries = []
# Sample flow entry
flow_entry = FlowEntry()
flow_entry.set_flow_cookie(6001)
flow_entry.set_flow_table_id(flow_table_id)
flow_entry.set_flow_id(flow_id)
flow_id += 1
示例10: of_demo_37
def of_demo_37():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit(0)
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 37 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
(ctrlIpAddr, nodeName))
first_flow_id = 110
# ---------------------------------------------------
# First flow entry
# ---------------------------------------------------
table_id = 0
flow_id = first_flow_id
flow_name = "Modify VLAN ID and VLAN priority example1"
priority = 600
cookie = 1000
match_in_port = 109
match_eth_type = ETH_TYPE_IPv4
match_vlan_id = 100
act_mod_vlan_id = 172
act_mod_vlan_pcp = 2
act_out_port = 112
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Input Port (%s)\n"
" Ethernet Type (%s)\n"
" VLAN ID (%s)" %
(match_in_port,
hex(match_eth_type),
match_vlan_id))
print (" Actions: Set VLAN ID (%s)\n"
" Set VLAN priority (%s)\n"
" Output (%s)" %
(act_mod_vlan_id, act_mod_vlan_pcp, act_out_port))
time.sleep(rundelay)
# Allocate a placeholder for the Flow Entry
flow_entry1 = FlowEntry()
# Generic attributes of the Flow Entry
flow_entry1.set_flow_table_id(table_id)
flow_entry1.set_flow_name(flow_name)
flow_entry1.set_flow_id(flow_id)
flow_entry1.set_flow_cookie(cookie)
flow_entry1.set_flow_priority(priority)
flow_entry1.set_flow_hard_timeout(0)
flow_entry1.set_flow_idle_timeout(0)
# Instructions/Actions for the Flow Entry
instruction = Instruction(instruction_order=0)
action_order = 0
action = SetVlanIdAction(action_order)
action.set_vid(act_mod_vlan_id)
instruction.add_apply_action(action)
action_order += 1
action = SetVlanPCPAction(action_order)
action.set_vlan_pcp(act_mod_vlan_pcp)
instruction.add_apply_action(action)
action_order += 1
action = OutputAction(action_order)
action.set_outport(act_out_port)
instruction.add_apply_action(action)
flow_entry1.add_instruction(instruction)
# Match Fields for the Flow Entry
match = Match()
match.set_in_port(match_in_port)
match.set_eth_type(match_eth_type)
match.set_vlan_id(match_vlan_id)
#.........这里部分代码省略.........
示例11: of_demo_36
def of_demo_36():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 36 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
print "\n".strip()
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
(ctrlIpAddr, nodeName))
grp_ids_cfg = []
grp_ids_oper = []
print "\n".strip()
print ("<<< Get OpenFlow Groups Information")
time.sleep(rundelay)
result = ofswitch.get_configured_group_ids()
status = result.get_status()
if(status.eq(STATUS.OK)):
grp_ids_cfg = result.get_data()
elif(status.eq(STATUS.DATA_NOT_FOUND)):
grp_ids_cfg = []
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.detailed())
exit(0)
result = ofswitch.get_operational_group_ids()
status = result.get_status()
if(status.eq(STATUS.OK)):
grp_ids_oper = result.get_data()
elif(status.eq(STATUS.DATA_NOT_FOUND)):
grp_ids_oper = []
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.detailed())
exit(0)
# Show current state of the Group Table in the Controller's
# configuration and operational data stores
print_groups(grp_ids_cfg, grp_ids_oper)
# Create new group
group_id = 15
group_type = OFPGT_FF
group_name = "Example of 'link fast failover' group"
watch_port1 = 110
watch_port2 = 111
watch_port3 = 112
out_port1 = 110
out_port2 = 111
out_port3 = 112
print "\n".strip()
print ("<<< Create Group")
print "\n".strip()
print (" Group Type : %s\n"
" Group ID : %s\n"
" Group Name : \"%s\"" %
(group_type.strip('group-').upper(),
group_id, group_name))
print (" Buckets :")
print (" [0] watch-port: %s" %
watch_port1)
print (" actions: Output (%s)" %
out_port1)
print (" [1] watch-port: %s" %
watch_port2)
print (" actions: Output (%s)" %
out_port2)
print (" [2] watch-port: %s" %
watch_port3)
print (" actions: Output (%s)" %
out_port3)
time.sleep(rundelay)
# Allocate a placeholder for the group entry
group_entry = GroupEntry(group_id, group_type)
group_entry.set_group_name(group_name)
#.........这里部分代码省略.........
示例12: print
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
rundelay = 5
print ("\n")
print ("<<< Creating Controller instance")
time.sleep(rundelay)
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd, None)
print ("'Controller':")
print ctrl.brief_json()
print ("\n")
print ("<<< Get detailed information about ports on OpenFlow node '%s'" % nodeName)
time.sleep(rundelay)
ofswitch = OFSwitch(ctrl, nodeName)
result = ofswitch.get_ports_list()
status = result.get_status()
if(status.eq(STATUS.OK) == True):
ports = result.get_data()
for port in ports:
result = ofswitch.get_port_detail_info(port)
status = result.get_status()
if(status.eq(STATUS.OK) == True):
print ("Port '%s' info:" % port)
info = result.get_data()
print json.dumps(info, indent=4)
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
示例13: of_demo_13
def of_demo_13():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 13 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# VLAN ID
# VLAN PCP
eth_type = ETH_TYPE_IPv4
eth_src = "00:00:00:11:23:ad"
eth_dst = "00:ff:29:01:19:61"
vlan_id = 100
vlan_pcp = PCP_CA # 'Critical Applications' (priority 3)
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'"
% (ctrlIpAddr, nodeName))
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Ethernet Type (%s)\n"
" Ethernet Source Address (%s)\n"
" Ethernet Destination Address (%s)\n"
" VLAN ID (%s)\n"
" VLAN PCP(%s)"
% (hex(eth_type), eth_src,
eth_dst, vlan_id, vlan_pcp))
print (" Action: Output (to Physical Port Number)")
time.sleep(rundelay)
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 20
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_hard_timeout(0)
flow_entry.set_flow_idle_timeout(0)
flow_entry.set_flow_priority(1011)
# --- Instruction: 'Apply-actions'
# Action: 'Output' to port 7
instruction = Instruction(instruction_order=0)
action = OutputAction(order=0, port=7)
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)
# --- Match Fields: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# VLAN ID
# VLAN PCP
match = Match()
match.set_eth_type(eth_type)
match.set_eth_src(eth_src)
match.set_eth_dst(eth_dst)
match.set_vlan_id(vlan_id)
match.set_vlan_pcp(vlan_pcp)
flow_entry.add_match(match)
print ("\n")
print ("<<< Flow to send:")
print flow_entry.get_payload()
time.sleep(rundelay)
result = ofswitch.add_modify_flow(flow_entry)
status = result.get_status()
if(status.eq(STATUS.OK)):
print ("<<< Flow successfully added to the Controller")
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
exit(0)
print ("\n")
print ("<<< Get configured flow from the Controller")
time.sleep(rundelay)
result = ofswitch.get_configured_flow(table_id, flow_id)
#.........这里部分代码省略.........
示例14: of_demo_20
def of_demo_20():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit()
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 20 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Type
# IP DSCP
# IP ECN
# IPv6 Source Address
# IPv6 Destination Address
# IPv6 Flow Label
# ICMPv6 type
# ICMPv6 Code
# Metadata
eth_type = ETH_TYPE_IPv6
ip_dscp = IP_DSCP_CS7 # 'Class Selector' = 'Network'
ip_ecn = IP_ECN_CE # 'Congestion Encountered'
ipv6_src = "1234:5678:9ABC:DEF0:FDCD:A987:6543:210F/76"
ipv6_dst = "2000:2abc:edff:fe00::3456/94"
ipv6_flabel = 15
ip_proto = IP_PROTO_ICMPv6
icmpv6_type = 1 # 'Destination Unreachable'
icmpv6_code = 3 # 'Address Unreachable'
metadata = "0x0123456789ABCDEF"
# --- Flow Actions: Output (CONTROLLER)
output_port = "CONTROLLER"
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
(ctrlIpAddr, nodeName))
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Ethernet Type (%s)\n"
" IP DSCP (%s)\n"
" IP ECN (%s)\n"
" IPv6 Source Address (%s)\n"
" IPv6 Destination Address (%s)\n"
" IPv6 Flow Label (%s)\n"
" ICMPv6 Type (%s)\n"
" ICMPv6 Code (%s)\n"
" Metadata (%s)" %
(hex(eth_type), ip_dscp, ip_ecn,
ipv6_src, ipv6_dst, ipv6_flabel,
icmpv6_type, icmpv6_code, metadata))
print (" Action: Output (to %s)" % (output_port))
time.sleep(rundelay)
flow_entry = FlowEntry()
table_id = 0
flow_id = 26
flow_entry.set_flow_table_id(table_id)
flow_entry.set_flow_name(flow_name="demo20.py")
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_priority(flow_priority=1019)
flow_entry.set_flow_cookie(cookie=250)
flow_entry.set_flow_cookie_mask(cookie_mask=255)
flow_entry.set_flow_hard_timeout(hard_timeout=1200)
flow_entry.set_flow_idle_timeout(idle_timeout=3400)
# --- Instruction: 'Apply-actions'
# Actions: 'Output'
instruction = Instruction(instruction_order=0)
action = OutputAction(order=0, port=output_port)
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)
# --- Match Fields: Ethernet Type
# IP DSCP
# IP ECN
# IPv6 Source Address
# IPv6 Destination Address
# IPv6 Flow Label
# IP protocol number (ICMPv6)
# ICMPv6 Type
# ICMPv6 Code
# Metadata
match = Match()
match.set_eth_type(eth_type)
#.........这里部分代码省略.........
示例15: of_demo_43
def of_demo_43():
f = "cfg.yml"
d = {}
if(load_dict_from_file(f, d) is False):
print("Config file '%s' read error: " % f)
exit(0)
try:
ctrlIpAddr = d['ctrlIpAddr']
ctrlPortNum = d['ctrlPortNum']
ctrlUname = d['ctrlUname']
ctrlPswd = d['ctrlPswd']
nodeName = d['nodeName']
rundelay = d['rundelay']
except:
print ("Failed to get Controller device attributes")
exit(0)
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print ("<<< Demo 43 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
(ctrlIpAddr, nodeName))
first_flow_id = 110
# ---------------------------------------------------
# First flow entry
# ---------------------------------------------------
table_id = 0
flow_id = first_flow_id
flow_name = "Set Queue example"
priority = 1000
cookie = 1400
match_in_port = 109
match_eth_type = ETH_TYPE_IPv4
match_ipv4_dst_addr = "10.0.0.0/8"
act_queue_id = 7
act_out_port = 112
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (" Match: Input Port (%s)\n"
" Ethernet Type (%s)\n"
" IPv4 Destination Address (%s)" %
(match_in_port,
hex(match_eth_type),
match_ipv4_dst_addr))
print (" Actions: Set Queue (%s)\n"
" Output (%s)" %
(act_queue_id, act_out_port))
time.sleep(rundelay)
# Allocate a placeholder for the Flow Entry
flow_entry1 = FlowEntry()
# Generic attributes of the Flow Entry
flow_entry1.set_flow_table_id(table_id)
flow_entry1.set_flow_name(flow_name)
flow_entry1.set_flow_id(flow_id)
flow_entry1.set_flow_cookie(cookie)
flow_entry1.set_flow_priority(priority)
flow_entry1.set_flow_hard_timeout(0)
flow_entry1.set_flow_idle_timeout(0)
# Instructions/Actions for the Flow Entry
instruction = Instruction(instruction_order=0)
action_order = 0
action = SetQueueAction(action_order)
action.set_gueue_id(act_queue_id)
instruction.add_apply_action(action)
action_order += 1
action = OutputAction(action_order)
action.set_outport(act_out_port)
instruction.add_apply_action(action)
flow_entry1.add_instruction(instruction)
# Match Fields for the Flow Entry
match = Match()
match.set_in_port(match_in_port)
match.set_eth_type(match_eth_type)
match.set_ipv4_dst(match_ipv4_dst_addr)
flow_entry1.add_match(match)
print ("\n")
print ("<<< Flow to send:")
print flow_entry1.get_payload()
time.sleep(rundelay)
result = ofswitch.add_modify_flow(flow_entry1)
#.........这里部分代码省略.........