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)]) ], 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_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) 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) 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) 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_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) 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) # 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): logging.info("Running 310.320 - Aggregate statistics byte count test") rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") in_port, out_port, = openflow_ports(2) table_id=0 priority=100 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow") pkt= str(simple_tcp_packet()) for i in range(5): logging.info("Sending a dataplane packet") self.dataplane.send(in_port,pkt) verify_packet(self,pkt,out_port) time.sleep(2) request = ofp.message.aggregate_stats_request(table_id=table_id,match=ofp.match(),out_port=ofp.OFPP_ANY,out_group=ofp.OFPG_ANY) reply, _=self.controller.transact(request) self.assertEqual(reply.byte_count,500, "Incorrect byte_count") logging.info("Received multipart reply as expected")
def runTest(self): logging.info("Running 310.240 - Aggregate statistics test") rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") in_port, out_port, = openflow_ports(2) table_id=0 priority=100 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow") time.sleep(2) request = ofp.message.aggregate_stats_request(table_id=table_id,match=ofp.match()) reply, _=self.controller.transact(request) self.assertEqual(reply.type, ofp.const.OFPT_STATS_REPLY, "Type of multipart reply is not correct") logging.info("Received multipart reply as expected")
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): 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) 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) 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_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_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) # Also used as masks cookies = [ 0x0000000000000000, 0xDDDDDDDD00000000, 0x00000000DDDDDDDD, 0xDDDDDDDDDDDDDDDD, 0xDDDD0000DDDD0000, 0x0000DDDD0000DDDD, 0xDD00DD00DD00DD00, 0xD0D0D0D0D0D0D0D0, 0xF000000000000000, 0xFF00000000000000, 0xFFF0000000000000, 0xFFFF000000000000, ] for i in range(0, 10): cookies.append(random.getrandbits(64)) # Generate the matching cookies for each combination of cookie and mask matches = {} for mask in cookies: for cookie in cookies: matching = [] for cookie2 in cookies: if cookie & mask == cookie2 & mask: matching.append(cookie2) matches[(cookie, mask)] = sorted(matching) # Generate a flow for each cookie flows = {} table_id = test_param_get("table", 0) for idx, cookie in enumerate(cookies): flows[cookie] = ofp.message.flow_add( table_id=table_id, cookie=cookie, match=ofp.match([ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | idx)]), buffer_id=ofp.OFP_NO_BUFFER) # Install flows for flow in flows.values(): self.controller.message_send(flow) do_barrier(self.controller) # For each combination of cookie and match, verify the correct flows # are retrieved for (cookie, mask), expected_cookies in matches.iteritems(): stats = get_flow_stats(self, ofp.match(), cookie=cookie, cookie_mask=mask) received_cookies = sorted([entry.cookie for entry in stats]) logging.debug("expected 0x%016x/0x%016x: %s", cookie, mask, ' '.join(["0x%016x" % x for x in expected_cookies])) logging.debug("received 0x%016x/0x%016x: %s", cookie, mask, ' '.join(["0x%016x" % x for x in received_cookies])) self.assertEqual(expected_cookies, received_cookies)
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) 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_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): logging.info("Running 310.290 - Aggregate statistics cookie mask test") rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") in_port, out_port1, out_port2, out_port3, = openflow_ports(4) table_id=0 priority=100 cookie1 = 1 actions=[ofp.action.output(port=out_port1, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority, cookie=cookie1) logging.info("Insert flow 1") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 1") priority=200 cookie2 = 2 actions=[ofp.action.output(port=out_port2, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority, cookie=cookie2) logging.info("Insert flow 2") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 2") priority=300 cookie3 = 3 actions=[ofp.action.output(port=out_port3, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority, cookie=cookie3) logging.info("Insert flow 2") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 2") time.sleep(2) cookie_mask = 0xfffffffffffffffe request = ofp.message.aggregate_stats_request(table_id=table_id,match=ofp.match(),cookie=cookie2,cookie_mask=cookie_mask,out_port=ofp.OFPP_ANY,out_group=ofp.OFPG_ANY) reply, _=self.controller.transact(request) self.assertEqual(reply.flow_count,2, "Incorrect flow_stats entry") logging.info("Received multipart reply as expected")
def runTest(self): logging.info("Running 310.110 - Flow statistics cookie mask test") rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") in_port1, in_port2, in_port3, out_port, = openflow_ports(4) table_id=0 priority=100 cookie1=1 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port1)]) req = ofp.message.flow_add(table_id=table_id, match= match, cookie=cookie1, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow 1") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 1") cookie2=2 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port2)]) req = ofp.message.flow_add(table_id=table_id, match= match, cookie=cookie2, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow 2") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 2") cookie3=3 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port3)]) req = ofp.message.flow_add(table_id=table_id, match= match, cookie=cookie3, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow 3") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow 3") cookie_mask=0xfffffffffffffffe cookie_list=[cookie2, cookie3] stats = get_flow_stats(self,table_id=table_id,match=ofp.match(),cookie=cookie2,cookie_mask=cookie_mask) self.assertEqual(len(stats), 2, "Incorrect flow stats.") self.assertIn(stats[0].cookie,cookie_list, "Incorrect cookie") cookie_list.remove(stats[0].cookie) self.assertIn(stats[1].cookie,cookie_list, "Incorrect cookie") logging.info("Received multipart reply as expected")
def runTest(self): delete_all_flows(self.controller) # Also used as masks cookies = [ 0x0000000000000000, 0xDDDDDDDD00000000, 0x00000000DDDDDDDD, 0xDDDDDDDDDDDDDDDD, 0xDDDD0000DDDD0000, 0x0000DDDD0000DDDD, 0xDD00DD00DD00DD00, 0xD0D0D0D0D0D0D0D0, 0xF000000000000000, 0xFF00000000000000, 0xFFF0000000000000, 0xFFFF000000000000, ] for i in range(0, 10): cookies.append(random.getrandbits(64)) # Generate the matching cookies for each combination of cookie and mask matches = {} for mask in cookies: for cookie in cookies: matching = [] for cookie2 in cookies: if cookie & mask == cookie2 & mask: matching.append(cookie2) matches[(cookie, mask)] = sorted(matching) # Generate a flow for each cookie flows = {} table_id = test_param_get("table", 0) for idx, cookie in enumerate(cookies): flows[cookie] = ofp.message.flow_add( table_id=table_id, cookie=cookie, match=ofp.match([ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT|idx)]), buffer_id=ofp.OFP_NO_BUFFER) # Install flows for flow in flows.values(): self.controller.message_send(flow) do_barrier(self.controller) # For each combination of cookie and match, verify the correct flows # are retrieved for (cookie, mask), expected_cookies in matches.iteritems(): stats = get_flow_stats(self, ofp.match(), cookie=cookie, cookie_mask=mask) received_cookies = sorted([entry.cookie for entry in stats]) logging.debug("expected 0x%016x/0x%016x: %s", cookie, mask, ' '.join(["0x%016x" % x for x in expected_cookies])) logging.debug("received 0x%016x/0x%016x: %s", cookie, mask, ' '.join(["0x%016x" % x for x in received_cookies])) self.assertEqual(expected_cookies, received_cookies)
def runTest(self): port2, = openflow_ports(1) table_id = test_param_get("table", 0) delete_all_flows(self.controller) flow2 = ofp.message.flow_add( table_id=table_id, priority=0x12, idle_timeout=0x22, hard_timeout=0x32, flags=ofp.OFPFF_NO_BYT_COUNTS, cookie=2, match=ofp.match([ ofp.oxm.in_port(port2), ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT|2)]), instructions=[ ofp.instruction.write_actions( actions=[ ofp.action.output( port=port2, max_len=ofp.OFPCML_NO_BUFFER)])], buffer_id=ofp.OFP_NO_BUFFER) #flows = [flow1, flow2, flow3] flows = [flow2] for flow in flows: logging.debug(flow.show()) self.controller.message_send(flow) flows_by_cookie = { flow.cookie: flow for flow in flows } do_barrier(self.controller) logging.info("Sending flow stats request") stats = get_flow_stats(self, ofp.match()) logging.info("Received %d flow stats entries", len(stats)) seen_cookies = set() for entry in stats: logging.debug(entry.show()) self.assertTrue(entry.cookie in flows_by_cookie, "Unexpected cookie") self.assertTrue(entry.cookie not in seen_cookies, "Duplicate cookie") flow = flows_by_cookie[entry.cookie] seen_cookies.add(entry.cookie) self.assertEqual(entry.table_id, flow.table_id) self.assertEqual(entry.priority, flow.priority) self.assertEqual(entry.idle_timeout, flow.idle_timeout) self.assertEqual(entry.hard_timeout, flow.hard_timeout) self.assertEqual(entry.flags, flow.flags) self.assertEqual(entry.cookie, flow.cookie) self.assertEqual(sorted(entry.match.oxm_list), sorted(flow.match.oxm_list)) self.assertEqual(sorted(entry.instructions), sorted(flow.instructions)) #self.assertEqual(seen_cookies, set([1,2,3])) self.assertEqual(seen_cookies, set([2]))
def runTest(self): logging.info("Running Testcase 60.50 for matching on Ethernet types") logging.info("---Running subtestcases") logging.info("Running for Ethernet type IPv4") match = ofp.match([ofp.oxm.eth_type(0x0800)]) snap_pkt = ( scapy.Ether(dst="00:01:02:03:04:05", src="00:06:07:08:09:0a", type=48) / scapy.LLC(dsap=0xAA, ssap=0xAA, ctrl=0x03) / scapy.SNAP(OUI=0x000000, code=0x0800) / scapy.IP(src="192.168.0.1", dst="192.168.0.2", proto=6) / scapy.TCP(sport=1234, dport=80) ) llc_pkt = scapy.Ether(dst="00:01:02:03:04:05", src="00:06:07:08:09:0a", type=17) / scapy.LLC( dsap=0xAA, ssap=0xAB, ctrl=0x03 ) matching = { "ipv4/tcp": simple_tcp_packet(), "ipv4/udp": simple_udp_packet(), "ipv4/icmp": simple_icmp_packet(), "vlan tagged": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=3), "qinq/tcp": qinq_tcp_packet(), } nonmatching = {"arp": simple_arp_packet(), "llc": llc_pkt, "ipv6/tcp": simple_tcpv6_packet()} self.verify_match(match, matching, nonmatching) logging.info("---Running subtestcases") logging.info("Running for Ethernet Type IPv6") match = ofp.match([ofp.oxm.eth_type(0x86DD)]) matching = { "ipv6/tcp": simple_tcpv6_packet(), "ipv6/udp": simple_udpv6_packet(), "ipv6/icmp": simple_icmpv6_packet(), "vlan tagged": simple_tcpv6_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=3), } nonmatching = {"ipv4/tcp": simple_tcp_packet(), "arp": simple_arp_packet()} self.verify_match(match, matching, nonmatching) logging.info("---Running subtestcases") logging.info("Running for Ethernet Type ARP") match = ofp.match([ofp.oxm.eth_type(0x0806)]) matching = {"arp": simple_arp_packet(), "vlan tagged": simple_arp_packet(vlan_vid=2, vlan_pcp=3)} nonmatching = {"ipv4/tcp": simple_tcp_packet(), "ipv6/tcp": simple_tcpv6_packet()} self.verify_match(match, matching, nonmatching)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) request = FuncUtils.flow_entry_install(self.controller, "flow_mod", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # verilog the flow entry was added and its counter was 0 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 0) verify_flow_stats(self, request.match, pkts=0)
def runTest(self): delete_all_flows(self.controller) in_port, out_port = openflow_ports(2) request = FuncUtils.flow_entry_install( self.controller, "flow_mod", match=ofp.match([ofp.oxm.in_port(in_port)]), instructions=[ ofp.instruction.apply_actions([ofp.action.output(out_port)]) ]) # verilog the flow entry was added and its counter was 0 flow_stats = get_flow_stats(self, ofp.match()) self.assertEqual(len(flow_stats), 0) verify_flow_stats(self, request.match, pkts=0)
def runTest(self): match = ofp.match([ ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 2), ofp.oxm.vlan_pcp_masked(3, 3), ]) matching = { "vid=2 pcp=3": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=3), "vid=2 pcp=7": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=7), } nonmatching = { "vid=2 pcp=1": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=1), "vid=2 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=2), "vid=2 pcp=4": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=4), "vid=2 pcp=5": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=5), "vid=2 pcp=6": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=6), "no vlan tag": simple_tcp_packet(), } self.verify_match(match, matching, nonmatching)
def runTest(self): in_port, = openflow_ports(1) delete_all_flows(self.controller) pkt = str(simple_tcp_packet()) request = ofp.message.flow_add( match=ofp.match(wildcards=ofp.OFPFW_ALL), buffer_id=0xffffffff, actions=[ofp.action.output(ofp.OFPP_CONTROLLER)]) self.controller.message_send(request) do_barrier(self.controller) latencies = [] for i in xrange(0, 1000): start_time = time.time() self.dataplane.send(in_port, pkt) verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION) end_time = time.time() latencies.append(end_time - start_time) latencies.sort() latency_min = latencies[0] latency_90 = latencies[int(len(latencies) * 0.9)] latency_max = latencies[-1] logging.debug("Minimum latency: %f ms", latency_min * 1000.0) logging.debug("90%% latency: %f ms", latency_90 * 1000.0) logging.debug("Maximum latency: %f ms", latency_max * 1000.0) self.assertGreater(config["default_timeout"], latency_max) self.assertGreater(config["default_negative_timeout"], latency_90)
def runTest(self): INFO = " 1.1.110 - Invalid OXM - Value" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ ofp.oxm.in_port(in_port), ofp.oxm.eth_type(0x800), ofp.oxm.ip_dscp(100), ]) action = ofp.action.output(out_port1) inst = ofp.instruction.apply_actions(actions=[action]) logging.info("Inserting flow with bad match value") # Wrong match value in flow mod request = ofp.message.flow_add( table_id=10, match=match, instructions=[inst], hard_timeout=1000, ) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to invalid OXM value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_MATCH, "Reply error type is not bad match request") self.assertTrue(reply.code == ofp.OFPBMC_BAD_VALUE, "Reply error code is not bad match value") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> " + str(Err))
def runTest(self): INFO = " 1.1.90 - Invalid OXM - Type" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ ofp.oxm.in_port(in_port), ]) inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) logging.info("Inserting flow with malformed control message type") # Wrong type in flow mod request = ofp.message.flow_add(table_id=10, type=16, match=match, instructions=[inst], hard_timeout=1000) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to invalid OXM type") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_REQUEST, "Reply error type is not bad request") self.assertTrue(reply.code == ofp.OFPFMFC_BAD_COMMAND, "Reply error code is not bad command") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))
def runTest(self): INFO = " 1.1.20 - Table Identifier Violation" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ ofp.oxm.in_port(in_port), ]) priority = 10 logging.info("Inserting flow with bad table ID") inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) request = ofp.message.flow_add(table_id=255, match=match, instructions=[inst], buffer_id=ofp.OFP_NO_BUFFER, priority=priority, flags=ofp.OFPFF_SEND_FLOW_REM) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to malformed table ID") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_FLOW_MOD_FAILED, "Reply error type is not flow mod failed") self.assertTrue(reply.code == ofp.OFPFMFC_BAD_TABLE_ID, "Reply error code is not bad table ID") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> " + str(Err))
def runTest(self): INFO = " 1.1.160 - Corrupted Cookie Values" in_port, out_port1 = testutils.openflow_ports(2) match = ofp.match([ ofp.oxm.in_port(in_port), ]) inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) logging.info("Inserting flow with malformed/reserved cookie value") # Wrong type in flow mod request = ofp.message.flow_add( table_id=1, match=match, instructions=[inst], buffer_id=ofp.OFP_NO_BUFFER, cookie=0xfffffffffffffff, ) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to corrupted cookie value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_FLOW_MOD_FAILED, "Reply error type is not flow mod failed") self.assertTrue(reply.code == ofp.OFPFMFC_UNKNOWN, "Reply error code is not unknown code type") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> " + str(Err))
def runTest(self): match = ofp.match([ ofp.oxm.eth_type(0x0800) ]) snap_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=48)/ \ scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ scapy.SNAP(OUI=0x000000, code=0x0800)/ \ scapy.IP(src='192.168.0.1', dst='192.168.0.2', proto=6)/ \ scapy.TCP(sport=1234, dport=80) llc_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=17)/ \ scapy.LLC(dsap=0xaa, ssap=0xab, ctrl=0x03) matching = { "ipv4/tcp": simple_tcp_packet(), "ipv4/udp": simple_udp_packet(), "ipv4/icmp": simple_icmp_packet(), "vlan tagged": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=3), "llc/snap": snap_pkt, } nonmatching = { "arp": simple_arp_packet(), "llc": llc_pkt, "ipv6/tcp": simple_tcpv6_packet(), } self.verify_match(match, matching, nonmatching)
def runTest(self): delete_all_flows(self.controller) delete_all_groups(self.controller) in_port = config["port_map"].keys()[0] out_port=config["port_map"].keys()[1] add_one_vlan_table_flow(self.controller, in_port, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False) add_one_l2_interface_group(self.controller, out_port, 10, True, False) msg=add_l2_rewrite_group(self.controller, out_port, 10, 1, None, None) match = ofp.match() match.oxm_list.append(ofp.oxm.in_port(in_port)) request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[ ofp.instruction.write_actions( actions=[ ofp.action.group(msg.group_id)]) ], buffer_id=ofp.OFP_NO_BUFFER, priority=1000) self.controller.message_send(request) parsed_pkt = simple_tcp_packet(pktlen=100) pkt = str(parsed_pkt) self.dataplane.send(in_port, pkt) parsed_pkt = simple_tcp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=10) verify_packet(self, str(parsed_pkt), out_port)
def runTest(self): INFO = " 1.1.20 - Table Identifier Violation" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ ofp.oxm.in_port(in_port), ]) priority = 10 logging.info("Inserting flow with bad table ID") inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) request = ofp.message.flow_add(table_id=255, match=match, instructions=[inst], buffer_id=ofp.OFP_NO_BUFFER, priority=priority, flags=ofp.OFPFF_SEND_FLOW_REM) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to malformed table ID") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_FLOW_MOD_FAILED, "Reply error type is not flow mod failed") self.assertTrue(reply.code == ofp.OFPFMFC_BAD_TABLE_ID, "Reply error code is not bad table ID") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))
def runTest(self): flow = "2001:0db8:85a3::0001" mask = "ffff:ffff:ffff::000f" correct1 = "2001:0db8:85a3::8a2e:0370:7331" correct2 = "2001:0db8:85a3::ffff:ffff:fff1" incorrect1 = "2001:0db8:85a2::0001" incorrect2 = "2001:0db8:85a3::0000" match = ofp.match([ ofp.oxm.eth_type(0x86dd), ofp.oxm.ipv6_dst_masked(parse_ipv6(flow), parse_ipv6(mask)), ]) matching = { "flow": simple_tcpv6_packet(ipv6_dst=flow), "correct1": simple_tcpv6_packet(ipv6_dst=correct1), "correct2": simple_tcpv6_packet(ipv6_dst=correct2), } nonmatching = { "incorrect1": simple_tcpv6_packet(ipv6_dst=incorrect1), "incorrect2": simple_tcpv6_packet(ipv6_dst=incorrect2), } self.verify_match(match, matching, nonmatching)
def runTest(self): INFO = " 1.1.170 - Malformed Buffer ID Values" in_port, out_port1 = testutils.openflow_ports(2) match = ofp.match([ ofp.oxm.in_port(in_port), ]) inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) logging.info("Inserting flow with malformed/reserved buffered value") # Wrong type in flow mod request = ofp.message.flow_add(table_id=1, match=match, instructions=[inst], buffer_id=1243,) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to malformed cookie value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_REQUEST, "Reply error type is not bad request") self.assertTrue(reply.code == ofp.OFPBRC_BUFFER_UNKNOWN, "Reply error code is not unknown buffer code") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))
def runTest(self): INFO = " 1.1.160 - Corrupted Cookie Values" in_port, out_port1 = testutils.openflow_ports(2) match = ofp.match([ ofp.oxm.in_port(in_port), ]) inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) logging.info("Inserting flow with malformed/reserved cookie value") # Wrong type in flow mod request = ofp.message.flow_add(table_id=1, match=match, instructions=[inst], buffer_id=ofp.OFP_NO_BUFFER, cookie=0xfffffffffffffff,) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to corrupted cookie value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_FLOW_MOD_FAILED, "Reply error type is not flow mod failed") self.assertTrue(reply.code == ofp.OFPFMFC_UNKNOWN, "Reply error code is not unknown code type") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))
def runTest(self): INFO = " 1.1.110 - Invalid OXM - Value" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ofp.oxm.in_port(in_port), ofp.oxm.eth_type(0x800), ofp.oxm.ip_dscp(100), ]) action = ofp.action.output(out_port1) inst = ofp.instruction.apply_actions(actions=[action]) logging.info("Inserting flow with bad match value") # Wrong match value in flow mod request = ofp.message.flow_add(table_id=10, match=match, instructions=[inst], hard_timeout=1000,) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to invalid OXM value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_MATCH, "Reply error type is not bad match request") self.assertTrue(reply.code == ofp.OFPBMC_BAD_VALUE, "Reply error code is not bad match value") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))
def runTest(self): in_port, = openflow_ports(1) delete_all_flows(self.controller) pkt = str(simple_tcp_packet()) request = ofp.message.flow_add( match=ofp.match(wildcards=ofp.OFPFW_ALL), buffer_id=0xffffffff, actions=[ofp.action.output(ofp.OFPP_CONTROLLER)]) self.controller.message_send(request) do_barrier(self.controller) latencies = [] for i in xrange(0, 1000): start_time = time.time() self.dataplane.send(in_port, pkt) verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION) end_time = time.time() latencies.append(end_time - start_time) latencies.sort() latency_min = latencies[0] latency_90 = latencies[int(len(latencies)*0.9)] latency_max = latencies[-1] logging.debug("Minimum latency: %f ms", latency_min * 1000.0) logging.debug("90%% latency: %f ms", latency_90 * 1000.0) logging.debug("Maximum latency: %f ms", latency_max * 1000.0) self.assertGreater(config["default_timeout"], latency_max) self.assertGreater(config["default_negative_timeout"], latency_90)
def runTest(self): match = ofp.match([ ofp.oxm.eth_type(0x0800) ]) snap_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=0x0800)/ \ scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ scapy.SNAP(OUI=0x000000, code=0x0800)/ \ scapy.IP(src='192.168.0.1', dst='192.168.0.2', proto=6)/ \ scapy.TCP(sport=1234, dport=80) llc_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=0x0800)/ \ scapy.IP(src='192.168.0.1', dst='192.168.0.2', proto=6) #scapy.LLC(dsap=0xaa, ssap=0xab, ctrl=0x03) matching = { "llc": llc_pkt, } nonmatching = { # "ipv4/tcp": simple_tcp_packet(), "ipv6/tcp": simple_tcpv6_packet(), # "llc/snap": snap_pkt, } self.verify_match(match, matching, nonmatching)
def runTest(self): logging.info("Running testcase 80.200 Multiple instances of the same OXM_TYPE in a flow entry") delete_all_flows(self.controller) out_port, bad_port = openflow_ports(2) table_id = test_param_get("table", 0) priority=1 actions=[ofp.action.output(port=out_port,max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] #Match on IPv4 UDP source Port with a wrong pre-requisite(ip_proto=6) match = ofp.match([ ofp.oxm.eth_type(0x0800), ofp.oxm.ip_proto(17), ofp.oxm.udp_src(53), ofp.oxm.ip_proto(17), ]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Inserting a flow to match on IPv4 UDP source Port (with duplicated oxm_types) and action output to port %s", out_port) self.controller.message_send(req) reply, _ = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=3) self.assertIsNotNone(reply, "Din't receive an error message, installed flow successfully") logging.info("Switch generated an error") self.assertEqual(reply.err_type,ofp.const.OFPET_BAD_MATCH,"Reply type is not OFPET_BAD_MATCH") logging.info("Error type is OFPET_BAD_MATCH") self.assertEqual(reply.code,ofp.const.OFPBMC_DUP_FIELD, "Reply code is not OFPBMC_DUP_FIELD") logging.info("Error Code is OFPBMC_DUP_FIELD")
def runTest(self): logging.info("Running 310.230 - Flow statistics match test") rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") in_port, out_port, = openflow_ports(2) table_id=0 priority=100 actions=[ofp.action.output(port=out_port, max_len=128)] instructions=[ofp.instruction.apply_actions(actions=actions)] match = ofp.match([ofp.oxm.in_port(in_port)]) req = ofp.message.flow_add(table_id=table_id, match= match, buffer_id=ofp.OFP_NO_BUFFER, instructions=instructions, priority=priority) logging.info("Insert flow") rv = self.controller.message_send(req) self.assertTrue(rv != -1, "Failed to insert flow") time.sleep(2) stats = get_flow_stats(self,table_id=table_id,match=req.match) self.assertEqual(len(stats), 1, "Incorrect flow stats.") self.assertEqual(stats[0].match,req.match, "Incorrect match") logging.info("Received multipart reply as expected")
def runTest(self): match = ofp.match([ofp.oxm.eth_type(0x05ff)]) snap_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=48)/ \ scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ scapy.SNAP(OUI=0x000000, code=0x0800)/ \ scapy.IP(src='192.168.0.1', dst='192.168.0.2', proto=6)/ \ scapy.TCP(sport=1234, dport=80) llc_pkt = \ scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a', type=17)/ \ scapy.LLC(dsap=0xaa, ssap=0xab, ctrl=0x03) matching = { "llc": llc_pkt, } nonmatching = { "ipv4/tcp": simple_tcp_packet(), "ipv6/tcp": simple_tcpv6_packet(), "llc/snap": snap_pkt, } self.verify_match(match, matching, nonmatching)
def runTest(self): INFO = " 1.1.170 - Malformed Buffer ID Values" in_port, out_port1 = testutils.openflow_ports(2) match = ofp.match([ ofp.oxm.in_port(in_port), ]) inst = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) logging.info("Inserting flow with malformed/reserved buffered value") # Wrong type in flow mod request = ofp.message.flow_add( table_id=1, match=match, instructions=[inst], buffer_id=1243, ) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to malformed cookie value") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_REQUEST, "Reply error type is not bad request") self.assertTrue(reply.code == ofp.OFPBRC_BUFFER_UNKNOWN, "Reply error code is not unknown buffer code") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> " + str(Err))
def runTest(self): match = ofp.match([ ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 2), ofp.oxm.vlan_pcp(3), ]) matching = { "vid=2 pcp=3": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=3), } nonmatching = { "vid=4 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=4, vlan_pcp=2), "vid=4 pcp=3": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=4, vlan_pcp=3), "vid=2 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=2), "vid=0 pcp=3": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=3), "vid=2 pcp=0": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=0), "no vlan tag": simple_tcp_packet(), } self.verify_match(match, matching, nonmatching)
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): match = ofp.match([ ofp.oxm.vlan_vid_masked(ofp.OFPVID_PRESENT | 3, ofp.OFPVID_PRESENT | 3), ]) matching = { "vid=3 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=3, vlan_pcp=2), "vid=7 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=7, vlan_pcp=2), "vid=11 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=11, vlan_pcp=2), } nonmatching = { "vid=0 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=2), "vid=1 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, vlan_pcp=2), "vid=2 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=2, vlan_pcp=2), "vid=4 pcp=2": simple_tcp_packet(dl_vlan_enable=True, vlan_vid=4, vlan_pcp=2), "no vlan tag": simple_tcp_packet(), } self.verify_match(match, matching, nonmatching)
def all_stats_get(parent): """ Get the aggregate stats for all flows in the table @param parent Test instance with controller connection and assert @returns dict with keys flows, packets, bytes, active (flows), lookups, matched """ stat_req = ofp.message.aggregate_stats_request() stat_req.match = ofp.match() stat_req.match.wildcards = ofp.OFPFW_ALL stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE rv = {} (reply, pkt) = parent.controller.transact(stat_req) parent.assertTrue( len(reply.entries) == 1, "Did not receive flow stats reply") for obj in reply.entries: (rv["flows"], rv["packets"], rv["bytes"]) = (obj.flow_count, obj.packet_count, obj.byte_count) break request = ofp.message.table_stats_request() (reply, pkt) = parent.controller.transact(request) (rv["active"], rv["lookups"], rv["matched"]) = (0, 0, 0) for obj in reply.entries: rv["active"] += obj.active_count rv["lookups"] += obj.lookup_count rv["matched"] += obj.matched_count return rv
def runTest(self): INFO = " 1.1.50 - Table Loop Violation" in_port, out_port1 = testutils.openflow_ports(2) testutils.delete_all_flows(self.controller) match = ofp.match([ ofp.oxm.in_port(in_port), ]) priority = 1000 logging.info("Inserting flow with bad goto table instruction") inst1 = ofp.instruction.apply_actions([ofp.action.output(out_port1)]) inst2 = ofp.instruction.goto_table(5) request = ofp.message.flow_add(table_id=10, match=match, instructions=[inst1, inst2], buffer_id=ofp.OFP_NO_BUFFER, priority=priority, flags=ofp.OFPFF_SEND_FLOW_REM) reply, pkt = self.controller.transact(request) try: self.assertTrue(reply is not None, "No response to table loop error") self.assertTrue(reply.type == ofp.OFPT_ERROR, "Reply not an error message") self.assertTrue(reply.err_type == ofp.OFPET_BAD_INSTRUCTION, "Reply error type is not bad instruction request") self.assertTrue(reply.code == ofp.OFPBIC_BAD_TABLE_ID, "Reply error code is not bad table id") log.info(PASS + INFO) except AssertionError, Err: log.info(FAIL + INFO) log.info(REASON + " -> "+ str(Err))