edited
diff --git a/tests/FuncUtils.py b/tests/FuncUtils.py
index ad00246..9e3fea6 100644
--- a/tests/FuncUtils.py
+++ b/tests/FuncUtils.py
@@ -1,4 +1,4 @@
-""" Defined Some common functions used by Conformance tests -- OF-SWITCH 1.0.0 Testcases """
+""" Some common function definitions used by Conformance tests -- OF-SWITCH 1.0.0 Testcases """
import sys
import copy
@@ -104,11 +104,11 @@
return (pkt_wildcardsrc,match1)
-def match_wthernet_src_address(self,of_ports,priority=None):
+def match_ethernet_src_address(self,of_ports,priority=None):
#Generate Match_Ethernet_SrC_Address flow
#Create a simple tcp packet and generate match on ethernet src address flow
- pkt_MatchSrc = simple_tcp_packet(dl_src='00:01:01:01:01:01')
+ pkt_MatchSrc = simple_eth_packet(dl_src='00:01:01:01:01:01')
match = parse.packet_to_flow_match(pkt_MatchSrc)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
@@ -136,7 +136,7 @@
#Generate Match_Ethernet_Dst_Address flow
#Create a simple tcp packet and generate match on ethernet dst address flow
- pkt_matchdst = simple_tcp_packet(dl_dst='00:01:01:01:01:01')
+ pkt_matchdst = simple_eth_packet(dl_dst='00:01:01:01:01:01')
match = parse.packet_to_flow_match(pkt_matchdst)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
@@ -254,8 +254,6 @@
return (pkt_matchingress,match3)
-
-
def match_vlan_id(self,of_ports,priority=None):
#Generate Match_Vlan_Id
@@ -264,7 +262,7 @@
match = parse.packet_to_flow_match(pkt_matchvlanid)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN
+ match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_VLAN
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -291,7 +289,7 @@
match = parse.packet_to_flow_match(pkt_matchvlanpcp)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN_PCP
+ match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_DL_VLAN^ofp.OFPFW_DL_VLAN_PCP
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -339,14 +337,14 @@
return (pkt_mulL2,match)
-def match_mul_L4(self,of_ports,priority=None):
+def match_mul_l4(self,of_ports,priority=None):
#Generate Match_Mul_L4 flow
#Create a simple tcp packet and generate match on tcp protocol flow
pkt_mulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112)
match = parse.packet_to_flow_match(pkt_mulL4)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST
+ match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -369,11 +367,11 @@
#Generate a Match on IP Type of service flow
#Create a simple tcp packet and generate match on Type of service
- pkt_iptos = simple_tcp_packet(ip_tos=3)
+ pkt_iptos = simple_tcp_packet(ip_tos=30)
match = parse.packet_to_flow_match(pkt_iptos)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_NW_TOS
+ match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_TOS
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -391,6 +389,33 @@
return (pkt_iptos,match)
+def match_ip_protocol(self,of_ports,priority=None):
+ #Generate a Match on IP Protocol
+
+ #Create a simple tcp packet and generate match on Type of service
+ pkt_iptos = simple_tcp_packet()
+ match = parse.packet_to_flow_match(pkt_iptos)
+ self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+ match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO
+ msg = message.flow_mod()
+ msg.out_port = ofp.OFPP_NONE
+ msg.command = ofp.OFPFC_ADD
+ msg.buffer_id = 0xffffffff
+ msg.match = match
+ if priority != None :
+ msg.priority = priority
+ act = action.action_output()
+ act.port = of_ports[1]
+ self.assertTrue(msg.actions.add(act), "could not add action")
+
+ rv = self.controller.message_send(msg)
+ self.assertTrue(rv != -1, "Error installing flow mod")
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+ return (pkt_iptos,match)
+
+
def match_tcp_src(self,of_ports,priority=None):
#Generate Match_Tcp_Src
@@ -399,7 +424,7 @@
match = parse.packet_to_flow_match(pkt_matchtSrc)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC
+ match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -422,11 +447,11 @@
#Generate Match_Tcp_Dst
#Create a simple tcp packet and generate match on tcp destination port flow
- pkt_Matchtdst = simple_tcp_packet(tcp_dport=112)
- match = parse.packet_to_flow_match(pkt_matchtdst)
+ pkt_matchdst = simple_tcp_packet(tcp_dport=112)
+ match = parse.packet_to_flow_match(pkt_matchdst)
self.assertTrue(match is not None, "Could not generate flow match from pkt")
- match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_DST
+ match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST
msg = message.flow_mod()
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_ADD
@@ -442,11 +467,7 @@
self.assertTrue(rv != -1, "Error installing flow mod")
self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
- return (pkt_matchtdst,match)
-
-
-
-
+ return (pkt_matchdst,match)
def match_ethernet_type(self,of_ports,priority=None):
#Generate a Match_Ethernet_Type flow
@@ -472,11 +493,11 @@
rv = self.controller.message_send(msg)
self.assertTrue(rv != -1, "Error installing flow mod")
self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
-
return (pkt_matchtype,match)
+
def strict_modify_flow_action(self,egress_port,match,priority=None):
# Strict Modify the flow Action
@@ -546,8 +567,6 @@
return (pkt,match)
-
-
########################### Verify Stats Functions ###########################################################################################
def get_flowstats(self,match):
# Generate flow_stats request
@@ -768,7 +787,6 @@
self.assertEqual(tx_byte,item.tx_bytes,"tx_bytes counter is not incremented correctly")
-
def verify_queuestats(self,port_num,queue_id,expect_packet=None,expect_byte=None):
# Verify queue counters : tx_packets and tx_bytes
diff --git a/tests/flow_matches.py b/tests/flow_matches.py
new file mode 100644
index 0000000..dc91616
--- /dev/null
+++ b/tests/flow_matches.py
@@ -0,0 +1,689 @@
+"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
+ Refer Documentation -- Detailed testing methodology
+ <Some of test-cases are directly taken from oftest> """
+
+"Test Suite 6 --> Flow Matches"
+
+
+import logging
+
+import unittest
+import random
+
+import oftest.controller as controller
+import oftest.cstruct as ofp
+import oftest.message as message
+import oftest.dataplane as dataplane
+import oftest.action as action
+import oftest.parse as parse
+import oftest.base_tests as base_tests
+import time
+
+from oftest.testutils import *
+from time import sleep
+from FuncUtils import *
+
+
+
+class AllWildcardMatch(base_tests.SimpleDataPlane):
+
+ """Verify for an all wildcarded flow all the injected packets would match that flow"""
+
+ def runTest(self):
+
+ logging.info("Running All Wildcard Match test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting an all wildcarded flow and sending packets with various match fields")
+ logging.info("Expecting all sent packets to match")
+
+ #Insert an All Wildcarded flow.
+ wildcard_all(self,of_ports)
+
+ #check for different match fields and verify packet implements the action specified in the flow
+ pkt1 = simple_tcp_packet(dl_src="00:01:01:01:01:01");
+ self.dataplane.send(of_ports[0], str(pkt1))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self)
+
+ pkt2 = simple_tcp_packet(dl_dst="00:01:01:01:01:01");
+ self.dataplane.send(of_ports[0], str(pkt2))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self)
+
+ pkt3 = simple_tcp_packet(ip_src="192.168.2.1");
+ self.dataplane.send(of_ports[0], str(pkt3))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self)
+
+ pkt4 = simple_tcp_packet(ip_dst="192.168.2.2");
+ self.dataplane.send(of_ports[0], str(pkt4))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self)
+
+ pkt5 = simple_tcp_packet(ip_tos=2);
+ self.dataplane.send(of_ports[0], str(pkt5))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self)
+
+ pkt6 = simple_tcp_packet(tcp_sport=8080);
+ self.dataplane.send(of_ports[0], str(pkt6))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self)
+
+ pkt7 = simple_tcp_packet(tcp_dport=8081);
+ self.dataplane.send(of_ports[0], str(pkt7))
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self)
+
+
+
+class EthernetSrcAddress(base_tests.SimpleDataPlane):
+
+ """Verify match on single header field -- Ethernet Src Address """
+
+ def runTest(self):
+
+ logging.info("Running Ethernet Src Address test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ethernet Source Address ")
+ logging.info("Sending matching and non-matching ethernet packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Insert a Match On Ethernet Src Address flow
+ (pkt,match) = match_ethernet_src_address(self,of_ports)
+
+ #Sending packet matching the flow, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet , verify Packetin event gets triggered.
+ pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02');
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packets")
+
+class EthernetDstAddress(base_tests.SimpleDataPlane):
+
+ """Verify match on single Header Field Field -- Ethernet Dst Address """
+
+ def runTest(self):
+
+ logging.info("Running Ethernet Dst Address test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rv = delete_all_flows(self.controller)
+ self.assertEqual(rv, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ethernet Destination Address ")
+ logging.info("Sending matching and non-matching ethernet packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Insert a Match on Destination Address flow
+ (pkt,match) = match_ethernet_dst_address(self,of_ports)
+
+ #Send Packet matching the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Send Non-matching packet
+ pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02');
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ #Verify PacketIn event gets triggered
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+
+class EthernetType(base_tests.SimpleDataPlane):
+
+ """Verify match on single header field -- Ethernet Type """
+
+ def runTest(self):
+
+ logging.info("Running Ethernet Type test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ethernet Type ")
+ logging.info("Sending matching and non-matching ethernet packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Insert a Match on Ethernet-Type flow
+ (pkt,match) = match_ethernet_type(self,of_ports)
+
+ #Sending packet matching the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet ,
+ pkt2 = simple_eth_packet(dl_type=0x0806);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ #verify Packetin event gets triggered.
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
+
+
+class IngressPort(base_tests.SimpleDataPlane):
+
+ """Verify match on single Header Field Field -- In_port """
+
+ def runTest(self):
+
+ logging.info("Running Ingress Port test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ingress Port ")
+ logging.info("Sending matching and non-matching packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Insert a Match on Ingress Port FLow
+ (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
+
+ #Send Packet matching the flow i.e on in_port specified in the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Send Non-Matching Packet
+ self.dataplane.send(of_ports[1],str(pkt))
+
+ #Verify PacketIn event gets triggered
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
+
+class VlanId(base_tests.SimpleDataPlane):
+
+ """Verify match on single Header Field Field -- Vlan Id """
+
+ def runTest(self):
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on VLAN ID ")
+ logging.info("Sending matching and non-matching tagged packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ #Create a flow with match on Vlan Id
+ (pkt,match) = match_vlan_id(self,of_ports)
+
+ #Send tagged packet matching the flow i.e packet with same vlan id as in flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Send Non-matching packet, i.e packet with different Vlan Id
+ pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ #Verify PacketIn event gets triggered
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+class VlanPCP(base_tests.SimpleDataPlane):
+
+ """"Verify match on single Header Field Field -- Vlan Priority"""
+
+ def runTest(self):
+
+ logging.info("Running VlanPCP1 test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rv = delete_all_flows(self.controller)
+ self.assertEqual(rv, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on VLAN Priority ")
+ logging.info("Sending matching and non-matching tagged packets")
+ logging.info("Verifying matching packet implements the action specified in the flow")
+
+ #Create a flow matching on VLAN Priority
+ (pkt,match) = match_vlan_pcp(self,of_ports)
+
+ #Send tagged Packet matching the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Send tagged packet with same vlan_id but different vlan priority
+ pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20);
+ self.dataplane.send(in_port, str(pkt))
+
+class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
+
+ """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
+
+ def runTest(self):
+
+ logging.info("Running Multiple Header Field L2 test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
+ logging.info("Sending matching and non-matching packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ (pkt,match) = match_mul_l2(self,of_ports)
+
+ #Send eth packet matching the dl_type field, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered.
+ pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01');
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+ #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered.
+ pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02');
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+ #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
+ pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02');
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+class IpTos(base_tests.SimpleDataPlane):
+
+ """"Verify match on single Header Field Field -- Type of service"""
+
+ def runTest(self):
+
+ logging.info("Running Ip_Tos test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rv = delete_all_flows(self.controller)
+ self.assertEqual(rv, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ip_Tos ")
+ logging.info("Sending matching and non-matching tcp/ip packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Create a flow matching on VLAN Priority
+ (pkt,match) = match_ip_tos(self,of_ports)
+
+ #Send Packet matching the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Create a non-matching packet , verify packet_in get generated
+ pkt2 = simple_tcp_packet(ip_tos=2);
+ self.dataplane.send(of_ports[0], str(pkt2))
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+class IpProtocol(base_tests.SimpleDataPlane):
+
+ """"Verify match on single Header Field Field -- Ip Protocol"""
+
+ def runTest(self):
+
+ logging.info("Running Ip Protocol test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rv = delete_all_flows(self.controller)
+ self.assertEqual(rv, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Ip Protocol ")
+ logging.info("Sending matching and non-matching tcp/ip packets")
+ logging.info("Verifying only matching packets implements the action specified in the flow")
+
+ #Create a flow matching on VLAN Priority
+ (pkt,match) = match_ip_protocol(self,of_ports)
+
+ #Send Packet matching the flow
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Create a non-matching packet , verify packet_in get generated
+ pkt2 = simple_icmp_packet();
+ self.dataplane.send(of_ports[0], str(pkt2))
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+
+class TcpSrcPort(base_tests.SimpleDataPlane):
+
+ """Verify match on Single header field -- Tcp Source Port, """
+
+ def runTest(self):
+
+ logging.info("Running Tcp Src Port test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
+ logging.info("Sending matching and non-matching tcp packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ (pkt,match) = match_tcp_src(self,of_ports)
+
+ #Sending packet matching the tcp_sport, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet , verify Packetin event gets triggered.
+ pkt2 = simple_tcp_packet(tcp_sport=540);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+class TcpDstPort(base_tests.SimpleDataPlane):
+
+ """Verify match on Single header field -- Tcp Destination Port """
+
+ def runTest(self):
+
+ logging.info("Running Tcp Destination Port test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Tcp Destination Port ")
+ logging.info("Sending matching and non-matching packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ (pkt,match) = match_tcp_dst(self,of_ports)
+
+ #Sending packet matching the tcp_dport, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet , verify Packetin event gets triggered.
+ pkt2 = simple_tcp_packet(tcp_dport=541);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+
+class ExactMatch(base_tests.SimpleDataPlane):
+
+ """Verify match on Single header field -- Exact Match """
+
+ def runTest(self):
+
+ logging.info("Running Tcp Exact Match test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match for Exact Match ")
+ logging.info("Sending matching and non-matching packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ (pkt,match) = exact_match(self,of_ports)
+
+ #Sending packet matching all the fields of a tcp_packet, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet , verify Packetin event gets triggered.
+ pkt2 = simple_tcp_packet(tcp_sport=540);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+
+class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
+
+ """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
+
+ def runTest(self):
+
+ logging.info("Running Multiple Header Field L4 test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with match on Multiple Header Field L4 ")
+ logging.info("Sending matching and non-matching packets")
+ logging.info("Verifying matching packets implements the action specified in the flow")
+
+ (pkt,match) = match_mul_l4(self,of_ports)
+
+ #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
+ self.dataplane.send(of_ports[0], str(pkt))
+
+ #Verify packet implements the action specified in the flow
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+ #Sending non matching packet , verify Packetin event gets triggered.
+ pkt2 = simple_tcp_packet(tcp_sport=540,tcp_dport=541);
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
+ self.assertTrue(response is not None, "PacketIn not received for non matching packet")
+
+
+class ExactMatchPrio(base_tests.SimpleDataPlane):
+
+ """Verify that Exact Match has highest priority """
+
+ def runTest(self):
+
+ logging.info("Running Exact Match High Priority test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting a flow with Exact Match (low priority)")
+ logging.info("Inserting an overlapping wildcarded flow (higher priority)")
+ logging.info("Sending packets matching both the flows ")
+ logging.info("Verifying matching packets implements the action specified in the exact match flow")
+
+ #Insert two Overlapping Flows : Exact Match and Wildcard All.
+ (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
+ (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
+
+ #Sending packet matching both the flows ,
+ self.dataplane.send(of_ports[0], str(pkt2))
+
+ #verify it implements the action specified in Exact Match Flow
+ egress_port=of_ports[2]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = egress_port
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+
+class WildcardMatchPrio(base_tests.SimpleDataPlane):
+
+ """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
+
+ def runTest(self):
+
+ logging.info("Running Wildcard Match High Priority test")
+
+ of_ports = config["port_map"].keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+ #Clear Switch State
+ rc = delete_all_flows(self.controller)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ logging.info("Inserting two wildcarded flows with priorities ")
+ logging.info("Sending packets matching the flows")
+ logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
+
+ (pkt,match) = wildcard_all(self,of_ports,priority=20)
+ (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
+
+ #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
+ self.dataplane.send(of_ports[0], str(pkt1))
+
+ egress_port=of_ports[1]
+ no_ports=set(of_ports).difference([egress_port])
+ yes_ports = of_ports[1]
+ receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
+
+
+
+
+