Example #1
0
    def runTest(self):
        of_ports = exact_port_map.keys()
        ing_port = of_ports[0]
        egr_port = of_ports[1]
        table_id = testutils.EX_ACL_TABLE

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet()
        "construct flow entry"
        match_ls = testutils.packet_to_exact_flow_match(
            pkt, None, table_id, ing_port)
        flow_add = testutils.flow_msg_create(self,
                                             pkt,
                                             match_fields=match_ls,
                                             egr_port=egr_port,
                                             table_id=table_id)

        testutils.ofmsg_send(self, flow_add)

        "read flow back;"
        response = testutils.flow_stats_get(self, match_ls, table_id)
        self.assertTrue(len(response.stats) != 0, "stats len is 0")

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        testutils.receive_pkt_verify(self, egr_port, pkt)
Example #2
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]

        testutils.delete_all_flows(self.controller, self.logger)
        flow_add = message.flow_mod()
        flow_add.buffer_id = 0xffffffff;
        flow_add.header.xid = 123
        flow_add.table_id = 0
        flow_add.command = ofp.OFPFC_ADD
        flow_add.match_fields.add(match.eth_type(value = 0x86dd))
        flow_add.match_fields.add(match.ipv4_src(value = 3232235521))
        flow_add.match_fields.add(match.ipv4_dst(value = 3232235522))
        flow_add.match_fields.add(match.metadata(value = 0))
        "new a instruction"
        inst = instruction.instruction_write_actions()
        "new a output actions"
        act = action.action_output()
        act.port = out_port1
        inst.actions.add(act)
        flow_add.instructions.add(inst)
        #self.controller.message_send(flow_add)
        #print(flow_add.show())
	testutils.ofmsg_send(self, flow_add)

        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
        self.assertTrue(response is not None, 'No error message received')
        self.assertEqual(ofp.OFPET_BAD_MATCH, response.type,
                       'Error message type mismatch: ' +
                       str(ofp.OFPET_BAD_MATCH) + " != " +
                       str(response.type))
        self.assertEqual(ofp.OFPBMC_BAD_PREREQ, response.code,
                       'Error message code mismatch: ' +
                       str(ofp.OFPBMC_BAD_PREREQ) + " != " +
                       str(response.code))
Example #3
0
    def runTest(self):
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        'make packet'
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a', \
                                            vlan_tags = vlan_tags, mpls_tags = mpls_tags)
        'table 0 goto table3'
        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_ACL_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE,
                               testutils.EX_L2_TABLE, match_ls)
        "set table 3 not match, continue"
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        'table 4 output'
        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_VLAN_TABLE, ing_port=ing_port)
        exact_table_output(self,
                           testutils.EX_VLAN_TABLE,
                           match_ls,
                           egr_port=egr_port)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        'verify the rec data'
        testutils.receive_pkt_verify(self, egr_port, pkt)
Example #4
0
    def runTest(self):
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        'make packet'
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a', \
                                            vlan_tags = vlan_tags, mpls_tags = mpls_tags)
        'table 0 goto table3'
        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_ACL_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE,
                               testutils.EX_L2_TABLE, match_ls)
        "set table 3 not match, continue"
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_DROP, True)
        'table 4 output'
        match_ls = testutils.packet_to_exact_flow_match(
            pkt, None, testutils.EX_VLAN_TABLE, ing_port)
        exact_table_output(self,
                           testutils.EX_VLAN_TABLE,
                           match_ls,
                           egr_port=egr_port)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        # checks no response from controller and dataplane
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        # self.assertIsNone() is preferable for newer python
        self.assertFalse(response is not None, "PacketIn message is received")
        (_, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertFalse(rcv_pkt is not None, "Packet on dataplane")
Example #5
0
    def runTest(self):
        for of_port in sdn_port_map.keys():
            ing_port = of_port
            for egr_port in sdn_port_map.keys():
                if egr_port != of_port:
                    break
            #egr_port = (i+1) %4 + 1
            #print("\ncount: " + str(ing_port))
            #print("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            self.logger.info("\ncount: " + str(ing_port))
            self.logger.info("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            pkt = testutils.simple_tcp_packet()
            testutils.delete_all_flows(self.controller, self.logger)

            request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port,check_expire=True)
            request.cookie = random.randint(0,9007199254740992)
            request.buffer_id = 0xffffffff
            request.hard_timeout = 1000
            request.idle_timeout = 1000

            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            self.dataplane.send(ing_port, str(pkt))
            (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
            #print("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            #print("\n")
            self.logger.info("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            self.logger.info("\n")
            self.assertTrue(rcv_pkt is not None, "Did not receive packet")
Example #6
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self,
                                         pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)
     inst = None
     inst = instruction.instruction_write_actions(
     )  #instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(
         ofp.OFPET_BAD_INSTRUCTION, response.type,
         'Error message type mismatch: ' +
         str(ofp.OFPET_BAD_INSTRUCTION, ) + " != " + str(response.type))
     self.assertEqual(
         ofp.OFPBIC_UNKNOWN_INST, response.code,
         'Error message code mismatch: ' + str(ofp.OFPBIC_UNKNOWN_INST) +
         " != " + str(response.code))
Example #7
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = of_ports[2]

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.EX_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_VLAN_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_MPLS_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata();
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata)

        pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 
                        'metadata_msk':inst_write_metadata.metadata_mask}
        match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L3_TABLE)
        testutils.write_output(self, testutils.EX_L3_TABLE, egr_port, match_fields=match_fields)

        testutils.reply_check_dp(self, tcp_sport=1234, ing_port = ing_port, egr_port = egr_port)
        
        testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER)
Example #8
0
    def runTest(self):
        # Config
        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[2]
        table_id = testutils.WC_ACL_TABLE

        # Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match
        pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
        request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port, table_id = table_id)
        testutils.flow_msg_install(self, request)

        #Send packet
        ipv6_logger.info("Sending IPv6 packet to " + str(ing_port))
        ipv6_logger.debug("Data: " + str(pkt).encode('hex'))

        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #9
0
    def runTest(self):
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        'make packet'
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a', \
                                            vlan_tags = vlan_tags, mpls_tags = mpls_tags)
        'table 0 goto table3'
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_ACL_TABLE, ing_port = ing_port)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE, testutils.EX_L2_TABLE, match_ls)
        "set table 3 not match, continue"
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True)
        'table 4 output'
        match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_VLAN_TABLE, ing_port)
        exact_table_output(self, testutils.EX_VLAN_TABLE, match_ls, egr_port = egr_port)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        # checks no response from controller and dataplane
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        # self.assertIsNone() is preferable for newer python
        self.assertFalse(response is not None, "PacketIn message is received")
        (_, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertFalse(rcv_pkt is not None, "Packet on dataplane")
Example #10
0
    def runTest(self):

        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[2]
        table_id = testutils.WC_L3_TABLE

        # Remove all entries Add entry match all
        rc = testutils.delete_all_flows(self.controller, self.logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        rv = testutils.set_table_config(self, table_id)
        self.assertEqual(rv, 0, "Failed to set table config")

        # Add entry match
        pkt = testutils.simple_ipv6_packet()
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            ing_port=ing_port,
                                            egr_port=egr_port,
                                            table_id=table_id)
        testutils.flow_msg_install(self, request)

        #Send packet
        self.logger.info("Sending IPv6 packet to " + str(ing_port))
        self.logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        testutils.receive_pkt_verify(self, egr_port, pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, self.logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #11
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # make packet
        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

        exact_table_output(self, table_id, match_ls, egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        response, _ = self.controller.transact(stat_req, timeout=2)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        self.assertTrue(pkt_rec is not None,"rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Example #12
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        #make packet;
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a')
        exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='aa:aa:aa:aa:aa:aa')
        # get match list
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

        act = action.action_set_field()
        field = match.eth_dst(parse.parse_mac("aa:aa:aa:aa:aa:aa"))
        act.field.add(field)
        exact_table_output(self, table_id, match_ls, actions = [act], egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)

        self.assertTrue(pkt is not None,"rec none packets")
        self.assertEqual(str(exp_pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Example #13
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99', dl_dst='00:06:07:08:09:aa', \
                                               vlan_tags = [], mpls_tags = [])

        match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_L2_TABLE, port_in)

        exact_table_output(self, table_id, match_ls, egr_port = egr_port)

        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPP_ANY
        
        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
Example #14
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port1)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Example #15
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = ofp.OFPP_ALL
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self,
                                         pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)  #flood
     inst = None
     inst = instruction.instruction_apply_actions()
     act = action.action_output()
     act.port = ofp.OFPP_IN_PORT  #fwd to ingress
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
     self.assertTrue(response is None, 'Receive error message')
     #user sends packet
     self.dataplane.send(ing_port, str(pkt))
     testutils.do_barrier(self.controller)
     #verify pkt
     for of_port in flow_mods_port_map.keys():
         testutils.receive_pkt_verify(self, of_port, pkt)
Example #16
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = ofp.OFPP_ALL
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)#flood
     inst = None
     inst = instruction.instruction_apply_actions()
     act = action.action_output()
     act.port = ofp.OFPP_IN_PORT #fwd to ingress
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
     self.assertTrue(response is None, 'Receive error message')
     #user sends packet
     self.dataplane.send(ing_port, str(pkt))
     testutils.do_barrier(self.controller)
     #verify pkt
     for of_port in flow_mods_port_map.keys():
         testutils.receive_pkt_verify(self, of_port, pkt)
Example #17
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]

        testutils.delete_all_flows(self.controller, self.logger)
        flow_add = message.flow_mod()
        flow_add.buffer_id = 0xffffffff
        flow_add.header.xid = 123
        flow_add.table_id = 0
        flow_add.command = ofp.OFPFC_ADD
        flow_add.match_fields.add(match.eth_type(value=0x86dd))
        flow_add.match_fields.add(match.ipv4_src(value=3232235521))
        flow_add.match_fields.add(match.ipv4_dst(value=3232235522))
        flow_add.match_fields.add(match.metadata(value=0))
        "new a instruction"
        inst = instruction.instruction_write_actions()
        "new a output actions"
        act = action.action_output()
        act.port = out_port1
        inst.actions.add(act)
        flow_add.instructions.add(inst)
        #self.controller.message_send(flow_add)
        #print(flow_add.show())
        testutils.ofmsg_send(self, flow_add)

        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
        self.assertTrue(response is not None, 'No error message received')
        self.assertEqual(
            ofp.OFPET_BAD_MATCH, response.type,
            'Error message type mismatch: ' + str(ofp.OFPET_BAD_MATCH) +
            " != " + str(response.type))
        self.assertEqual(
            ofp.OFPBMC_BAD_PREREQ, response.code,
            'Error message code mismatch: ' + str(ofp.OFPBMC_BAD_PREREQ) +
            " != " + str(response.code))
Example #18
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]
        out_port2 = flow_mods_port_map.keys()[2]
        pkt = testutils.simple_tcp_packet()
        testutils.delete_all_flows(self.controller, self.logger)
        fm_orig = testutils.flow_msg_create(self,
                                            pkt,
                                            ing_port=ofp.OFPP_ANY,
                                            egr_port=out_port1,
                                            table_id=2)
        fm_new = testutils.flow_msg_create(self,
                                           pkt,
                                           ing_port=ing_port,
                                           egr_port=out_port2,
                                           table_id=2)
        fm_new.command = ofp.OFPFC_MODIFY_STRICT
        testutils.ofmsg_send(self, fm_orig)

        testutils.ofmsg_send(self, fm_new)

        flow_stats = testutils.flow_stats_get(self)
        #print(flow_stats.show())
        self.assertEqual(len(flow_stats.stats), 1,
                         "Expected only one flow_mod")

        #fail to modify and instruction will remain the same
        stat = flow_stats.stats[0]
        self.assertEqual(stat.match, fm_orig.match)
        self.assertEqual(stat.instructions, fm_orig.instructions)
Example #19
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99', dl_dst='00:06:07:08:09:aa', \
                                               vlan_tags = [], mpls_tags = [])

        match_ls = testutils.packet_to_exact_flow_match(
            pkt, None, testutils.EX_L2_TABLE, port_in)

        exact_table_output(self, table_id, match_ls, egr_port=egr_port)

        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPP_ANY

        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
Example #20
0
    def runTest(self):

        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[2]
        table_id = testutils.WC_L3_TABLE

        # Remove all entries Add entry match all
        rc = testutils.delete_all_flows(self.controller, self.logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        rv = testutils.set_table_config(self, table_id)
        self.assertEqual(rv, 0, "Failed to set table config")

        # Add entry match
        pkt = testutils.simple_ipv6_packet()
        request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port, table_id = table_id)
        testutils.flow_msg_install(self, request)

        #Send packet
        self.logger.info("Sending IPv6 packet to " + str(ing_port))
        self.logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        testutils.receive_pkt_verify(self, egr_port, pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, self.logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #21
0
    def runTest(self):
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                          dl_dst='00:06:07:08:09:0a')

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_ACL_TABLE, ing_port=port_in)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE,
                               testutils.EX_L2_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_L2_TABLE, ing_port=port_in)
        exact_table_output(self,
                           testutils.EX_L2_TABLE,
                           match_ls,
                           egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        #print( str(pkt_rec).encode('hex'))
        self.assertTrue(pkt_rec is not None, "rec none packets")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #22
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port =ofp.OFPP_CONTROLLER

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata();
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata)

        pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 'metadata_msk':inst_write_metadata.metadata_mask}
        match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L2_TABLE)
        testutils.write_output(self, testutils.EX_L2_TABLE, egr_port, match_fields=match_fields)
        
        self.dataplane.send(ing_port, str(pkt))
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        self.assertTrue(response is not None, 'Packet in message not received on port ' + str(egr_port))
        if str(pkt) != response.data:
               pa_logger.debug("pkt  len " + str(len(str(pkt))) +": " + str(pkt))
               pa_logger.debug("resp len " + str(len(str(response.data))) + ": " + str(response.data))
Example #23
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # make packet
        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt=pkt,
                                                        table_id=table_id,
                                                        ing_port=port_in)

        exact_table_output(self, table_id, match_ls, egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        response, _ = self.controller.transact(stat_req, timeout=2)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #24
0
 def runTest(self):
     basic_logger.info("Running StatsGet")
     basic_logger.info("Inserting trial flow")
     request = message.flow_mod()
     request.match.wildcards = ofp.OFPFW_ALL
     request.buffer_id = 0xffffffff
     for i in range(1, 5):
         request.priority = i * 1000
         basic_logger.debug("Adding flow %d" % i)
         rv = self.controller.message_send(request)
         self.assertTrue(rv != -1, "Failed to insert test flow %d" % i)
     basic_logger.info("Removing all flows")
     testutils.delete_all_flows(self.controller, basic_logger)
     basic_logger.info("Sending flow request")
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_ANY
     request.out_group = ofp.OFPG_ANY
     request.table_id = 0xff
     request.match.wildcards = 0  # ofp.OFPFW_ALL
     response, _ = self.controller.transact(request, timeout=2)
     self.assertTrue(response is not None, "Did not get response")
     self.assertTrue(isinstance(response, message.flow_stats_reply),
                     "Not a flow_stats_reply")
     self.assertEqual(len(response.stats), 0)
     basic_logger.debug(response.show())
Example #25
0
    def runTest(self):
        # Config
        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[2]
        table_id = testutils.WC_ACL_TABLE

        # Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match
        pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            ing_port=ing_port,
                                            egr_port=egr_port,
                                            table_id=table_id)
        testutils.flow_msg_install(self, request)

        #Send packet
        ipv6_logger.info("Sending IPv6 packet to " + str(ing_port))
        ipv6_logger.debug("Data: " + str(pkt).encode('hex'))

        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #26
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port1)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Example #27
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)
     inst = None
     inst = instruction.instruction_write_actions()#instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(ofp.OFPET_BAD_INSTRUCTION, response.type,
                    'Error message type mismatch: ' +
                    str(ofp.OFPET_BAD_INSTRUCTION,) + " != " +
                    str(response.type))
     self.assertEqual(ofp.OFPBIC_UNKNOWN_INST, response.code,
                    'Error message code mismatch: ' +
                    str(ofp.OFPBIC_UNKNOWN_INST) + " != " +
                    str(response.code))
Example #28
0
    def runTest(self):
        basic_logger.info("Running TableStats")
        testutils.delete_all_flows(self.controller, self.logger)
        basic_logger.info("Sending table stats request")
        request = message.table_stats_request()
        response, _ = self.controller.transact(request, timeout=2)

        # delete everything, so there should be no entries
        self.assertEqual(self.get_first_table_active_entries(response), 0)
        # add two entries to first table
        m1 = testutils.match_all_generate()
        m1.dl_type = 0x800
        m1.wildcards ^= ofp.OFPFW_DL_TYPE
        fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2)
        rv = self.controller.message_send(fm1)
        self.assertEqual(rv, 0)
        m2 = testutils.match_all_generate()
        m2.dl_type = 0x806
        m2.wildcards ^= ofp.OFPFW_DL_TYPE
        fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2)
        rv = self.controller.message_send(fm2)
        self.assertEqual(rv, 0)
        testutils.do_barrier(self.controller)
        response, _ = self.controller.transact(request, timeout=2)
        self.assertEqual(self.get_first_table_active_entries(response), 2)
Example #29
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]
        out_port2 = flow_mods_port_map.keys()[2]
        pkt = testutils.simple_tcp_packet()
        testutils.delete_all_flows(self.controller, self.logger)
        fm_orig = testutils.flow_msg_create(self, pkt,
                                            ing_port=ofp.OFPP_ANY,
                                            egr_port=out_port1,
                                            table_id=2)
        fm_new = testutils.flow_msg_create(self, pkt,
                                            ing_port=ing_port,
                                            egr_port=out_port2,
                                            table_id=2)
        fm_new.command = ofp.OFPFC_MODIFY_STRICT
        testutils.ofmsg_send(self, fm_orig)

        testutils.ofmsg_send(self, fm_new)

        flow_stats = testutils.flow_stats_get(self)
        #print(flow_stats.show())
        self.assertEqual(len(flow_stats.stats),1,
                         "Expected only one flow_mod")
                         
        #fail to modify and instruction will remain the same
        stat = flow_stats.stats[0]
        self.assertEqual(stat.match, fm_orig.match)                  
        self.assertEqual(stat.instructions, fm_orig.instructions)  
Example #30
0
 def runTest(self):
     basic_logger.info("Running TableStats")
     testutils.delete_all_flows(self.controller, self.logger)
     basic_logger.info("Sending table stats request")
     request = message.table_stats_request()
     response, _ = self.controller.transact(request, timeout=2)
 
     # delete everything, so there should be no entries
     self.assertEqual(self.get_first_table_active_entries(response), 0)
     # add two entries to first table
     m1 = testutils.match_all_generate()
     m1.dl_type = 0x800
     m1.wildcards ^= ofp.OFPFW_DL_TYPE
     fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2)
     rv = self.controller.message_send(fm1)
     self.assertEqual(rv, 0)
     m2 = testutils.match_all_generate()
     m2.dl_type = 0x806
     m2.wildcards ^= ofp.OFPFW_DL_TYPE
     fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2)
     rv = self.controller.message_send(fm2)
     self.assertEqual(rv, 0)
     testutils.do_barrier(self.controller)
     response, _ = self.controller.transact(request, timeout=2)
     self.assertEqual(self.get_first_table_active_entries(response), 2)
Example #31
0
    def runTest(self):
        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[3]
        
        # Remove all entries Add entry match all
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match 

        request = message.flow_mod()
        request.match.type = ofp.OFPMT_OXM
        port = match.in_port(of_ports[0])
        eth_type = match.eth_type(IPV6_ETHERTYPE)
        ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189'))
        
        request.match_fields.tlvs.append(port)
        request.match_fields.tlvs.append(eth_type)
        request.match_fields.tlvs.append(ipv6_src)
        
        field_2b_set = match.ipv6_dst(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD'))
        act_setfield = action.action_set_field()
        act_setfield.field = field_2b_set
        
#       TODO: insert action set field properly
        act_out = action.action_output()
        act_out.port = of_ports[3]
        
        
        inst = instruction.instruction_apply_actions()
        inst.actions.add(act_setfield)
        inst.actions.add(act_out)
        request.instructions.add(inst)
        request.buffer_id = 0xffffffff
        
        request.priority = 1000
        ipv6_logger.debug("Adding flow ")
        
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Failed to insert test flow")

        #Send packet
        pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190')
        ipv6_logger.info("Sending IPv6 packet to " + str(ing_port))
        ipv6_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD')
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        response = testutils.flow_stats_get(self)
        ipv6_logger.debug("Response" + response.show())
        
        #Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")    
Example #32
0
    def runTest(self):
        #testutils.clear_switch(self,pa_port_map,pa_logger)
        testutils.delete_all_flows(self.controller, pa_logger)
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0])
        match_ls = parse.packet_to_flow_match(pkt)

        request = message.flow_mod()
        request.match_fields = match_ls
        request.flags = 0x18  #set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS

        action_list = []
        act = action.action_output()
        act.port = of_ports[1]
        action_list.append(act)

        inst = None
        instruction_list = []

        if len(instruction_list) == 0:
            inst = instruction.instruction_apply_actions()
            instruction_list.append(inst)

        for act in action_list:
            rv = inst.actions.add(act)
            self.assertTrue(rv, "Could not add action" + act.show())

        for i in instruction_list:
            rv = request.instructions.add(i)
            self.assertTrue(rv, "Could not add instruction " + i.show())

        #testutils.message_send(self, request)
        rv0 = self.controller.message_send(request)
        self.assertTrue(rv0 != -1, "Error sending flow mod")
        testutils.do_barrier(self.controller)

        #self.send_data(pkt, of_ports[0])
        self.dataplane.send(of_ports[0], str(pkt))

        aggregate_stats_req = message.aggregate_stats_request()
        aggregate_stats_req.match_fields = match_ls

        rv = self.controller.message_send(aggregate_stats_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        #testutils.message_send(self, aggregate_stats_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2)
        #print(response.show())
        self.assertTrue(response is not None, "No aggregate_stats reply")
        self.assertEqual(len(response.stats), 1,
                         "Did not receive aggregate stats reply")
        self.assertEqual(response.stats[0].packet_count, 0)  #1)
        self.assertEqual(response.stats[0].byte_count, 0)  #len(packet_in))
Example #33
0
    def runTest(self):
        # Config
        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[3]

        # Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match

        request = message.flow_mod()
        request.match.type = ofp.OFPMT_OXM
        port = match.in_port(of_ports[0])
        eth_type = match.eth_type(IPV6_ETHERTYPE)
        ipv6_src = match.ipv6_src(
            ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189'))
        ip_proto = match.ip_proto(TCP_PROTOCOL)
        tcp_port = match.tcp_src(80)

        request.match_fields.tlvs.append(port)
        request.match_fields.tlvs.append(eth_type)
        request.match_fields.tlvs.append(ipv6_src)
        request.match_fields.tlvs.append(ip_proto)
        request.match_fields.tlvs.append(tcp_port)

        act = action.action_output()
        act.port = of_ports[3]
        inst = instruction.instruction_apply_actions()
        inst.actions.add(act)
        request.instructions.add(inst)
        request.buffer_id = 0xffffffff

        request.priority = 1000
        ipv6_logger.debug("Adding flow ")

        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Failed to send test flow")

        #Send packet
        pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)

        ipv6_logger.info("Sending IPv6 packet to " + str(ing_port))
        ipv6_logger.debug("Data: " + str(pkt).encode('hex'))

        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)

        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #34
0
    def runTest(self):
       	# Config
        of_ports = ipv6_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[3]
        
        # Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match 

        request = message.flow_mod()
        request.match.type = ofp.OFPMT_OXM
        port = match.in_port(of_ports[0])
        eth_type = match.eth_type(IPV6_ETHERTYPE)
        ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189'))        
        ip_proto = match.ip_proto(TCP_PROTOCOL)
        tcp_port = match.tcp_src(80)
        
        
        request.match_fields.tlvs.append(port)
        request.match_fields.tlvs.append(eth_type)
        request.match_fields.tlvs.append(ipv6_src)
        request.match_fields.tlvs.append(ip_proto)
        request.match_fields.tlvs.append(tcp_port)
        
        act = action.action_output()
        act.port = of_ports[3]
        inst = instruction.instruction_apply_actions()
        inst.actions.add(act)
        request.instructions.add(inst)
        request.buffer_id = 0xffffffff
        
        request.priority = 1000
        ipv6_logger.debug("Adding flow ")
        
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Failed to send test flow")

        #Send packet
        pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 

        ipv6_logger.info("Sending IPv6 packet to " + str(ing_port))
        ipv6_logger.debug("Data: " + str(pkt).encode('hex'))
        
        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 

        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #Remove flows
        rc = testutils.delete_all_flows(self.controller, ipv6_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #35
0
    def runTest(self):
        #testutils.clear_switch(self,pa_port_map,pa_logger)
        testutils.delete_all_flows(self.controller, pa_logger)
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt  = testutils.simple_tcp_packet()
        #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0])
        match_ls = parse.packet_to_flow_match(pkt)

        request = message.flow_mod()
        request.match_fields = match_ls
        request.flags = 0x18#set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS
        
        action_list = []        
        act = action.action_output()
        act.port = of_ports[1]
        action_list.append(act)
        
        inst = None
        instruction_list = []
        
        if len(instruction_list) == 0: 
              inst = instruction.instruction_apply_actions()
              instruction_list.append(inst)
        
        for act in action_list:
              rv = inst.actions.add(act)
              self.assertTrue(rv, "Could not add action" + act.show())

        for i in instruction_list: 
              rv = request.instructions.add(i)
              self.assertTrue(rv, "Could not add instruction " + i.show())

        #testutils.message_send(self, request)
        rv0 = self.controller.message_send(request)
        self.assertTrue( rv0 != -1, "Error sending flow mod")
        testutils.do_barrier(self.controller)

        #self.send_data(pkt, of_ports[0])
        self.dataplane.send(of_ports[0],str(pkt))

        aggregate_stats_req = message.aggregate_stats_request()
        aggregate_stats_req.match_fields = match_ls
        
        rv = self.controller.message_send(aggregate_stats_req)
        self.assertTrue( rv != -1, "Error sending flow stat req")
        #testutils.message_send(self, aggregate_stats_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2)
        #print(response.show())
        self.assertTrue(response is not None, "No aggregate_stats reply")
        self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply")
        self.assertEqual(response.stats[0].packet_count,0)#1)
        self.assertEqual(response.stats[0].byte_count,0)#len(packet_in))
Example #36
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = of_ports[2]

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.EX_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_VLAN_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_MPLS_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_L3_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata()
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self,
                             testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE,
                             ing_port,
                             add_inst=inst_write_metadata)

        pkt_metadata = {
            'metadata_val': inst_write_metadata.metadata,
            'metadata_msk': inst_write_metadata.metadata_mask
        }
        match_fields = testutils.packet_to_exact_flow_match(
            pkt_metadata=pkt_metadata, table_id=testutils.EX_L3_TABLE)
        testutils.write_output(self,
                               testutils.EX_L3_TABLE,
                               egr_port,
                               match_fields=match_fields)

        testutils.reply_check_dp(self,
                                 tcp_sport=1234,
                                 ing_port=ing_port,
                                 egr_port=egr_port)

        testutils.set_table_config(self, testutils.EX_L3_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER)
Example #37
0
    def runTest(self):
        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")

        pkt = testutils.simple_tcp_packet()
        testutils.flow_match_test(self, pa_port_map, pkt=pkt,  wildcards=ofp.OFPFW_ALL, max_test =1)

        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #38
0
    def runTest(self):
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(vlan_tags=vlan_tags,
                                          mpls_tags=mpls_tags)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_ACL_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE,
                               testutils.EX_L2_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_L2_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_L2_TABLE,
                               testutils.EX_VLAN_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_VLAN_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_VLAN_TABLE,
                               testutils.EX_MPLS_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_MPLS_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_MPLS_TABLE,
                               testutils.EX_L3_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_L3_TABLE, ing_port=ing_port)
        exact_table_output(self,
                           testutils.EX_L3_TABLE,
                           match_ls,
                           egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packets")
        #print("++++++++++++++++++++++rcv_pkt++++++++++++++++++++++")
        #if pkt_rec is None:
        #   print(str(pkt_rec))
        #else:
        #   print(str(pkt_rec).encode('hex'))
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #39
0
    def runTest(self):
        
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[2]
        
        self.of_dir = os.path.normpath("../../of11softswitch")
        self.ofd = os.path.normpath(self.of_dir + "/udatapath/ofdatapath")
        self.dpctl = os.path.normpath(self.of_dir + "/utilities/dpctl")
        dpctl_switch = "unix:/tmp/ofd"

        # Remove all entries Add entry match all
        # sudo ./dpctl unix:/tmp/ofd flow-mod cmd=del,table=0
#        flow_cmd1 = "flow-mod"
#        flow_cmd2 = "cmd=del,table=0"
#        pcall = [self.dpctl, dpctl_switch, flow_cmd1, flow_cmd2]
#        subprocess.call(pcall)  

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

        # Add entry match all
        flow_cmd1 = "flow-mod"
        flow_cmd2 = "cmd=add,table=0,idle=100"
        flow_match = "wildcards=+all,dl_src_mask=FF:FF:FF:FF:FF:FF,dl_dst_mask=FF:FF:FF:FF:FF:FF,nw_src_mask=255.255.255.255,nw_dst_mask=255.255.255.255" #, -in_port,in_port=1,dl_type=2048in_port=0  wildcards=0xffff
        flow_acts = "apply:output=" + str(egr_port)

        pcall = [self.dpctl, dpctl_switch, flow_cmd1, flow_cmd2, flow_match,  flow_acts]
        print pcall
        subprocess.call(pcall)

        #Send packet
        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_tcp_packet()
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        pa_logger.debug("Request stats-flow")  
        pcall = [self.dpctl, dpctl_switch, "stats-flow"]  #  
        subprocess.call(pcall)
        
        #Remove flows
        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #40
0
 def runTest(self):
     rc = testutils.delete_all_flows(self.controller, pa_logger)
     self.assertEqual(rc, 0, "Failed to delete all flows")
     
     pkt = simple_ipv6_packet()
     
     of_ports = pa_port_map.keys()
     of_ports.sort()
     ing_port = of_ports[0]
     pa_logger.info("Sending IPv6 packet to " + str(ing_port))
     pa_logger.debug("Data: " + str(pkt).encode('hex'))
     self.dataplane.send(ing_port, str(pkt))
     
     rc = testutils.delete_all_flows(self.controller, pa_logger)
     self.assertEqual(rc, 0, "Failed to delete all flows")
Example #41
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = ofp.OFPP_CONTROLLER

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE,
                                   ofp.OFPTC_TABLE_MISS_DROP, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata()
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self,
                             testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE,
                             ing_port,
                             add_inst=inst_write_metadata)

        pkt_metadata = {
            'metadata_val': inst_write_metadata.metadata,
            'metadata_msk': inst_write_metadata.metadata_mask
        }
        match_fields = testutils.packet_to_exact_flow_match(
            pkt_metadata=pkt_metadata, table_id=testutils.EX_L2_TABLE)
        testutils.write_output(self,
                               testutils.EX_L2_TABLE,
                               egr_port,
                               match_fields=match_fields)

        self.dataplane.send(ing_port, str(pkt))
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        self.assertTrue(
            response is not None,
            'Packet in message not received on port ' + str(egr_port))
        if str(pkt) != response.data:
            pa_logger.debug("pkt  len " + str(len(str(pkt))) + ": " + str(pkt))
            pa_logger.debug("resp len " + str(len(str(response.data))) + ": " +
                            str(response.data))
Example #42
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        
        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [ act_all, act_ing]

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")
        
            flow_mod = testutils.flow_msg_create(self, pkt, 
                                                 ing_port=ingress_port, 
                                                 action_list=actions, 
                                                 wildcards=~ofp.OFPFW_IN_PORT)
            flow_mod.buffer_id = 0xffffffff
            pa_logger.info(flow_mod.show())

            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(flow_mod)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Example #43
0
    def handleFlow(self, pkttype='TCP'):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        if (pkttype == 'ICMP'):
            pkt = testutils.simple_icmp_packet()
            table_id = testutils.EX_ICMP_TABLE
        else:
            pkt = testutils.simple_tcp_packet()
            table_id = testutils.WC_ACL_TABLE

        for idx in range(len(of_ports)):
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")
            testutils.set_table_config(self, table_id,
                                       ofp.OFPTC_TABLE_MISS_CONTINUE)

            ingress_port = of_ports[idx]
            egress_port = of_ports[(idx + 1) % len(of_ports)]
            pa_logger.info("Ingress " + str(ingress_port) + " to egress " +
                           str(egress_port))

            #controller send flow mod to switch
            request = testutils.flow_msg_create(self,
                                                pkt,
                                                ing_port=ingress_port,
                                                egr_port=egress_port,
                                                table_id=table_id)
            testutils.flow_msg_install(self, request)

            #user send pkt to switch
            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_verify(self, egress_port, pkt)
Example #44
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [act_all, act_ing]

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            flow_mod = testutils.flow_msg_create(
                self,
                pkt,
                ing_port=ingress_port,
                action_list=actions,
                inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)
            pa_logger.info(flow_mod.show())

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, flow_mod)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [],
                                        self, pa_logger)
Example #45
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            request = testutils.flow_msg_create(self,
                                                pkt,
                                                ing_port=ingress_port,
                                                egr_port=ofp.OFPP_ALL)

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, request)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports,
                                        [ingress_port], self, pa_logger)
Example #46
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) +
                           " all non-ingress ports")
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    continue
                act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(
                self,
                pkt,
                ing_port=ingress_port,
                action_list=actions,
                inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, request)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports,
                                        [ingress_port], self, pa_logger)
Example #47
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) +
                           " all non-ingress ports")
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    continue
                act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port,
                                action_list=actions, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, request)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
                              self, pa_logger)
Example #48
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [ act_all, act_ing]

        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            flow_mod = testutils.flow_msg_create(self, pkt,
                                                 ing_port=ingress_port,
                                                 action_list=actions,
                                                 inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION
                                                 )
            pa_logger.info(flow_mod.show())

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, flow_mod)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Example #49
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

        of_port = config_port_map.keys()[0]
        rv = testutils.port_config_set(self.controller, of_port,
                                       ofp.OFPPC_NO_PACKET_IN,
                                       ofp.OFPPC_NO_PACKET_IN, config_logger)
        self.assertTrue(rv != -1, "Error sending port mod")
        config_logger.info("NO PKT IN test, port " + str(of_port))

        # make sure config is changed before sending the packet
        testutils.do_barrier(self.controller)

        pkt = testutils.simple_tcp_packet()
        self.dataplane.send(of_port, str(pkt))
        #@todo Check for unexpected messages?
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)

        self.assertTrue(
            response is None,
            'OFPPC_NO_PACKET_IN flag is ignored on port (got a packet when we asked not to) '
            + str(of_port))
Example #50
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        
        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")    
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    act.port = ofp.OFPP_IN_PORT
                else:
                    act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(self, pkt, ingress_port, action_list=actions)
            request.buffer_id = 0xffffffff
            # pa_logger.info(request.show())

            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Example #51
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        # Clear flow table
        rv = testutils.initialize_table_config(self)
        self.assertEqual(rv, 0, "Failed to initialize table config")
        rv = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        # Set up first match,fengqiang modify at 20130109
        testutils.write_goto_output(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE, of_ports[0])

        # Set up fourth match,fengqiang modify at 20130109
        testutils.write_output(self, testutils.WC_ACL_TABLE, of_ports[1])    
        
        # Generate a packet matching both flow 1 and flow 2; rcv on port[1]
        pkt = testutils.simple_tcp_packet(ip_src = testutils.MT_TEST_IP)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")
Example #52
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

        of_port=config_port_map.keys()[0]
        rv = testutils.port_config_set(self.controller, of_port,
                         ofp.OFPPC_NO_PACKET_IN, ofp.OFPPC_NO_PACKET_IN,
                         config_logger)
        self.assertTrue(rv != -1, "Error sending port mod")
        config_logger.info("NO PKT IN test, port " + str(of_port))

        # make sure config is changed before sending the packet
        testutils.do_barrier(self.controller);


        pkt = testutils.simple_tcp_packet()
        self.dataplane.send(of_port, str(pkt))
        #@todo Check for unexpected messages?
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)

        self.assertTrue(response is None, 
                        'OFPPC_NO_PACKET_IN flag is ignored on port (got a packet when we asked not to) ' + 
                        str(of_port))
Example #53
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

        for of_port in basic_port_map.keys():
            basic_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)

            self.assertTrue(
                response is not None,
                'Packet in message not received on port ' + str(of_port))
            if str(pkt) != response.data:
                basic_logger.debug("pkt  len " + str(len(str(pkt))) + ": " +
                                   str(pkt))
                basic_logger.debug("resp len " + str(len(str(response.data))) +
                                   ": " + str(response.data))

            self.assertEqual(
                str(pkt), response.data,
                'Response packet does not match send packet' + ' for port ' +
                str(of_port))
Example #54
0
    def runTest(self):
        
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[3]
        
        # Remove all entries Add entry match all
        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all
        flow_match = "wildcards=none,dl_src_mask=ff:ff:ff:ff:ff:ff,dl_dst_mask=ff:ff:ff:ff:ff:ff,nw_src_mask=255.255.255.255,nw_dst_mask=255.255.255.255,meta_mask=0xffffffffffffffff" #, -in_port,in_port=1,dl_type=2048in_port=0  wildcards=0xffff
        flow_acts = "apply:output=" + str(egr_port)
        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_tcp_packet()
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #55
0
    def runTest(self):
        
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[3]
        
        # Remove all entries Add entry match all
        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match 
        flow_match = "wildcards=none,nw_src_ipv6=fe80::2420:52ff:fe8f:5189,nw_dst_ipv6=fe80::2420:52ff:fe8f:5190"
        flow_acts = "apply:output=" + str(egr_port)
        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = simple_ipv6_packet(EH = True)
        pa_logger.info("Sending IPv6 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = simple_ipv6_packet(EH = True)
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #56
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane
        # Poll controller with expect message type packet in

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

        # These will get put into function
        outpkt = testutils.simple_tcp_packet()
        of_ports = basic_port_map.keys()
        of_ports.sort()
        for dp_port in of_ports:
            msg = message.packet_out()
            msg.in_port = ofp.OFPP_CONTROLLER
            msg.data = str(outpkt)
            act = action.action_output()
            act.port = dp_port
            self.assertTrue(msg.actions.add(act),
                            'Could not add action to msg')

            basic_logger.info("PacketOut to: " + str(dp_port))
            rv = self.controller.message_send(msg)
            self.assertTrue(rv == 0, "Error sending out message")

            (of_port, pkt, _) = self.dataplane.poll(timeout=1)

            self.assertTrue(pkt is not None, 'Packet not received')
            basic_logger.info("PacketOut: got pkt from " + str(of_port))
            if of_port is not None:
                self.assertEqual(of_port, dp_port, "Unexpected receive port")
            self.assertEqual(str(outpkt), str(pkt),
                             'Response packet does not match send packet')
Example #57
0
    def handleFlow(self, pkttype='TCP'):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        if (pkttype == 'ICMP'):
                pkt = testutils.simple_icmp_packet()
                table_id = testutils.EX_ICMP_TABLE
        else:
                pkt = testutils.simple_tcp_packet()
                table_id = testutils.WC_ACL_TABLE
        
        for idx in range(len(of_ports)):
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")
            testutils.set_table_config(self, table_id, ofp.OFPTC_TABLE_MISS_CONTINUE)

            ingress_port = of_ports[idx]
            egress_port = of_ports[(idx + 1) % len(of_ports)]
            pa_logger.info("Ingress " + str(ingress_port) +
                             " to egress " + str(egress_port))
            
            #controller send flow mod to switch
            request = testutils.flow_msg_create(self,pkt, ing_port=ingress_port, 
                                                egr_port=egress_port, table_id=table_id)
            testutils.flow_msg_install(self, request)
            
            #user send pkt to switch
            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_verify(self, egress_port, pkt)