def runTest(self): logging.info("Running Forward_Table test") # delete all entries delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # add flow FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # Create a packet out message pkt = str(simple_tcp_packet()) pkt_out = ofp.message.packet_out() pkt_out.data = pkt pkt_out.in_port = in_port pkt_out.buffer_id = ofp.OFP_NO_BUFFER act = ofp.action.output() act.port = ofp.OFPP_TABLE pkt_out.actions.append(act) self.controller.message_send(pkt_out) # Verifying packet out message recieved on the expected dataplane port. verify_packets(self, pkt, [out_port])
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])], prio = 10 ) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])], prio = 11 ) # send packet to in_port and verify flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 2) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [out_port2]) verify_no_packet(self, pkt, out_port1)
def runTest(self): delete_all_flows(self.controller) logging.info( "Inserting flow: flow-mod cmd=add,table=0,prio=15 in_port=1 apply:output=2" ) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(2)]), instructions=[ ofp.instruction.apply_actions( [ofp.action.output(1)]), ]) logging.info( "Inserting flow: flow-mod cmd=add,table=0,prio=15,flags=0x2 apply:output=1" ) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(2)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(1)]), ], flags=ofp.OFPFF_CHECK_OVERLAP, ) # Verify the correct error message is returned response, _ = self.controller.poll( exp_msg=ofp.message.flow_mod_failed_error_msg) self.assertTrue(response is not None, "No Flow Mod Failed Error message was received") self.assertEqual(response.code, ofp.OFPFMFC_OVERLAP, "Error message error code is not OFPFMFC_OVERLAP")
def runTest(self): logging.info("") flow_stats = get_flow_stats(self, ofp.match()) in_port, out_port = openflow_ports(2) # Clear Switch State delete_all_flows(self.controller) flow_entry_num = 10 table_num = 5 for i in range(table_num): for j in range(flow_entry_num): FuncUtils.flow_entry_install( self.controller, "flow_add", table_id=i, match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=j, ) # test request = ofp.message.table_stats_request() (reply, pkt) = self.controller.transact(request) active_entry = 0 for obj in reply.entries: active_entry += obj.active_count self.assertEqual(flow_entry_num * table_num, active_entry, "Active entry error")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) request1 = FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) request2 = FuncUtils.flow_entry_install( self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # Verify the correct error message is returned response, _ = self.controller.poll( exp_msg=ofp.message.flow_mod_failed_error_msg) self.assertTrue(response is None, "Flow Mod Failed Error message was received") # read flow entries to ensure the new entry is inserted flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 2) self.assertTrue(request1.instructions, flow_stats[0].instructions) self.assertTrue(request2.instructions, flow_stats[1].instructions)
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port1)]) ], hard_timeout=1, ) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port2)]) ], hard_timeout=100) # tests time.sleep(5) stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(stats), 1, "Expected empty flow stats reply")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], hard_timeout=1, flags=ofp.OFPFF_SEND_FLOW_REM ) # send packet to in_port and verify start_time = time.time() dura_time = 6 while True: if time.time() - start_time > dura_time: break pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) time.sleep(5) msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(msg is not None, "Error message was not received") self.assertEqual(msg.duration_sec, 1, "Time is not correct")
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port1)]) ], prio=10) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port2)]) ], prio=11) # send packet to in_port and verify flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 2) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [out_port2]) verify_no_packet(self, pkt, out_port1)
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) request = FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port1)]) ]) pkg_num = 10 FuncUtils.send_packets(self, simple_icmp_packet(), in_port, pkg_num) FuncUtils.flow_entry_install( self.controller, "flow_mods", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port2)]) ]) # verify flow entry pkg num flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1) verify_flow_stats(self, request.match, pkts=pkg_num)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], hard_timeout=1, flags=ofp.OFPFF_SEND_FLOW_REM) # send packet to in_port and verify start_time = time.time() dura_time = 6 while True: if time.time() - start_time > dura_time: break pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) time.sleep(5) msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(msg is not None, "Error message was not received") self.assertEqual(msg.duration_sec, 1, "Time is not correct")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # test delete_all_flows(self.controller) error_msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(error_msg is None, "Error message was received") FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], flags=ofp.OFPFF_SEND_FLOW_REM) # test delete_all_flows(self.controller) error_msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(error_msg is not None, "Error message was not received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], ) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [out_port]) # flow del FuncUtils.flow_entry_install( self.controller, "flow_del", match=ofp.match([ofp.oxm.in_port(in_port)]), ) # verify the num of flow entry is 0 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 0) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [])
def runTest(self): delete_all_flows(self.controller) logging.info("Inserting flow: flow-mod cmd=add,table=0,prio=15 in_port=1 apply:output=2") FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(2)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(1)]), ]) logging.info("Inserting flow: flow-mod cmd=add,table=0,prio=15,flags=0x2 apply:output=1") FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(2)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(1)]), ], flags=ofp.OFPFF_CHECK_OVERLAP, ) # Verify the correct error message is returned response, _ = self.controller.poll(exp_msg=ofp.message.flow_mod_failed_error_msg) self.assertTrue(response is not None, "No Flow Mod Failed Error message was received") self.assertEqual(response.code, ofp.OFPFMFC_OVERLAP, "Error message error code is not OFPFMFC_OVERLAP")
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) request = FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port1)]) ]) pkg_num = 10 FuncUtils.send_packets(self, simple_icmp_packet(), in_port, pkg_num) FuncUtils.flow_entry_install(self.controller, "flow_mods", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port2)]) ]) # verify flow entry pkg num flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1) verify_flow_stats(self, request.match, pkts=pkg_num)
def runTest(self): in_port = openflow_ports(1)[0] pkt = str(simple_tcp_packet()) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions([ ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=2000) ]) ]) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) msg = ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER, actions=[ofp.action.output(port=in_port)], buffer_id=response.buffer_id, data=pkt) self.controller.message_send(msg) response, _ = self.controller.poll(ofp.message.bad_request_error_msg) self.assertEqual( response.code, ofp.OFPBRC_BUFFER_EMPTY, "Error message error code is not OFPBRC_BUFFER_EMPTY")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions( [ofp.action.output(out_port)]) ], flags=ofp.OFPFF_CHECK_OVERLAP) # Verify the correct error message is returned response, _ = self.controller.poll( exp_msg=ofp.message.flow_mod_failed_error_msg) self.assertTrue(response is not None, "No Flow Mod Failed Error message was received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # test delete_all_flows(self.controller) error_msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(error_msg is None, "Error message was received") FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], flags=ofp.OFPFF_SEND_FLOW_REM) # test delete_all_flows(self.controller) error_msg, _ = self.controller.poll(ofp.message.flow_removed) self.assertTrue(error_msg is not None, "Error message was not received")
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=1000 )])]) # test request = ofp.message.get_config_request() response, _ = self.controller.transact(request) print(response.show() + "num=" + str(response.miss_send_len)) pkt = str(simple_tcp_packet(pktlen=80, ip_ttl=1)) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) self.assertTrue(response is not None, "No packetin received") logging.info(response.show()) logging.info(len(response.data)) self.assertEqual(response.reason, ofp.OFPR_NO_MATCH, "Packetin reason field is not NO_MATCH")
def runTest(self): in_port = openflow_ports(1)[0] pkt = str(simple_tcp_packet()) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=2000 )])]) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) msg = ofp.message.packet_out( in_port=ofp.OFPP_CONTROLLER, actions=[ofp.action.output(port=in_port)], buffer_id=response.buffer_id, data=pkt) self.controller.message_send(msg) response, _ = self.controller.poll(ofp.message.bad_request_error_msg) self.assertEqual(response.code, ofp.OFPBRC_BUFFER_EMPTY, "Error message error code is not OFPBRC_BUFFER_EMPTY")
def runTest(self): FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [ofp.action.push_vlan(ethertype=0x0081)])]) response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No Error message was received") self.assertEqual(response.code, ofp.OFPBAC_BAD_ARGUMENT, "Error message error code is not OFPBAC_BAD_ARGUMENT")
def runTest(self): action = ofp.action.output(port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER) action.type = 100 FuncUtils.flow_entry_install( self.controller, "flow_add", instructions=[ofp.instruction.apply_actions([action])]) response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No Error message was received") self.assertEqual(response.code, ofp.OFPBAC_BAD_TYPE, "Error message error code is not OFPBRC_BAD_TYPE")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_del", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # test error_msg, _ = self.controller.poll(ofp.OFPT_ERROR) self.assertTrue(error_msg is None, "Error message was received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(ofp.OFPP_IN_PORT)])]) # send packets pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [in_port])
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # add flow FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], ) stat = get_port_stats(self, in_port)[0] self.assertTrue(stat.rx_dropped is not None, "No rx_dropped field")
def runTest(self): FuncUtils.flow_entry_install( self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions( [ofp.action.push_vlan(ethertype=0x0081)]) ]) response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No Error message was received") self.assertEqual( response.code, ofp.OFPBAC_BAD_ARGUMENT, "Error message error code is not OFPBAC_BAD_ARGUMENT")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install( self.controller, "flow_del", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # test error_msg, _ = self.controller.poll(ofp.OFPT_ERROR) self.assertTrue(error_msg is None, "Error message was received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add and delete FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=15) FuncUtils.flow_entry_install(self.controller, "flow_del", match=ofp.match([ofp.oxm.in_port(in_port)]), ) # flow add and delete strict FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=125) FuncUtils.flow_entry_install(self.controller, "flow_dels", match=ofp.match([ofp.oxm.in_port(in_port)]), prio=125) # verify the num of flow entry is 0 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 0)
def runTest(self): action = ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) action.type = 100 FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [action])]) response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No Error message was received") self.assertEqual(response.code, ofp.OFPBAC_BAD_TYPE, "Error message error code is not OFPBRC_BAD_TYPE")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) request = FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # send matching packets pkt = str(simple_icmp_packet()) times = 10 for i in range(times): self.dataplane.send(in_port, pkt) # send same flow into the table to reset counters self.controller.message_send(request) # check result flow_stats = get_flow_stats(self, ofp.match()) for entry in flow_stats: logging.debug(entry.show()) self.assertEqual(len(flow_stats), 1) self.assertEqual(flow_stats[0].packet_count, 0)
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER )])]) # test pkt = str(simple_tcp_packet(pktlen=70)) self.dataplane.send(in_port, pkt) verify_packet_in(self, pkt, in_port, ofp.OFPR_NO_MATCH)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) request = FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)])]) # send matching packets pkt = str(simple_icmp_packet()) times = 10 for i in range(times): self.dataplane.send(in_port, pkt) # send same flow into the table to reset counters self.controller.message_send(request) # check result flow_stats = get_flow_stats(self, ofp.match()) for entry in flow_stats: logging.debug(entry.show()) self.assertEqual(len(flow_stats), 1) self.assertEqual(flow_stats[0].packet_count, 0)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions( [ofp.action.output(ofp.OFPP_IN_PORT)]) ]) # send packets pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [in_port])
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) for i in range(65539): FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=i) # read error message response, _ = self.controller.poll(ofp.message.flow_mod_failed_error_msg, 0.00001) if response is not None and (response.code == ofp.OFPFMFC_TABLE_FULL): return self.assertTrue(False, "No error message was received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # add flow FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], ) # test pkt_num = 10 pkt = str(simple_tcp_packet()) for i in range(pkt_num): self.dataplane.send(in_port, pkt) verify_port_stats(self, out_port, tx_bytes=pkt_num * len(pkt))
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])]) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], flags=ofp.OFPFF_CHECK_OVERLAP) # Verify the correct error message is returned response, _ = self.controller.poll(exp_msg=ofp.message.flow_mod_failed_error_msg) self.assertTrue(response is not None, "No Flow Mod Failed Error message was received")
def runTest(self): logging.info("TestCase 70.30: Forward: Controller") # delete all entries delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER )])]) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port1, out_port2, out_port3 = openflow_ports(4) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions( [ofp.action.output(ofp.OFPP_ALL)])] ) # tests pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_no_packet(self, pkt, in_port) verify_packets(self, pkt, [out_port1, out_port2, out_port3])
def verify_modify(self, actions, pkt, exp_pkt): in_port, out_port = openflow_ports(2) actions = actions + [ofp.action.output(out_port)] logging.info("Running actions test for %s", pp(actions)) delete_all_flows(self.controller) logging.info("Inserting flow") FuncUtils.flow_entry_install(self.controller, "flow_add", match=packet_to_flow_match(self, pkt), instructions=[ofp.instruction.apply_actions(actions)] ) logging.info("Sending packet, expecting output to port %d", out_port) self.dataplane.send(in_port, str(pkt)) verify_packets(self, str(exp_pkt), [out_port])
def verify_modify(self, actions, pkt, exp_pkt): in_port, out_port = openflow_ports(2) actions = actions + [ofp.action.output(out_port)] logging.info("Running actions test for %s", pp(actions)) delete_all_flows(self.controller) logging.info("Inserting flow") FuncUtils.flow_entry_install( self.controller, "flow_add", match=packet_to_flow_match(self, pkt), instructions=[ofp.instruction.apply_actions(actions)]) logging.info("Sending packet, expecting output to port %d", out_port) self.dataplane.send(in_port, str(pkt)) verify_packets(self, str(exp_pkt), [out_port])
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER )])]) # test pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) self.assertTrue(response is not None, "No packetin received") self.assertEqual(response.reason, ofp.OFPR_NO_MATCH, "Packetin reason field is not NO_MATCH")
def runTest(self): delete_all_flows(self.controller) # search unavalible port for port_nonvalid in range(1000): FuncUtils.flow_entry_install(self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions([ofp.action.output(port_nonvalid)]) ]) _, port_config, _ = port_config_get(self.controller, port_nonvalid) if port_config is None: break # read error message response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No error message was received") self.assertEqual(response.code, ofp.OFPBAC_BAD_OUT_PORT)
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port1, out_port2, out_port3 = openflow_ports(4) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match( [ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions( [ofp.action.output(ofp.OFPP_ALL)]) ]) # tests pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_no_packet(self, pkt, in_port) verify_packets(self, pkt, [out_port1, out_port2, out_port3])
def runTest(self): logging.info("TestCase 70.30: Forward: Controller") # delete all entries delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ ofp.action.output(port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER) ]) ]) pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
def runTest(self): delete_all_flows(self.controller) # search unavalible port for port_nonvalid in range(1000): FuncUtils.flow_entry_install( self.controller, "flow_add", instructions=[ ofp.instruction.apply_actions( [ofp.action.output(port_nonvalid)]) ]) _, port_config, _ = port_config_get(self.controller, port_nonvalid) if port_config is None: break # read error message response, _ = self.controller.poll(ofp.message.bad_action_error_msg) self.assertTrue(response is not None, "No error message was received") self.assertEqual(response.code, ofp.OFPBAC_BAD_OUT_PORT)
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port = openflow_ports(2) max_len = 100 FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER )])]) # test pkt = str(simple_tcp_packet(pktlen=0)) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) logging.info(response.show()) self.assertTrue(response is not None, "No packetin received")
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])], hard_timeout=1, ) FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])], hard_timeout=100 ) # tests time.sleep(5) stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(stats), 1, "Expected empty flow stats reply")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow T0 add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # flow T1 add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ ofp.oxm.in_port(in_port), ofp.oxm.eth_dst([0x00, 0x13, 0x3b, 0x0f, 0x42, 0x1c]) ]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # flow del FuncUtils.flow_entry_install( self.controller, "flow_dels", match=ofp.match([ofp.oxm.in_port(in_port)]), ) # verify the num of flow entry is 1 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1)
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])], prio=15 ) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])], prio=14 ) # check flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 2, "Flow was not inserted correctly") # flow del FuncUtils.flow_entry_install(self.controller, "flow_del", match=ofp.match([ofp.oxm.in_port(in_port)]), prio=15, out_port=out_port1 ) # verify the num of flow entry is 1 and matching entry is removed flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1, len(flow_stats))
def runTest(self): delete_all_flows(self.controller) in_port, out_port1, out_port2 = openflow_ports(3) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port1)]) ], prio=15) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port2)]) ], prio=14) # check flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 2, "Flow was not inserted correctly") # flow del FuncUtils.flow_entry_install(self.controller, "flow_del", match=ofp.match( [ofp.oxm.in_port(in_port)]), prio=15, out_port=out_port1) # verify the num of flow entry is 1 and matching entry is removed flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1, len(flow_stats))
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=15 ) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], prio=14 ) # flow del FuncUtils.flow_entry_install(self.controller, "flow_dels", match=ofp.match([ofp.oxm.in_port(in_port)]), prio=15 ) # verify the num of flow entry is 1 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1) self.assertEqual(flow_stats[0].priority, 14, "Not matching entry is removed")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow T0 add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])] ) # flow T1 add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port), ofp.oxm.eth_dst([0x00, 0x13, 0x3b, 0x0f, 0x42, 0x1c]) ]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])] ) # flow del FuncUtils.flow_entry_install(self.controller, "flow_dels", match=ofp.match([ofp.oxm.in_port(in_port)]), ) # verify the num of flow entry is 1 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], prio=15) # flow add FuncUtils.flow_entry_install( self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ], prio=14) # flow del FuncUtils.flow_entry_install(self.controller, "flow_dels", match=ofp.match( [ofp.oxm.in_port(in_port)]), prio=15) # verify the num of flow entry is 1 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1) self.assertEqual(flow_stats[0].priority, 14, "Not matching entry is removed")
def runTest(self): delete_all_flows(self.controller) # config in_port, out_port = openflow_ports(2) max_len = 100 FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions( [ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=max_len )])]) # test pkt = str(simple_tcp_packet(pktlen=700)) self.dataplane.send(in_port, pkt) response, _ = self.controller.poll(ofp.message.packet_in) self.assertTrue(response is not None, "No packetin received") self.assertEqual(response.reason, ofp.OFPR_ACTION, "Reason of packetin is incorrect") self.assertEqual(len(response.data), max_len, "Length of packetin is incorrect")
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) # flow add FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])], hard_timeout=0, idle_timeout=0 ) # send packet to in_port and verify pkt = str(simple_tcp_packet()) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [out_port]) time.sleep(3) self.dataplane.send(in_port, pkt) verify_packets(self, pkt, [out_port]) flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 1)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) for i in range(65539): FuncUtils.flow_entry_install(self.controller, "flow_add", match=ofp.match( [ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions( [ofp.action.output(out_port)]) ], prio=i) # read error message response, _ = self.controller.poll( ofp.message.flow_mod_failed_error_msg, 0.00001) if response is not None and (response.code == ofp.OFPFMFC_TABLE_FULL): return self.assertTrue(False, "No error message was received")
def runTest(self): in_port, out_port = openflow_ports(2) actions = [ofp.action.output(out_port)] pkt = simple_tcp_packet() logging.info("Running actions test for %s", pp(actions)) delete_all_flows(self.controller) FuncUtils.flow_entry_install( self.controller, "flow_add", match=packet_to_flow_match(self, pkt), instructions=[ofp.instruction.write_actions(actions)]) pktstr = str(pkt) logging.info("Sending packet, expecting output to port %d", out_port) self.dataplane.send(in_port, pktstr) verify_packets(self, pktstr, [out_port])