# --- 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) == True): print ("<<< Flow successfully added to the Controller") else: print ("\n")
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_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(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")