Example #1
0
 def test_arp_reply(self):
   '''Receive a valid ARP packet and ensure the correct reply'''
   interfaces = [HostInterface(EthAddr(H2_I1_ETH),[IPAddr(H2_I1_IP1),IPAddr(H2_I1_IP2)]),HostInterface(EthAddr(H2_I2_ETH),[IPAddr(H2_I2_IP)])]
   h = Host(interfaces)
   arp_req = arp()
   arp_req.hwsrc = EthAddr(H1_I1_ETH)
   arp_req.hwdst = EthAddr(b"\xff\xff\xff\xff\xff\xff")
   arp_req.opcode = arp.REQUEST
   arp_req.protosrc = IPAddr(H1_I1_IP)
   arp_req.protodst = IPAddr(H2_I1_IP1)
   ether = ethernet()
   ether.type = ethernet.ARP_TYPE
   ether.dst = EthAddr(b"\xff\xff\xff\xff\xff\xff")
   ether.src = EthAddr(H1_I1_ETH)
   ether.payload = arp_req
   # Get the action and arp reply packet
   arp_reply = h.receive(interfaces[0],ether)
   self.assertTrue(arp_reply is not None)
   self.assertEqual(arp_reply.src,EthAddr(H2_I1_ETH))
   self.assertEqual(arp_reply.dst,EthAddr(H1_I1_ETH))
   self.assertEqual(arp_reply.type,ethernet.ARP_TYPE)
   reply_payload = arp_reply.payload
   self.assertEqual(reply_payload.opcode,arp.REPLY)
   self.assertEqual(reply_payload.hwsrc,EthAddr(H2_I1_ETH))
   self.assertEqual(reply_payload.hwdst,EthAddr(H1_I1_ETH))
   self.assertTrue(reply_payload.protosrc == H2_I1_IP1)
   self.assertTrue(reply_payload.protodst == H1_I1_IP)
Example #2
0
 def test_none_arp(self):
   '''Receive a non-ARP packet and ensure there is no reply'''
   interfaces = [HostInterface(EthAddr(H2_I1_ETH),[IPAddr(H2_I1_IP1),IPAddr(H2_I1_IP2)]),HostInterface(EthAddr(H2_I2_ETH),[IPAddr(H2_I2_IP)])]
   h = Host(interfaces)
   ether = ethernet()
   ether.type = ethernet.IP_TYPE
   ether.dst = EthAddr(H2_I1_ETH)
   ether.src = EthAddr(H1_I1_ETH)
   # Get the action and reply packet
   reply_packet = h.receive(interfaces[0],ether)
   self.assertTrue(reply_packet is None)
Example #3
0
    def setUp(self):
        class MockSwitch(SoftwareSwitch):
            _eventMixin_events = set([DpPacketOut])

            def __init__(self, dpid, ports):
                self.has_forwarded = False
                self.dpid = dpid
                self.ports = {}
                for port in ports:
                    self.ports[port.port_no] = port

            def process_packet(self, packet, in_port):
                self.has_forwarded = True

        def create_mock_switch(num_ports, switch_id):
            ports = []
            for port_no in range(1, num_ports + 1):
                port = ofp_phy_port(port_no=port_no,
                                    hw_addr=EthAddr("00:00:00:00:%02x:%02x" %
                                                    (switch_id, port_no)))
                # monkey patch an IP address onto the port for anteater purposes
                port.ip_addr = "1.1.%d.%d" % (switch_id, port_no)
                ports.append(port)
            return MockSwitch(switch_id, ports)

        self.g = Graph()
        self.switches = [create_mock_switch(2, 1), create_mock_switch(2, 2)]
        self.hosts = [
            Host([HostInterface(EthAddr("00:00:00:00:00:01"))], name="host1"),
            Host([HostInterface(EthAddr("00:00:00:00:00:02"))], name="host2")
        ]
        for switch in self.switches:
            self.g.add(switch)
        for host in self.hosts:
            self.g.add(host)
        self.g.link((self.switches[0], self.switches[0].ports[2]),
                    (self.switches[1], self.switches[1].ports[2]))
        self.g.link((self.hosts[0], self.hosts[0].interfaces[0]),
                    (self.switches[0], self.switches[0].ports[1]))
        self.g.link((self.hosts[1], self.hosts[1].interfaces[0]),
                    (self.switches[1], self.switches[1].ports[1]))
        topology = Topology.populate_from_topology(self.g)
        self.patch = BufferedPatchPanelForTopology(self.g)
        self.switches_calc = topology.switches
        self.hosts_calc = topology.hosts
        self.access_links = topology.access_links
Example #4
0
 def test_invalid_arp(self):
   '''Receive a ARP packet that isn't desinated to it and ensure there is no reply'''
   interfaces = [HostInterface(EthAddr(H2_I1_ETH),[IPAddr(H2_I1_IP1),IPAddr(H2_I1_IP2)]),HostInterface(EthAddr(H2_I2_ETH),[IPAddr(H2_I2_IP)])]
   h = Host(interfaces)
   arp_req = arp()
   arp_req.hwsrc = EthAddr(H1_I1_ETH)
   arp_req.hwdst = EthAddr(b"\xff\xff\xff\xff\xff\xff")
   arp_req.opcode = arp.REQUEST
   arp_req.protosrc = IPAddr(H1_I1_IP)
   arp_req.protodst = IPAddr(H3_I3_IP)
   ether = ethernet()
   ether.type = ethernet.ARP_TYPE
   ether.dst = EthAddr(b"\xff\xff\xff\xff\xff\xff")
   ether.src = EthAddr(H1_I1_ETH)
   ether.payload = arp_req
   # Get the action and reply packet
   reply_packet = h.receive(interfaces[0],ether)
   self.assertTrue(reply_packet is None)