Search in sources :

Example 91 with Ethernet

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);
}
Also used : HostService(org.onosproject.net.host.HostService) Ethernet(org.onlab.packet.Ethernet) NeighbourMessageHandler(org.onosproject.net.neighbour.NeighbourMessageHandler) Test(org.junit.Test)

Example 92 with Ethernet

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);
}
Also used : HostService(org.onosproject.net.host.HostService) Ethernet(org.onlab.packet.Ethernet) NeighbourMessageHandler(org.onosproject.net.neighbour.NeighbourMessageHandler) Test(org.junit.Test)

Example 93 with Ethernet

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;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 94 with Ethernet

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));
}
Also used : CodecContext(org.onosproject.codec.CodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Ethernet(org.onlab.packet.Ethernet) EthernetJsonMatcher.matchesEthernet(org.onosproject.codec.impl.EthernetJsonMatcher.matchesEthernet) Test(org.junit.Test)

Example 95 with Ethernet

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());
}
Also used : Ethernet(org.onlab.packet.Ethernet) DHCP6(org.onlab.packet.DHCP6) Test(org.junit.Test)

Aggregations

Ethernet (org.onlab.packet.Ethernet)187 Test (org.junit.Test)91 ConnectPoint (org.onosproject.net.ConnectPoint)46 IPv4 (org.onlab.packet.IPv4)42 IPv6 (org.onlab.packet.IPv6)41 UDP (org.onlab.packet.UDP)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 MacAddress (org.onlab.packet.MacAddress)30 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)30 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)29 IpAddress (org.onlab.packet.IpAddress)28 OutboundPacket (org.onosproject.net.packet.OutboundPacket)26 DeviceId (org.onosproject.net.DeviceId)25 ByteBuffer (java.nio.ByteBuffer)24 DHCP (org.onlab.packet.DHCP)24 DHCP6 (org.onlab.packet.DHCP6)24 Interface (org.onosproject.net.intf.Interface)22 DeserializationException (org.onlab.packet.DeserializationException)20 ICMP6 (org.onlab.packet.ICMP6)20 InboundPacket (org.onosproject.net.packet.InboundPacket)20