示例#1
0
 def test__hints_for_own_beacon_received_on_same_interface(self):
     # Note: Always use a random port for testing. (port=0)
     protocol = BeaconingSocketProtocol(
         reactor,
         port=0,
         process_incoming=False,
         loopback=True,
         interface="::",
         debug=True,
     )
     # Need to generate a real UUID with the current time, so it doesn't
     # get aged out.
     uuid = str(uuid1())
     # Make the protocol think we sent a beacon with this UUID already.
     fake_tx_beacon = FakeBeaconPayload(uuid, ifname="eth0")
     protocol.tx_queue[uuid] = fake_tx_beacon
     fake_rx_beacon = {
         "source_ip": "127.0.0.1",
         "source_port": 5240,
         "destination_ip": "224.0.0.118",
         "interface": "eth0",
         "type": "solicitation",
         "payload": fake_tx_beacon.payload,
     }
     protocol.beaconReceived(fake_rx_beacon)
     # Should only have created one hint.
     hint = protocol.topology_hints[uuid].pop()
     self.assertThat(hint.hint, Equals("rx_own_beacon_on_tx_interface"))
     yield protocol.stopProtocol()
示例#2
0
 def test__hints_for_same_beacon_seen_on_multiple_interfaces(self):
     # Note: Always use a random port for testing. (port=0)
     protocol = BeaconingSocketProtocol(
         reactor,
         port=0,
         process_incoming=False,
         loopback=True,
         interface="::",
         debug=True,
     )
     # Don't try to send out any replies.
     self.patch(services, "create_beacon_payload")
     self.patch(protocol, "send_beacon")
     # Need to generate a real UUID with the current time, so it doesn't
     # get aged out.
     uuid = str(uuid1())
     # Make the protocol think we sent a beacon with this UUID already.
     fake_tx_beacon = FakeBeaconPayload(uuid, ifname="eth0")
     fake_rx_beacon_eth0 = {
         "source_ip": "127.0.0.1",
         "source_port": 5240,
         "destination_ip": "224.0.0.118",
         "interface": "eth0",
         "type": "solicitation",
         "payload": fake_tx_beacon.payload,
     }
     fake_rx_beacon_eth1 = {
         "source_ip": "127.0.0.1",
         "source_port": 5240,
         "destination_ip": "224.0.0.118",
         "interface": "eth1",
         "vid": 100,
         "type": "solicitation",
         "payload": fake_tx_beacon.payload,
     }
     protocol.beaconReceived(fake_rx_beacon_eth0)
     protocol.beaconReceived(fake_rx_beacon_eth1)
     hints = protocol.topology_hints[uuid]
     expected_hints = {
         TopologyHint(
             ifname="eth0",
             vid=None,
             hint="same_local_fabric_as",
             related_ifname="eth1",
             related_vid=100,
             related_mac=None,
         ),
         TopologyHint(
             ifname="eth1",
             vid=100,
             hint="same_local_fabric_as",
             related_ifname="eth0",
             related_vid=None,
             related_mac=None,
         ),
     }
     self.assertThat(hints, Equals(expected_hints))
     yield protocol.stopProtocol()
示例#3
0
 def test__getJSONTopologyHints_converts_hints_to_dictionary(self):
     # Note: Always use a random port for testing. (port=0)
     protocol = BeaconingSocketProtocol(
         reactor,
         port=0,
         process_incoming=False,
         loopback=True,
         interface="::",
         debug=True,
     )
     # Don't try to send out any replies.
     self.patch(services, "create_beacon_payload")
     self.patch(protocol, "send_beacon")
     # Need to generate a real UUID with the current time, so it doesn't
     # get aged out.
     uuid = str(uuid1())
     # Make the protocol think we sent a beacon with this UUID already.
     tx_mac = factory.make_mac_address()
     fake_tx_beacon = FakeBeaconPayload(uuid,
                                        ifname="eth1",
                                        mac=tx_mac,
                                        vid=100)
     fake_rx_beacon = {
         "source_ip": "127.0.0.1",
         "source_port": 5240,
         "destination_ip": "224.0.0.118",
         "interface": "eth0",
         "type": "solicitation",
         "payload": fake_tx_beacon.payload,
     }
     protocol.beaconReceived(fake_rx_beacon)
     all_hints = protocol.getJSONTopologyHints()
     expected_hints = [
         # Note: since vid=None on the received beacon, we expect that
         # the hint won't have a 'vid' field.
         dict(
             ifname="eth0",
             hint="on_remote_network",
             related_ifname="eth1",
             related_vid=100,
             related_mac=tx_mac,
         )
     ]
     self.assertThat(all_hints, Equals(expected_hints))
     yield protocol.stopProtocol()