Example #1
0
    def runTest(self):
        global fs_port_map

        # TODO: set from command-line parameter
        test_timeout = 60

        of_ports = fs_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
        ingress_port = of_ports[0];
        egress_port1 = of_ports[1];
        egress_port2 = of_ports[2];

        rc = delete_all_flows(self.controller, fs_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        pkt1 = simple_tcp_packet()
        flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
       
        pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
        flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
       
        fs_logger.info("Inserting flow1")
        rv = self.controller.message_send(flow_mod_msg1)
        self.assertTrue(rv != -1, "Error installing flow mod")
        fs_logger.info("Inserting flow2")
        rv = self.controller.message_send(flow_mod_msg2)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        num_pkt1s = random.randint(10,30)
        fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
        num_pkt2s = random.randint(10,30)
        fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
        for i in range(0,num_pkt1s):
            sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
        for i in range(0,num_pkt2s):
            sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
            
        match1 = parse.packet_to_flow_match(pkt1)
        fs_logger.info("Verifying flow1's " + str(num_pkt1s) + " packets")
        self.verifyStats(match1, ofp.OFPP_NONE, test_timeout, num_pkt1s)
        match2 = parse.packet_to_flow_match(pkt2)
        fs_logger.info("Verifying flow2's " + str(num_pkt2s) + " packets")
        self.verifyStats(match2, ofp.OFPP_NONE, test_timeout, num_pkt2s)
        match1.wildcards |= ofp.OFPFW_DL_SRC
        fs_logger.info("Verifying combined " + str(num_pkt1s+num_pkt2s) + " packets")
        self.verifyStats(match1, ofp.OFPP_NONE, test_timeout, 
                         num_pkt1s+num_pkt2s)
Example #2
0
def exact_match(self,of_ports,priority=None):
    '''
    Generates and installs a flow message with all match fields
    set that are defined for the current conformance profile.
    The conformance profile is defined as oft optional argument
    --conformance ["l2", "l3", "full"]
    '''

    pkt_exactflow = simple_tcp_packet()
    match = parse.packet_to_flow_match(pkt_exactflow)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")
    # in_port is not automatically set in parse.packet_to_flow_match
    match.in_port = of_ports[0]
    match.wildcards &= ~ofp.OFPFW_IN_PORT
    #match.nw_src = 1
    #match.wildcards=0
    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_exactflow,match)
Example #3
0
 def runTest(self):
     logging=get_logger()
     logging.info("Running Grp70No110 forward Enqueue test")
     of_ports=config["port_map"].keys()
     of_ports.sort()
     self.assertTrue(len(of_ports)>1,"Not enough ports for test")
     
     rv=delete_all_flows(self.controller)
     self.assertTrue(rv==0, "Could not send the delete flow_mod")
     self.assertEqual(do_barrier(self.controller),0,"Barrier Failed")
     
     logging.info("Installing a flow with output action Enqueue")
     pkt=simple_tcp_packet()
     match=parse.packet_to_flow_match(pkt)
     match.wildcards = ofp.OFPFW_ALL
     msg=message.flow_mod()
     msg.command = ofp.OFPFC_ADD
     msg.match=match
     msg.buffer_id = 0xffffffff
     act=action.action_enqueue()
     act.port=of_ports[1]
     act.queue_id=50
     self.assertTrue(msg.actions.add(act),"could not add action to the flow_mod")
     rc=self.controller.message_send(msg)
     self.assertTrue(rc!=-1,"Could not send the flow_mod")
     self.assertEqual(do_barrier(self.controller),0,"Barrier failed")
     self.dataplane.send(of_ports[0], str(pkt))
     receive_pkt_check(self.dataplane, pkt, [of_ports[1]], set(of_ports).difference([of_ports[1]]), self)
Example #4
0
def match_ip_dst(self, of_ports, wildcard_bits, priority=None):
    # Generate match on ip_dst address

    # Create a simple tcp packet and generate match on ip src address
    pkt = simple_tcp_packet(ip_dst="192.168.100.100")
    match = parse.packet_to_flow_match(pkt)

    # @param val is number of bits we need to wild-card in the ip_src add
    # @ can take values from 0 (exact-match) 32 (for wild-card all)
    val = wildcard_bits

    wildcards = (ofp.OFPFW_ALL & ~ofp.OFPFW_NW_DST_MASK) | (val << ofp.OFPFW_NW_DST_SHIFT)

    msg = message.flow_mod()
    msg.match = match
    if priority != None:
        msg.priority = priority
    act = action.action_output()
    act.port = of_ports[1]
    rv = msg.actions.add(act)
    self.assertTrue(rv, "Could not add output action " + str(of_ports[1]))
    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, match)
Example #5
0
def match_icmp_code(self, of_ports, priority=None):
    # Generate Match on icmp code

    # Create a simple icmp packet and generate match on icmp type
    pkt = simple_icmp_packet(icmp_type=3, icmp_code=0)
    match = parse.packet_to_flow_match(pkt)
    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 ^ ofp.OFPFW_TP_SRC ^ ofp.OFPFW_TP_DST
    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, match)
Example #6
0
    def runTest(self):

        logging.info("Running PacketInBodyMiss Test")
        of_ports = config["port_map"].keys()
        of_ports.sort()

        #Clear switch state      
        delete_all_flows(self.controller)

        #Set miss_send_len field 
        logging.info("Sending  set_config_request to set miss_send_len... ")
        req = ofp.message.set_config()
        req.miss_send_len = 65535
        self.controller.message_send(req)
        sleep(1)

        # Send packet to trigger packet_in event
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        self.assertTrue(match is not None, "Could not generate flow match from pkt")
        match.wildcards=ofp.OFPFW_ALL
        match.in_port = of_ports[0]
        self.dataplane.send(of_ports[0],str(pkt))

        #Verify packet_in generated
        response = verify_packet_in(self, str(pkt), of_ports[0], ofp.OFPR_NO_MATCH)

        #Verify Frame Total Length Field in Packet_in 
        self.assertEqual(response.total_len,len(str(pkt)), "PacketIn total_len field is incorrect")

        #Verify data field 
        self.assertTrue(len(response.data) == len(str(pkt)), "Complete Data packet was not sent")
Example #7
0
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)
Example #8
0
def match_udp_src(self,of_ports,priority=None):
    #Generate Match_Udp_Src

    #Create a simple udp packet and generate match on udp source port flow
    pkt_matchtSrc = simple_udp_packet(udp_sport=111)
    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_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
    msg.buffer_id = 0xffffffff
    msg.match = match
    if priority != None :
        msg.priority = priority

    act = action.action_output()
    act.port = of_ports[1]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_matchtSrc,match)  
Example #9
0
def Wildcard_All_Except_Ingress(self,of_ports,priority=0):
# Generate Wildcard_All_Except_Ingress_port flow
        

        #Create a simple tcp packet and generate wildcard all except ingress_port flow.
        Pkt_MatchIngress = simple_tcp_packet()
        match3 = parse.packet_to_flow_match(Pkt_MatchIngress)
        self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
        match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
        match3.in_port = of_ports[0]

        msg3 = message.flow_mod()
        msg3.command = ofp.OFPFC_ADD
        msg3.match = match3
        msg3.out_port = of_ports[2] # ignored by flow add,flow modify 
        msg3.cookie = random.randint(0,9007199254740992)
        msg3.buffer_id = 0xffffffff
        msg3.idle_timeout = 0
        msg3.hard_timeout = 0
        msg3.buffer_id = 0xffffffff
       
        act3 = action.action_output()
        act3.port = of_ports[1]
        self.assertTrue(msg3.actions.add(act3), "could not add action")

        if priority != 0 :
                msg3.priority = priority

        rv = self.controller.message_send(msg3)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        return (Pkt_MatchIngress,match3)
Example #10
0
def wildcard_all_except_ingress1(self,of_ports,priority=None):
# Generate Wildcard_All_Except_Ingress_port flow with action output to port egress_port 2 
        

    #Create a simple tcp packet and generate wildcard all except ingress_port flow.
    pkt_matchingress = simple_tcp_packet()
    match3 = parse.packet_to_flow_match(pkt_matchingress)
    self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
    match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
    match3.in_port = of_ports[0]

    msg3 = message.flow_mod()
    msg3.command = ofp.OFPFC_ADD
    msg3.match = match3
    msg3.out_port = of_ports[2] # ignored by flow add,flow modify 
    msg3.cookie = random.randint(0,9007199254740992)
    msg3.buffer_id = 0xffffffff
    msg3.idle_timeout = 0
    msg3.hard_timeout = 0
    msg3.buffer_id = 0xffffffff
       
    act3 = action.action_output()
    act3.port = of_ports[2]
    msg3.actions.add(act3)
    if priority != None :
        msg3.priority = priority

    self.controller.message_send(msg3)
    do_barrier(self.controller)

    return (pkt_matchingress,match3)
Example #11
0
def match_vlan_id(self,of_ports,priority=None):
    #Generate Match_Vlan_Id

    #Create a simple tcp packet and generate match on ethernet dst address flow
    pkt_matchvlanid = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1)
    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_TYPE ^ofp.OFPFW_DL_VLAN
    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]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_matchvlanid,match)
Example #12
0
def wildcard_all(self,of_ports,priority=None):
# Generate a Wildcard_All Flow 

    #Create a simple tcp packet and generate wildcard all flow match from it.  
    pkt_wildcard = simple_tcp_packet()
    match2 = parse.packet_to_flow_match(pkt_wildcard)
    self.assertTrue(match2 is not None, "Could not generate flow match from pkt")
    match2.wildcards=ofp.OFPFW_ALL
    match2.in_port = of_ports[0]

    msg2 = message.flow_mod()
    msg2.out_port = ofp.OFPP_NONE
    msg2.command = ofp.OFPFC_ADD
    msg2.buffer_id = 0xffffffff
    msg2.match = match2
    act2 = action.action_output()
    act2.port = of_ports[1]
    msg2.actions.add(act2)
    if priority != None :
        msg2.priority = priority

    self.controller.message_send(msg2)
    do_barrier(self.controller)

    return (pkt_wildcard,match2)
Example #13
0
def match_ethernet_dst_address(self,of_ports,priority=None):
    #Generate Match_Ethernet_Dst_Address flow

    #Create a simple tcp packet and generate match on ethernet dst address flow
    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")

    match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST
    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]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_matchdst,match)
Example #14
0
def create_flow_msg(packet = None, in_port = None, match = None, apply_action_list = []):

    apply_inst = instruction.instruction_apply_actions()

    if apply_action_list is not None:
        for act in apply_action_list:
            apply_inst.actions.add(act)

    request = message.flow_mod()
    request.match.type = ofp.OFPMT_OXM

    if match is None:
        match = parse.packet_to_flow_match(packet)
    
    request.match_fields = match
    
    if in_port != None:
        match_port = testutils.oxm_field.in_port(in_port)
        request.match_fields.tlvs.append(match_port)
    request.buffer_id = 0xffffffff
    request.priority = 1000
    
    request.instructions.add(apply_inst)

    return request
Example #15
0
def match_mul_l2(self,of_ports,priority=None):
    #Generate Match_Mul_L2 flow

    #Create a simple eth packet and generate match on ethernet protocol flow
    pkt_mulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02')
    match = parse.packet_to_flow_match(pkt_mulL2)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")

    match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC
    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]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_mulL2,match)
Example #16
0
def match_all_except_source_address(self,of_ports,priority=None):
# Generate Match_All_Except_Source_Address flow
        
    #Create a simple tcp packet and generate match all except src address flow.
    pkt_wildcardsrc= simple_tcp_packet()
    match1 = parse.packet_to_flow_match(pkt_wildcardsrc)
    self.assertTrue(match1 is not None, "Could not generate flow match from pkt")
    match1.in_port = of_ports[0]
    #match1.nw_src = 1
    match1.wildcards = ofp.OFPFW_DL_SRC
    msg1 = message.flow_mod()
    msg1.out_port = ofp.OFPP_NONE
    msg1.command = ofp.OFPFC_ADD
    msg1.buffer_id = 0xffffffff
    msg1.match = match1
    if priority != None :
        msg1.priority = priority

    act1 = action.action_output()
    act1.port = of_ports[1]
    msg1.actions.add(act1)

    self.controller.message_send(msg1)
    do_barrier(self.controller)

    return (pkt_wildcardsrc,match1)
Example #17
0
def match_arp(self, of_ports, srcb=0, dstb=0, priority=None):
    arp_pkt = simple_arp_packet()
    match = parse.packet_to_flow_match(arp_pkt, match_on_arp=True)
    self.assertTrue(match is not None, "Could not create a match from the packet")
    if srcb==1:
        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^(63<<ofp.OFPFW_NW_SRC_SHIFT)
    elif dstb==1:
        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^(63<<ofp.OFPFW_NW_DST_SHIFT)
    else :
        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
    msg = message.flow_mod()
    msg.outport = 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 (arp_pkt,match)
Example #18
0
def Exact_Match(self,of_ports,priority=0):
# Generate ExactMatch flow .

        #Create a simple tcp packet and generate exact flow match from it.
        Pkt_ExactFlow = simple_tcp_packet()
        match = parse.packet_to_flow_match(Pkt_ExactFlow)
        self.assertTrue(match is not None, "Could not generate flow match from pkt")
        match.in_port = of_ports[0]
        #match.nw_src = 1
        match.wildcards=0
        msg = message.flow_mod()
        msg.out_port = ofp.OFPP_NONE
        msg.command = ofp.OFPFC_ADD
        msg.buffer_id = 0xffffffff
        msg.match = match
        if priority != 0 :
                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_ExactFlow,match)
Example #19
0
def Wildcard_All(self,of_ports,priority=0):
# Generate a Wildcard_All Flow 

        #Create a simple tcp packet and generate wildcard all flow match from it.  
        Pkt_Wildcard = simple_tcp_packet()
        match2 = parse.packet_to_flow_match(Pkt_Wildcard)
        self.assertTrue(match2 is not None, "Could not generate flow match from pkt")
        match2.wildcards=ofp.OFPFW_ALL
        match2.in_port = of_ports[0]

        msg2 = message.flow_mod()
        msg2.out_port = ofp.OFPP_NONE
        msg2.command = ofp.OFPFC_ADD
        msg2.buffer_id = 0xffffffff
        msg2.match = match2
        act2 = action.action_output()
        act2.port = of_ports[1]
        self.assertTrue(msg2.actions.add(act2), "could not add action")
        if priority != 0 :
                msg2.priority = priority

        rv = self.controller.message_send(msg2)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        return (Pkt_Wildcard,match2)
Example #20
0
def Match_All_Except_Source_Address(self,of_ports,priority=0):
# Generate Match_All_Except_Source_Address flow
        
        #Create a simple tcp packet and generate match all except src address flow.
        Pkt_WildcardSrc= simple_tcp_packet()
        match1 = parse.packet_to_flow_match(Pkt_WildcardSrc)
        self.assertTrue(match1 is not None, "Could not generate flow match from pkt")
        match1.in_port = of_ports[0]
        #match1.nw_src = 1
        match1.wildcards = ofp.OFPFW_DL_SRC
        msg1 = message.flow_mod()
        msg1.out_port = ofp.OFPP_NONE
        msg1.command = ofp.OFPFC_ADD
        msg1.buffer_id = 0xffffffff
        msg1.match = match1
        if priority != 0 :
                msg1.priority = priority

        act1 = action.action_output()
        act1.port = of_ports[1]
        self.assertTrue(msg1.actions.add(act1), "could not add action")

        rv = self.controller.message_send(msg1)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        return (Pkt_WildcardSrc,match1)
Example #21
0
def match_ethernet_type(self,of_ports,priority=None):
    #Generate a Match_Ethernet_Type flow

    #Create a simple tcp packet and generate match on ethernet type flow
    pkt_matchtype = simple_eth_packet(dl_type=0x88cc)
    match = parse.packet_to_flow_match(pkt_matchtype)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")

    match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
    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_matchtype,match)
Example #22
0
def match_vlan_pcp(self,of_ports,priority=None):
    #Generate Match_Vlan_Priority

    #Create a simple tcp packet and generate match on ethernet dst address flow
    pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=5)
    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_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
    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_matchvlanpcp,match)
Example #23
0
def match_tcp_dst(self,of_ports,priority=None):
    #Generate Match_Tcp_Dst

        #Create a simple tcp packet and generate match on tcp destination port flow
    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_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
    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_matchdst,match)        
Example #24
0
def match_mul_l2(self,of_ports,priority=None):
    #Generate Match_Mul_L2 flow

    #Create a simple eth packet and generate match on ethernet protocol flow
    pkt_mulL2 = simple_tcp_packet(dl_vlan_enable=True, dl_src= '00:00:00:01:01:01', dl_dst= '00:00:00:01:01:02', dl_vlan=3)
    match = parse.packet_to_flow_match(pkt_mulL2)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")

    match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_IN_PORT ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC ^ofp.OFPFW_DL_VLAN
    match.in_port=of_ports[0]
    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_mulL2,match)
    def runTest(self):

        logging.info("Running Delete_Emer_Flow")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        
        #Clear switch state        
        delete_all_flows(self.controller)

        logging.info("Inserting a emergency flow with send_flow_removed flag set")
        logging.info("Expecting no flow_removed_message on the deletion of the emergency flow")
        
        # Insert a flow with emergency bit set.
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.in_port = of_ports[0]
        request = ofp.message.flow_add()
        request.match = match
        request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
        act = ofp.action.output()
        act.port = of_ports[1]
        request.actions.append(act)

        self.controller.message_send(request)
        
        # Delete the emergency flow
        
        nonstrict_delete(self,match)
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
                                               timeout=2)
        self.assertTrue(response is None, 
                        'Test Failed ')
Example #26
0
def match_icmp_code(self,of_ports,priority=None):
    #Generate Match_Icmp_Code

    #Create a simple icmp packet and generate match on icmp code flow
    pkt_match = simple_icmp_packet(icmp_code=3)
    match = parse.packet_to_flow_match(pkt_match)
    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 ^ofp.OFPFW_TP_DST
    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]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_match, match)  
Example #27
0
def exact_match_with_prio(self,of_ports,priority=None):
    # Generate ExactMatch with action output to port 2

    #Create a simple tcp packet and generate exact flow match from it.
    pkt_exactflow = simple_tcp_packet()
    match = parse.packet_to_flow_match(pkt_exactflow)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")
    match.in_port = of_ports[0]
    #match.nw_src = 1
    match.wildcards=0
    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[2]
    msg.actions.add(act)

    self.controller.message_send(msg)
    do_barrier(self.controller)

    return (pkt_exactflow,match)         
Example #28
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        pktlen = 104
        mpls_label = 0xa5f05 # no specific meaning
        mpls_tc = 5
        mpls_ttl = 129
        pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                 mpls_label=mpls_label,
                                                 mpls_tc=mpls_tc,
                                                 mpls_ttl=mpls_ttl)

        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        new_mpls_ttl = mpls_ttl+1
        exp_pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                     mpls_label=mpls_label,
                                                     mpls_tc=mpls_tc,
                                                     mpls_ttl=new_mpls_ttl)

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        act = action.action_set_mpls_ttl()
        act.mpls_ttl = new_mpls_ttl
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_dec_mpls_ttl()
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match = match,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Example #29
0
    def runTest(self):
        global fe_port_map

        # TODO: set from command-line parameter
        test_timeout = 60

        of_ports = fe_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        rc = delete_all_flows(self.controller, fe_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.wildcards &= ~ofp.OFPFW_IN_PORT
        self.assertTrue(match is not None, 
                        "Could not generate flow match from pkt")
        act = action.action_output()

        of_ports = fe_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        ingress_port = of_ports[0]
        egress_port  = of_ports[1]
        fe_logger.info("Ingress " + str(ingress_port) + 
                       " to egress " + str(egress_port))
        
        match.in_port = ingress_port
        
        request = message.flow_mod()
        request.match = match
        request.cookie = random.randint(0,9007199254740992)
        request.buffer_id = 0xffffffff
        request.idle_timeout = 1
        request.flags |= ofp.OFPFF_SEND_FLOW_REM
        act.port = egress_port
        self.assertTrue(request.actions.add(act), "Could not add action")
        
        fe_logger.info("Inserting flow")
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
                                               timeout=test_timeout)

        self.assertTrue(response is not None, 
                        'Did not receive flow removed message ')

        self.assertEqual(request.cookie, response.cookie,
                         'Cookies do not match')

        self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
                         'Flow table entry removal reason is not idle_timeout')

        self.assertEqual(match, response.match,
                         'Flow table entry does not match')
Example #30
0
def flow_msg_create(parent, pkt, ing_port=None, action_list=None, wildcards=None,
               egr_ports=None, egr_queue=None, check_expire=False, in_band=False):
    """
    Create a flow message

    Match on packet with given wildcards.  
    See flow_match_test for other parameter descriptoins
    @param egr_queue if not None, make the output an enqueue action
    @param in_band if True, do not wildcard ingress port
    @param egr_ports None (drop), single port or list of ports
    """
    match = parse.packet_to_flow_match(pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")
    if wildcards is None:
        wildcards = required_wildcards(parent)
    if in_band:
        wildcards &= ~ofp.OFPFW_IN_PORT
    match.wildcards = wildcards
    match.in_port = ing_port

    if type(egr_ports) == type([]):
        egr_port_list = egr_ports
    else:
        egr_port_list = [egr_ports]

    request = message.flow_mod()
    request.match = match
    request.buffer_id = 0xffffffff
    if check_expire:
        request.flags |= ofp.OFPFF_SEND_FLOW_REM
        request.hard_timeout = 1

    if action_list is not None:
        for act in action_list:
            logging.debug("Adding action " + act.show())
            rv = request.actions.add(act)
            parent.assertTrue(rv, "Could not add action" + act.show())

    # Set up output/enqueue action if directed
    if egr_queue is not None:
        parent.assertTrue(egr_ports is not None, "Egress port not set")
        act = action.action_enqueue()
        for egr_port in egr_port_list:
            act.port = egr_port
            act.queue_id = egr_queue
            rv = request.actions.add(act)
            parent.assertTrue(rv, "Could not add enqueue action " + 
                              str(egr_port) + " Q: " + str(egr_queue))
    elif egr_ports is not None:
        for egr_port in egr_port_list:
            act = action.action_output()
            act.port = egr_port
            rv = request.actions.add(act)
            parent.assertTrue(rv, "Could not add output action " + 
                              str(egr_port))

    logging.debug(request.show())

    return request
Example #31
0
    def runTest(self):

        logging.info("Running Forward_All test")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        #Clear switch state
        delete_all_flows(self.controller)

        logging.info("Insert a flow with output action port OFPP_ALL")
        logging.info("Send packet matching the flow")
        logging.info(
            "Expecting packet on all dataplane ports except ingress_port")

        #Create a packet
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        act = ofp.action.output()

        #Delete all flows
        delete_all_flows(self.controller)
        ingress_port = of_ports[0]
        match.in_port = ingress_port

        #Create a flow mod with action.port = OFPP_ALL
        request = ofp.message.flow_add()
        request.match = match
        request.match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_IN_PORT
        act.port = ofp.OFPP_ALL
        request.actions.append(act)

        logging.info("Inserting flow")
        self.controller.message_send(request)
        do_barrier(self.controller)

        #Send Packet matching the flow
        logging.info("Sending packet to dp port " + str(ingress_port))
        self.dataplane.send(ingress_port, str(pkt))

        #Verifying packets recieved on expected dataplane ports
        yes_ports = set(of_ports).difference([ingress_port])
        verify_packets(self, pkt, yes_ports)
Example #32
0
    def runTest(self):

        logging.info("Running Forward_Inport test")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        #Clear switch state
        delete_all_flows(self.controller)

        logging.info("Insert a flow with output action port OFPP_INPORT")
        logging.info("Send packet matching the flow")
        logging.info("Expecting packet on the input port")

        #Create a packet
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        act = ofp.action.output()

        #Delete the flows
        delete_all_flows(self.controller)
        ingress_port = of_ports[0]
        match.in_port = ingress_port

        # Create a flow mod message
        request = ofp.message.flow_add()
        request.match = match
        act.port = ofp.OFPP_IN_PORT

        request.actions.append(act)
        logging.info("Inserting flow")
        self.controller.message_send(request)
        do_barrier(self.controller)

        #Send packet matching the flow
        logging.info("Sending packet to dp port " + str(ingress_port))
        self.dataplane.send(ingress_port, str(pkt))
        yes_ports = [ingress_port]

        #Verfying packet recieved on expected dataplane ports
        receive_pkt_check(self.dataplane, pkt, yes_ports,
                          set(of_ports).difference([ingress_port]), self)
Example #33
0
    def runTest(self):

        logging.info("Running Delete_Emer_Flow")

        of_ports = config["port_map"].keys()
        of_ports.sort()

        #Clear switch state
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        logging.info(
            "Inserting a emergency flow with send_flow_removed flag set")
        logging.info(
            "Expecting no flow_removed_message on the deletion of the emergency flow"
        )

        # Insert a flow with emergency bit set.
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.in_port = of_ports[0]
        request = message.flow_mod()
        request.match = match
        request.command = ofp.OFPFC_ADD
        request.flags = request.flags | ofp.OFPFF_EMERG | ofp.OFPFF_SEND_FLOW_REM
        act = action.action_output()
        act.port = of_ports[1]
        request.actions.add(act)

        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Flow addition failed.")

        # Delete the emergency flow

        NonStrict_Delete(self, match)
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM,
                                               timeout=2)
        self.assertTrue(response is None, 'Test Failed ')
Example #34
0
def enqueue(self,ingress_port,egress_port,egress_queue_id):
#Generate a flow with enqueue action i.e output to a queue configured on a egress_port

    pkt = simple_tcp_packet()
    match = parse.packet_to_flow_match(pkt)
    match.wildcards &= ~ofp.OFPFW_IN_PORT
    self.assertTrue(match is not None, 
            "Could not generate flow match from pkt")
    
    match.in_port = ingress_port
    request = message.flow_mod()
    request.match = match
    request.buffer_id = 0xffffffff
    act = action.action_enqueue()
    act.port     = egress_port
    act.queue_id = egress_queue_id
    self.assertTrue(request.actions.add(act), "Could not add action")
    
    logging.info("Inserting flow")
    rv = self.controller.message_send(request)
    self.assertTrue(rv != -1, "Error installing flow mod")
    self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
    return (pkt,match)
Example #35
0
    def runTest(self):

        logging.info("Running PacketInBodyMiss Test")
        of_ports = config["port_map"].keys()
        of_ports.sort()

        #Clear switch state
        delete_all_flows(self.controller)

        #Set miss_send_len field
        logging.info("Sending  set_config_request to set miss_send_len... ")
        req = ofp.message.set_config()
        req.miss_send_len = 65535
        self.controller.message_send(req)
        sleep(1)

        # Send packet to trigger packet_in event
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        self.assertTrue(match is not None,
                        "Could not generate flow match from pkt")
        match.wildcards = ofp.OFPFW_ALL
        match.in_port = of_ports[0]
        self.dataplane.send(of_ports[0], str(pkt))

        #Verify packet_in generated
        response = verify_packet_in(self, str(pkt), of_ports[0],
                                    ofp.OFPR_NO_MATCH)

        #Verify Frame Total Length Field in Packet_in
        self.assertEqual(response.total_len, len(str(pkt)),
                         "PacketIn total_len field is incorrect")

        #Verify data field
        self.assertTrue(
            len(response.data) == len(str(pkt)),
            "Complete Data packet was not sent")
Example #36
0
def create_flow_msg(packet=None,
                    in_port=None,
                    match=None,
                    apply_action_list=[]):

    apply_inst = instruction.instruction_apply_actions()

    if apply_action_list is not None:
        for act in apply_action_list:
            apply_inst.actions.add(act)

    request = message.flow_mod()

    if packet != None:
        match = parse.packet_to_flow_match(packet)
        match.wildcards = 0
        match.in_port = in_port

    request.match = match
    request.buffer_id = 0xffffffff

    request.instructions.add(apply_inst)

    return request
Example #37
0
def match_ethernet_type(self,of_ports,priority=None):
    #Generate a Match_Ethernet_Type flow
    #Create a simple tcp packet and generate match on ethernet type flow
    pkt_matchtype = simple_eth_packet(dl_dst='AC:81:12:99:47:0F',dl_src ='da:c9:f1:19:72:cf',dl_type = 0x88cc)
    match = parse.packet_to_flow_match(pkt_matchtype)
    self.assertTrue(match is not None, "Could not generate flow match from pkt")

    match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
    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_matchtype,match)
Example #38
0
def Wildcard_All(self,of_ports,priority=0):
# Generate a Wildcard_All Flow 

        #Create a simple tcp packet and generate wildcard all flow match from it.  
        Pkt_Wildcard = simple_tcp_packet()
        match2 = parse.packet_to_flow_match(Pkt_Wildcard)
        self.assertTrue(match2 is not None, "Could not generate flow match from pkt")
        match2.wildcards=ofp.OFPFW_ALL
        msg2 = message.flow_mod()
        msg2.out_port = ofp.OFPP_NONE
        msg2.command = ofp.OFPFC_ADD
        msg2.buffer_id = 0xffffffff
        msg2.match = match2
        act2 = action.action_output()
        act2.port = of_ports[2]
        self.assertTrue(msg2.actions.add(act2), "could not add action")
        if priority != 0 :
                msg2.priority = priority

        rv = self.controller.message_send(msg2)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        return (Pkt_Wildcard,match2)
    def runTest(self):

        logging.info("Running Delete_Emer_Flow")

        of_ports = config["port_map"].keys()
        of_ports.sort()

        #Clear switch state
        delete_all_flows(self.controller)

        logging.info(
            "Inserting a emergency flow with send_flow_removed flag set")
        logging.info(
            "Expecting no flow_removed_message on the deletion of the emergency flow"
        )

        # Insert a flow with emergency bit set.
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.in_port = of_ports[0]
        request = ofp.message.flow_add()
        request.match = match
        request.flags = request.flags | ofp.OFPFF_EMERG | ofp.OFPFF_SEND_FLOW_REM
        request.buffer_id = 0xffffffff
        act = ofp.action.output()
        act.port = of_ports[1]
        request.actions.append(act)

        self.controller.message_send(request)

        # Delete the emergency flow

        nonstrict_delete(self, match)
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM,
                                               timeout=2)
        self.assertTrue(response is None, 'Test Failed ')
Example #40
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running Grp10No110 test ")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 0, "Not enough ports for test")

        #Clear switch state
        rv = delete_all_flows(self.controller)
        self.assertEqual(rv, 0, "Failed to delete all flows")
        rc = delete_all_flows_emer(self.controller)
        self.assertEqual(rc, 0, "Failed to send delete-emergency flow")

        response, pkt = self.controller.poll(ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(
            response is None,
            "Emergency flow cannot be deleted: Check if the Switch supports Emergency Mode"
        )

        #Insert an emergency flow entry
        test_packet = simple_tcp_packet()
        match = parse.packet_to_flow_match(test_packet)
        e_flow_mod = message.flow_mod()
        match = parse.packet_to_flow_match(test_packet)
        e_flow_mod.match = match
        e_flow_mod.flags = e_flow_mod.flags | ofp.OFPFF_EMERG
        e_flow_mod.match.in_port = of_ports[0]
        act = action.action_output()
        act.port = of_ports[1]
        self.assertTrue(e_flow_mod.actions.add(act), "Failed to add action")

        rv = self.controller.message_send(e_flow_mod)
        response = None
        response, pkt = self.controller.poll(ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(response is None, "Unable to add emergency flows")
        self.assertTrue(rv != -1, "Unable to send a flow_mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        # Assert matching dataplane packet isn't forwarded.
        self.dataplane.send(of_ports[0], str(test_packet))

        #Verify dataplane packet should not be forwarded
        yes_ports = []
        no_ports = set(of_ports)
        receive_pkt_check(self.dataplane, test_packet, yes_ports, no_ports,
                          self)

        #Shutdown the controller
        self.controller.initial_hello = False
        self.controller.disconnect()
        #waiting for the switch to recognize the connection drop.
        sleep(2)

        assertionerr = False

        pkt = simple_tcp_packet()
        logging.info("checking for control channel status")
        try:
            for x in range(15):
                logging.info("Sending an unmatched packet")
                self.dataplane.send(of_ports[1], str(pkt))
                (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,
                                                       timeout=10)
                self.assertTrue(
                    response is not None,
                    'PacketIn is not generated--Control plane is down')
        except AssertionError:

            #Send a simple tcp packet on ingress_port
            logging.info("Control channel is down")
            logging.info("Sending simple tcp packet ...")
            logging.info(
                "Checking for Emergency flows status after controller shutdown"
            )
            self.dataplane.send(of_ports[0], str(test_packet))

            #Verify dataplane packet should be forwarded
            yes_ports = [of_ports[1]]
            no_ports = set(of_ports).difference(yes_ports)
            receive_pkt_check(self.dataplane, test_packet, yes_ports, no_ports,
                              self)
            logging.info(
                "Emergency flows are active after control channel is disconnected"
            )
            assertionerr = True

        else:
            self.assertTrue(assertionerr is True,
                            "Failed to shutdown the control plane")

        self.controller.initial_hello = True
        self.controller.connect()
        sleep(3)
        features = message.features_request()
        rv = self.controller.message_send(features)
        # for i in range(10):
        # sleep(2)
        (response, raw) = self.controller.poll(ofp.OFPT_FEATURES_REPLY,
                                               timeout=5)

        self.assertTrue(response is not None,
                        "Control channel connection could not be established")

        logging.info("Control channel is up")
        logging.info("Sending simple tcp packet ...")
        logging.info(
            "Checking for Emergency flows status after controller reconnection"
        )
        self.dataplane.send(of_ports[0], str(test_packet))

        #Verify dataplane packet should be forwarded
        yes_ports = [of_ports[1]]
        no_ports = set(of_ports).difference(yes_ports)
        receive_pkt_check(self.dataplane, test_packet, yes_ports, no_ports,
                          self)
        logging.info(
            "Emergency flows are active after control channel is reconnected")

        logging.info("Cleaning up emergency flows")
        rc = delete_all_flows_emer(self.controller)
        self.assertEqual(rc, 0, "Failed to send delete-emergency flow")
        res, pkt = self.controller.poll(ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(res is None, "Emergency flows could not be deleted.")
Example #41
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running EmergencyMode2 test ")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 0, "Not enough ports for test")

        #Clear switch state
        rv = delete_all_flows(self.controller)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        #Insert an emergency flow entry
        test_packet = simple_tcp_packet()
        e_flow_mod = message.flow_mod()
        match = parse.packet_to_flow_match(test_packet)
        e_flow_mod.match = match
        e_flow_mod.flags = e_flow_mod.flags | ofp.OFPFF_EMERG
        e_flow_mod.in_port = of_ports[0]
        act = action.action_output()
        act.port = of_ports[1]
        self.assertTrue(e_flow_mod.actions.add(act), "Failed to add action")

        rv = self.controller.message_send(e_flow_mod)
        self.assertTrue(rv != -1, "Error Cannot Send flow_mod")
        response, pkt = self.controller.poll(ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(response is None, "Unable to add emergency flows")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        #Shutdown the controller
        self.controller.shutdown()

        assertionerr = False

        pkt = simple_tcp_packet()
        logging.info("checking for control channel status")
        try:
            for x in range(15):
                self.dataplane.send(of_ports[1], str(pkt))
                (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,
                                                       timeout=15)
                self.assertTrue(
                    response is not None,
                    'PacketIn is not generated--Control plane is down')
        except AssertionError:

            #Send a simple tcp packet on ingress_port
            logging.info("Control channel is down")
            logging.info("Sending simple tcp packet ...")
            logging.info(
                "Checking for Emergency flows status after controller shutdown"
            )
            self.dataplane.send(of_ports[0], str(test_packet))

            #Verify dataplane packet should not be forwarded

            yes_ports = [of_ports[1]]
            no_ports = set(of_ports).difference(yes_ports)
            receive_pkt_check(self.dataplane, test_packet, yes_ports, no_ports,
                              self)
            logging.info(
                "Emergency flows are active after control channel is disconnected"
            )
            assertionerr = True

        else:
            self.assertTrue(assertionerr is True,
                            "Failed to shutdown the control plane")

        logging.info("Cleaning up emergency flows")
        rc = delete_all_flows_emer(self.controller)
        self.assertEqual(rc, 0, "Failed to send delete-emergency flow")
        res, pkt = self.controller.poll(ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(res is None, "Emergency flows could not be deleted.")
Example #42
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running FailSecureMode test ")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 0, "Not enough ports for test")

        #Clear switch state
        rv = delete_all_flows(self.controller)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        #Insert flo entry with hard_timeout set to 120
        pkt_matchingress = simple_tcp_packet()
        match3 = parse.packet_to_flow_match(pkt_matchingress)
        self.assertTrue(match3 is not None,
                        "Could not generate flow match from pkt")
        match3.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT
        match3.in_port = of_ports[2]
        msg3 = message.flow_mod()
        msg3.command = ofp.OFPFC_ADD
        msg3.match = match3
        msg3.cookie = random.randint(0, 9007199254740992)
        msg3.buffer_id = 0xffffffff
        msg3.idle_timeout = 0
        msg3.hard_timeout = 120
        msg3.buffer_id = 0xffffffff
        cookie = msg3.cookie
        act3 = action.action_output()
        act3.port = of_ports[3]
        self.assertTrue(msg3.actions.add(act3), "could not add action")
        rv = self.controller.message_send(msg3)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        #Insert flow entry with hard_timeout set to 15
        pkt = simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        self.assertTrue(match is not None,
                        "Could not generate flow match from pkt")
        match.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT
        match.in_port = of_ports[0]

        msg = message.flow_mod()
        msg.command = ofp.OFPFC_ADD
        msg.match = match
        msg.hard_timeout = 15
        msg.buffer_id = 0xffffffff
        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")

        #Ensure switch reports back with only one flow entry , ensure the flow entry is not some stray flow entry
        logging.info("Sending simple tcp packet ...")
        logging.info("Checking whether the flow we inserted is working")
        self.dataplane.send(of_ports[0], str(pkt))
        egress_port = of_ports[1]
        yes_ports = [egress_port]
        no_ports = set(of_ports).difference(yes_ports)
        receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self)
        logging.info("The inserted standard flow is working fine")

        #Shutdown the controller
        self.controller.shutdown()

        assertionerr = False
        #checking control plane connection
        logging.info("Checking for control plane connection")
        try:
            for x in range(15):
                self.dataplane.send(of_ports[1], str(pkt))
                (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,
                                                       timeout=5)
                self.assertTrue(
                    response is not None,
                    'PacketIn not generated--Control plane is down')

        except AssertionError:

            logging.info("Control plane connection Disconnected")

            #Send matching packet
            logging.info(
                "sending matching packet to verify standard flows are working correctly"
            )
            self.dataplane.send(of_ports[0], str(pkt))

            #Verify packet implements the action specified in the flow
            egress_port = of_ports[1]
            yes_ports = [egress_port]
            no_ports = set(of_ports).difference(yes_ports)
            receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self)
            logging.info(
                "All standard flows working fine even after control channel shutdown"
            )
            assertionerr = True

        else:
            self.assertTrue(assertionerr is True,
                            "Error Control Channel is Not Down")

        #Sleeping for flow to timeout
        logging.info("Waiting for flows to time out")
        sleep(16)

        #Send matching packet
        logging.info(
            "Verifying if the standard flows have been deleted after timeout")
        logging.info("Sending simple tcp packet ...")
        self.dataplane.send(of_ports[0], str(pkt))

        #Verify packet does not implement the action specified in the flow
        #flow should have timed out
        egress_port = of_ports[1]
        yes_ports = []
        no_ports = set(of_ports)
        receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self)
        logging.info("All the standard flows are deleted after time out")
        self.controller.connect()
        sleep(2)
        self.dataplane.send(of_ports[2], str(pkt_matchingress))
        receive_pkt_verify(self, of_ports[3], str(pkt_matchingress),
                           of_ports[2])
Example #43
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp40No10 Overlap_Checking 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("Installing an all wildcarded flow")

        #Insert a flow F with wildcarded all fields
        (pkt, match) = wildcard_all(self, of_ports)

        #Verify flow is active
        #verify_tablestats(self,expect_active=1)

        # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
        logging.info(
            "Installing a overlapping flow with check_overlap bit set")
        pkt_matchingress = simple_tcp_packet()
        match3 = parse.packet_to_flow_match(pkt_matchingress)
        self.assertTrue(match3 is not None,
                        "Could not generate flow match from pkt")
        match3.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT
        match3.in_port = of_ports[0]

        msg3 = message.flow_mod()
        msg3.command = ofp.OFPFC_ADD
        msg3.match = match3
        msg3.flags |= ofp.OFPFF_CHECK_OVERLAP
        msg3.cookie = random.randint(0, 9007199254740992)
        msg3.buffer_id = 0xffffffff

        act3 = action.action_output()
        act3.port = of_ports[1]
        self.assertTrue(msg3.actions.add(act3), "could not add action")
        rv = self.controller.message_send(msg3)
        self.assertTrue(rv != -1, "Error installing flow mod")
        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")

        # Verify Flow does not get inserted
        #verify_tablestats(self,expect_active=1)

        #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
        logging.info("waiting for the switch to respond with an error")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                               timeout=5)

        self.assertTrue(response is not None,
                        'Switch did not reply with error message')
        self.assertTrue(response.type == ofp.OFPET_FLOW_MOD_FAILED,
                        'Error message type is not flow mod failed ')
        self.assertTrue(response.code == ofp.OFPFMFC_OVERLAP,
                        'Error Message code is not overlap')
        logging.info("Flow_mod error received")

        #Verify that only one flow exists
        verify_tablestats(self, expect_active=1)