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()
def of_demo_15(): 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 15 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # VLAN ID # Input Port eth_type = ETH_TYPE_IPv4 vlan_id = 100 input_port = 3 # --- Flow Actions: Push VLAN: Ethernet Type # Set Field: VLAN ID # Output: Port Number push_eth_type = ETH_TYPE_DOT1AD # 802.1ad VLAN tagged frame push_vlan_id = 200 output_port = 5 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(eth_type), vlan_id, input_port)) print (" Action: Push VLAN (Ethernet Type=%s)" % (hex(push_eth_type))) print (" Set Field (VLAN ID=%s)" % (push_vlan_id)) print (" Output (to Physical Port Number %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="Push VLAN") table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 22 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1013) flow_entry.set_flow_cookie(cookie=407) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'PushVlan' # 'SetField' # 'Output' instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(eth_type=push_eth_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(vid=push_vlan_id) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # Input Port match = Match() match.set_eth_type(eth_type) match.set_vlan_id(vlan_id) match.set_in_port(in_port=input_port) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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 # ICMPv4 Code # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_icmpv4_type(icmpv4_type) match.set_icmpv4_code(icmpv4_code) match.set_in_port(input_port) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_8(): 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 8 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 # IP Protocol Number # IP DSCP # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 eth_src = "00:1c:01:00:23:aa" eth_dst = "00:02:02:60:ff:fe" ipv4_src = "10.0.245.1/24" ipv4_dst = "192.168.1.123/16" ip_proto = IP_PROTO_TLSP ip_dscp = IP_DSCP_CS3 # 'Class Selector' = 'Flash' input_port = 13 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" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, input_port)) print (" Action: Output (CONTROLLER)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 15 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1006) flow_entry.set_flow_cookie(cookie=100) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Action: 'Output' to CONTROLLER instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER", max_len=60) 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 # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_in_port(input_port) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_7(): 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 7 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 # Input Port # NOTE: Ethernet type must be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 eth_src = "00:1a:1b:00:22:aa" eth_dst = "00:2b:00:60:ff:f1" ipv4_src = "44.44.44.1/24" ipv4_dst = "55.55.55.1/16" input_port = 13 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" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, input_port)) print(" Action: Output (CONTROLLER)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 15 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1005) # --- Instruction: 'Apply-actions' # Action: 'Output' to CONTROLLER instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER", max_len=60) 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 # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_in_port(input_port) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
status = result.get_status() if(status.eq(STATUS.OK) == True): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK) == True): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_15(): 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 15 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # VLAN ID # Input Port eth_type = ETH_TYPE_IPv4 vlan_id = 100 input_port = 3 # --- Flow Actions: Push VLAN: Ethernet Type # Set Field: VLAN ID # Output: Port Number push_eth_type = ETH_TYPE_DOT1AD # 802.1ad VLAN tagged frame push_vlan_id = 200 output_port = 5 print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(eth_type), vlan_id, input_port)) print(" Action: Push VLAN (Ethernet Type=%s)" % (hex(push_eth_type))) print(" Set Field (VLAN ID=%s)" % (push_vlan_id)) print(" Output (to Physical Port Number %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="Push VLAN") table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 22 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1013) flow_entry.set_flow_cookie(cookie=407) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'PushVlan' # 'SetField' # 'Output' instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(eth_type=push_eth_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(vid=push_vlan_id) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # Input Port match = Match() match.set_eth_type(eth_type) match.set_vlan_id(vlan_id) match.set_in_port(in_port=input_port) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_16(): 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 16 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address eth_type = ETH_TYPE_IPv6 ipv6_src = "fe80::2acf:e9ff:fe21:6431/128" ipv6_dst = "aabb:1234:2acf:e9ff::fe21:6431/64" # --- 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" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)" % (hex(eth_type), ipv6_src, ipv6_dst)) print (" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() fname = "match=ipv6_src,ipv6_dst;actions=output:Controller" flow_entry.set_flow_name(flow_name=fname) table_id = 0 flow_id = 23 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1014) flow_entry.set_flow_cookie(cookie=408) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) 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 # IPv6 Source Address # IPv6 Destination Address match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_5(): 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 5 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: IPv4 Source Address # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 ipv4_src = "10.11.12.13/24" print ("<<< 'Controller': %s, 'OpenFlow' switch: %s" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " IPv4 Source Address (%s)" % (hex(eth_type), ipv4_src)) print (" Action: Drop") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 12 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1000) # --- Instruction: 'Apply-actions' # Action: 'Drop' instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IPv4 Source Address match = Match() match.set_eth_type(eth_type) match.set_ipv4_src(ipv4_src) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ipv6_flabel(ipv6_flabel) match.set_ip_proto(ip_proto) match.set_icmpv6_type(icmpv6_type) match.set_icmpv6_code(icmpv6_code) match.set_metadata(metadata) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) 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.detailed()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_16(): 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 16 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address eth_type = ETH_TYPE_IPv6 ipv6_src = "fe80::2acf:e9ff:fe21:6431/128" ipv6_dst = "aabb:1234:2acf:e9ff::fe21:6431/64" # --- 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" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)" % (hex(eth_type), ipv6_src, ipv6_dst)) print(" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() fname = "match=ipv6_src,ipv6_dst;actions=output:Controller" flow_entry.set_flow_name(flow_name=fname) table_id = 0 flow_id = 23 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1014) flow_entry.set_flow_cookie(cookie=408) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) 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 # IPv6 Source Address # IPv6 Destination Address match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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 # ICMPv4 Code # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_icmpv4_type(icmpv4_type) match.set_icmpv4_code(icmpv4_code) match.set_in_port(input_port) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ipv6_flabel(ipv6_flabel) match.set_ip_proto(ip_proto) match.set_icmpv6_type(icmpv6_type) match.set_icmpv6_code(icmpv6_code) match.set_metadata(metadata) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_22(): 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 22 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Input Port # IPv4 Destination Address eth_type = ETH_TYPE_IPv4 in_port = 13 ipv4_dst = "10.12.5.4/32" # --- Flow Actions: Push MPLS # Set Field # Output push_ether_type = ETH_TYPE_MPLS_UCAST mpls_label = 27 output_port = 14 print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " Input Port (%s)\n" " IPv4 Destination Address (%s)" % (hex(eth_type), in_port, ipv4_dst)) print( " Action: Push MPLS Header (Ethernet Type %s)\n" " Set Field (MPLS label %s)\n" " Output (Physical Port number %s)" % (hex(push_ether_type), mpls_label, output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 28 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_name(flow_name="Push MPLS Label") flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(hard_timeout=0) flow_entry.set_flow_idle_timeout(idle_timeout=0) flow_entry.set_flow_priority(flow_priority=1021) flow_entry.set_flow_cookie(cookie=654) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Actions: 'Push MPLS Header' # 'Set Field' # 'Output' instruction = Instruction(instruction_order=0) action = PushMplsHeaderAction(order=0) action.set_eth_type(push_ether_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_mpls_label(mpls_label) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Input Port # IPv4 Destination Address match = Match() match.set_eth_type(eth_type) match.set_in_port(in_port) match.set_ipv4_dst(ipv4_dst) 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.detailed()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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) 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.detailed()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_6(): 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 6 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Ethernet Source Address # Ethernet Destination Addresses eth_type = 45 # (0x002D) eth_src = "00:01:02:03:04:05" eth_dst = "aa:bb:cc:dd:ee:ff" 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)" % (hex(eth_type), eth_src, eth_dst)) print (" Action: Drop") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 14 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1000) # --- Instruction: 'Apply-actions' # Action: 'Drop' instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_19(): 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 19 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IP DSCP # TCP Source Port # TCP Destination Port eth_type = ETH_TYPE_IPv6 ipv6_src = "4231::3210:3210:3210:3210/80" ipv6_dst = "1234:1234:1234:1234::5678:5678/64" ipv6_flabel = 33 ip_dscp = IP_DSCP_CS5 # 'Class Selector' = 'Critical' ip_proto = IP_PROTO_TCP tcp_src_port = 11111 tcp_dst_port = 22222 # --- 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" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IPv6 Flow Label (%s)\n" " IP DSCP (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)" % (hex(eth_type), ipv6_src, ipv6_dst, ipv6_flabel, ip_dscp, tcp_src_port, tcp_dst_port)) print(" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="demo19.py") table_id = 0 flow_id = 25 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1018) flow_entry.set_flow_cookie(cookie=23) 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 # IPv6 Source Address # IPv6 Destination Address # IPv6 Flow Label # IP protocol number (TCP) # IP DSCP # TCP Source Port # TCP Destination Port match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ipv6_flabel(ipv6_flabel) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src(tcp_src_port) match.set_tcp_dst(tcp_dst_port) 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) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_23(): 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 23 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Input Port # IPv4 Destination Address eth_type = ETH_TYPE_MPLS_UCAST in_port = 13 mpls_label = 27 # --- Flow Actions: Set Field # Output new_mpls_label = 44 output_port = 14 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Input Port (%s)\n" " MPLS Label (%s)" % (hex(eth_type), in_port, mpls_label)) print (" Action: Set Field (MPLS Label %s)\n" " Output (Physical Port number %s)" % (new_mpls_label, output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 29 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_name(flow_name="Change MPLS Label") flow_entry.set_flow_hard_timeout(hard_timeout=0) flow_entry.set_flow_idle_timeout(idle_timeout=0) flow_entry.set_flow_priority(flow_priority=1022) flow_entry.set_flow_cookie(cookie=401) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Actions: 'Set Field' # 'Output' instruction = Instruction(instruction_order=0) action = SetFieldAction(order=0) action.set_mpls_label(new_mpls_label) instruction.add_apply_action(action) action = OutputAction(order=1, port=2) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Input Port # MPLS Label match = Match() match.set_eth_type(eth_type) match.set_in_port(in_port) match.set_mpls_label(mpls_label) 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.detailed()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_18(): 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 18 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IP DSCP # TCP Source Port # TCP Destination Port eth_type = ETH_TYPE_IPv6 ipv6_src = "2001::2acf:e9ff:fe21:6431/80" ipv6_dst = "2004:1234:2acf:e9ff::fe21:6431/64" ip_dscp = IP_DSCP_CS1 # 'Class Selector' = 'Priority' ip_proto = IP_PROTO_TCP tcp_src_port = 12345 tcp_dst_port = 54321 # --- 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" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IP DSCP (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)" % (hex(eth_type), ipv6_src, ipv6_dst, ip_dscp, tcp_src_port, tcp_dst_port)) print (" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="demo18.py") table_id = 0 flow_id = 24 flow_entry.set_flow_table_id(table_id) 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(flow_priority=1017) # --- 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 # IPv6 Source Address # IPv6 Destination Address # IP protocol number (TCP) # IP DSCP # TCP Source Port # TCP Destination Port match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src_port(tcp_src_port) match.set_tcp_dst_port(tcp_dst_port) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_9(): 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 9 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 # TCP Source Port Number # TCP Destination Port Number # IP DSCP # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 eth_src = "00:00:00:11:23:ae" eth_dst = "ff:ff:29:01:19:61" ipv4_src = "17.1.2.3/8" ipv4_dst = "172.168.5.6/16" ip_proto = IP_PROTO_TCP # Assured Forwarding ('class'=1, 'drop precedence'=2) ip_dscp = IP_DSCP_AF12 tcp_src_port = 25364 tcp_dst_port = 8080 input_port = 13 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" " TCP Source Port Number (%s)\n" " TCP Destination Port Number (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, tcp_src_port, tcp_dst_port, 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 = 16 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1007) flow_entry.set_flow_cookie(cookie=101) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- 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 # TCP Source Port Number # TCP Destination Port Number # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src(tcp_src_port) match.set_tcp_dst(tcp_dst_port) match.set_in_port(input_port) 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) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")