use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class NeighbourResolutionManagerTest method testPacketDistributionToInterface.
@Test
public void testPacketDistributionToInterface() {
Ethernet arpRequest = createArpRequest(IP1);
NeighbourMessageHandler handler = createMock(NeighbourMessageHandler.class);
handler.handleMessage(eq(createContext(arpRequest, CP1, null)), anyObject(HostService.class));
expectLastCall().once();
replay(handler);
neighbourManager.registerNeighbourHandler(INTF1, handler, APP_ID);
// Incoming packet matching the interface where the handler is registered
packetProcessor.process(context(arpRequest, CP1));
verify(handler);
reset(handler);
replay(handler);
// Incoming packet on same connect point but not matching the interface
packetProcessor.process(context(createArpRequest(IP2), CP1));
verify(handler);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class NeighbourResolutionManagerTest method testPacketDistribution.
@Test
public void testPacketDistribution() {
Ethernet arpRequest = createArpRequest(IP1);
NeighbourMessageHandler handler = createMock(NeighbourMessageHandler.class);
handler.handleMessage(eq(createContext(arpRequest, CP1, null)), anyObject(HostService.class));
expectLastCall().once();
replay(handler);
neighbourManager.registerNeighbourHandler(CP1, handler, APP_ID);
// Incoming packet on the connect point where the handler is registered
packetProcessor.process(context(arpRequest, CP1));
// Send a packet from a different connect point that should not be
// delivered to the handler
packetProcessor.process(context(arpRequest, CP2));
verify(handler);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class NeighbourTestUtils method createArpRequest.
/**
* Creates an ARP request for the given target IP.
*
* @param targetIp IP address
* @return ARP request packet
*/
public static Ethernet createArpRequest(IpAddress targetIp) {
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(MAC1);
eth.setSourceMACAddress(MAC2);
eth.setEtherType(Ethernet.TYPE_ARP);
ARP arp = new ARP();
arp.setOpCode(ARP.OP_REPLY);
arp.setProtocolType(ARP.PROTO_TYPE_IP);
arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
arp.setSenderHardwareAddress(MAC2.toBytes());
arp.setTargetHardwareAddress(MacAddress.ZERO.toBytes());
arp.setTargetProtocolAddress(targetIp.toOctets());
arp.setSenderProtocolAddress(IP2.toOctets());
eth.setPayload(arp);
return eth;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class EthernetCodecTest method ethernetCodecTest.
/**
* Unit test for the ethernet object codec.
*/
@Test
public void ethernetCodecTest() {
final CodecContext context = new MockCodecContext();
final JsonCodec<Ethernet> ethernetCodec = context.codec(Ethernet.class);
assertThat(ethernetCodec, notNullValue());
final Ethernet eth1 = new Ethernet();
eth1.setSourceMACAddress("11:22:33:44:55:01");
eth1.setDestinationMACAddress("11:22:33:44:55:02");
eth1.setPad(true);
eth1.setEtherType(Ethernet.TYPE_ARP);
eth1.setPriorityCode((byte) 7);
eth1.setVlanID((short) 33);
final ObjectNode eth1Json = ethernetCodec.encode(eth1, context);
assertThat(eth1Json, notNullValue());
assertThat(eth1Json, matchesEthernet(eth1));
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class Dhcp6RelayTest method deserializeSolicit.
/**
* Test deserialize relay message with solicit message.
*
* @throws Exception exception while deserialize the DHCPv6 payload
*/
@Test
public void deserializeSolicit() throws Exception {
byte[] data = Resources.toByteArray(Dhcp6RelayTest.class.getResource(SOLICIT));
Ethernet eth = Ethernet.deserializer().deserialize(data, 0, data.length);
DHCP6 relayMsg = (DHCP6) eth.getPayload().getPayload().getPayload();
assertEquals(relayMsg.getMsgType(), DHCP6.MsgType.RELAY_FORW.value());
assertEquals(relayMsg.getHopCount(), HOP_COUNT);
assertEquals(relayMsg.getIp6LinkAddress(), LINK_ADDRESS);
assertEquals(relayMsg.getIp6PeerAddress(), PEER_ADDRESS);
assertEquals(relayMsg.getOptions().size(), 2);
Dhcp6Option option = relayMsg.getOptions().get(0);
assertEquals(option.getCode(), DHCP6.OptionCode.SUBSCRIBER_ID.value());
assertEquals(option.getLength(), 10);
assertArrayEquals(option.getData(), SERVER_IP.toString().getBytes(US_ASCII));
option = relayMsg.getOptions().get(1);
assertEquals(option.getCode(), DHCP6.OptionCode.RELAY_MSG.value());
assertEquals(option.getLength(), 84);
assertTrue(option.getPayload() instanceof DHCP6);
DHCP6 relaiedDhcp6 = (DHCP6) option.getPayload();
assertEquals(relaiedDhcp6.getMsgType(), DHCP6.MsgType.SOLICIT.value());
assertEquals(relaiedDhcp6.getTransactionId(), XID_1);
assertEquals(relaiedDhcp6.getOptions().size(), 4);
// Client ID
option = relaiedDhcp6.getOptions().get(0);
assertTrue(option instanceof Dhcp6ClientIdOption);
Dhcp6ClientIdOption clientIdOption = (Dhcp6ClientIdOption) option;
assertEquals(clientIdOption.getCode(), DHCP6.OptionCode.CLIENTID.value());
assertEquals(clientIdOption.getLength(), 14);
assertEquals(clientIdOption.getDuid().getDuidType(), Dhcp6Duid.DuidType.DUID_LLT);
assertEquals(clientIdOption.getDuid().getHardwareType(), 1);
assertEquals(clientIdOption.getDuid().getDuidTime(), CLIENT_DUID_TIME);
assertArrayEquals(clientIdOption.getDuid().getLinkLayerAddress(), CLIENT_MAC.toBytes());
// ORO
option = relaiedDhcp6.getOptions().get(1);
assertEquals(option.getCode(), DHCP6.OptionCode.ORO.value());
assertEquals(option.getLength(), 8);
assertArrayEquals(option.getData(), new byte[] { 0, 23, 0, 24, 0, 39, 0, 31 });
// ELAPSED_TIME
option = relaiedDhcp6.getOptions().get(2);
assertEquals(option.getCode(), DHCP6.OptionCode.ELAPSED_TIME.value());
assertEquals(option.getLength(), 2);
assertArrayEquals(option.getData(), new byte[] { 0, 0 });
// IA NA
option = relaiedDhcp6.getOptions().get(3);
assertTrue(option instanceof Dhcp6IaNaOption);
Dhcp6IaNaOption iaNaOption = (Dhcp6IaNaOption) option;
assertEquals(iaNaOption.getCode(), DHCP6.OptionCode.IA_NA.value());
assertEquals(iaNaOption.getLength(), 40);
assertEquals(iaNaOption.getIaId(), IA_ID);
assertEquals(iaNaOption.getT1(), T1_CLIENT);
assertEquals(iaNaOption.getT2(), T2_CLIENT);
assertEquals(iaNaOption.getOptions().size(), 1);
Dhcp6IaAddressOption subOption = (Dhcp6IaAddressOption) iaNaOption.getOptions().get(0);
assertEquals(subOption.getIp6Address(), IA_ADDRESS);
assertEquals(subOption.getPreferredLifetime(), PREFFERRED_LT_REQ);
assertEquals(subOption.getValidLifetime(), VALID_LT_REQ);
assertArrayEquals(data, eth.serialize());
}
Aggregations