Search in sources :

Example 1 with PROTOCOL_MPLS

use of org.onlab.packet.MPLS.PROTOCOL_MPLS in project onos by opennetworkinglab.

the class MplsTest method testIpv4OverMplsDeserialize.

@Test
public void testIpv4OverMplsDeserialize() throws Exception {
    // Serialize
    byte[] packet = ETH_IPV4.serialize();
    assertThat(MPLS_IPV4.protocol, is(PROTOCOL_MPLS));
    assertThat(MPLS_IPV4.bos, is((byte) 0));
    assertThat(MPLS_BOS_IPV4.protocol, is(PROTOCOL_IPV4));
    assertThat(MPLS_BOS_IPV4.bos, is((byte) 1));
    // Deserialize
    Ethernet ethernet;
    ethernet = Ethernet.deserializer().deserialize(packet, 0, packet.length);
    // Verify
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_IPV4.getSourceMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_IPV4.getDestinationMAC()));
    assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST));
    assertTrue(ethernet.getPayload() instanceof MPLS);
    MPLS mpls = (MPLS) ethernet.getPayload();
    assertThat(mpls.getLabel(), is(1));
    assertThat(mpls.getTtl(), is((byte) 0));
    assertThat(mpls.protocol, is(PROTOCOL_MPLS));
    assertThat(mpls.bos, is((byte) 0));
    assertTrue(mpls.getPayload() instanceof MPLS);
    mpls = (MPLS) mpls.getPayload();
    assertThat(mpls.getLabel(), is(101));
    assertThat(mpls.getTtl(), is((byte) 0));
    assertThat(mpls.protocol, is(PROTOCOL_IPV4));
    assertThat(mpls.bos, is((byte) 1));
    IPv4 ip = (IPv4) mpls.getPayload();
    assertThat(ip.getSourceAddress(), is(SRC_IPV4.toInt()));
    assertThat(ip.getDestinationAddress(), is(DST_IPV4.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REQUEST));
}
Also used : PROTOCOL_MPLS(org.onlab.packet.MPLS.PROTOCOL_MPLS) PROTOCOL_ICMP(org.onlab.packet.IPv4.PROTOCOL_ICMP) Test(org.junit.Test)

Example 2 with PROTOCOL_MPLS

use of org.onlab.packet.MPLS.PROTOCOL_MPLS in project onos by opennetworkinglab.

the class MplsTest method testIpv6OverMplsDeserialize.

@Test
public void testIpv6OverMplsDeserialize() throws Exception {
    // Serialize
    byte[] packet = ETH_IPV6.serialize();
    assertThat(MPLS_IPV6.protocol, is(PROTOCOL_MPLS));
    assertThat(MPLS_IPV6.bos, is((byte) 0));
    assertThat(MPLS_BOS_IPV6.protocol, is(PROTOCOL_IPV6));
    assertThat(MPLS_BOS_IPV6.bos, is((byte) 1));
    // Deserialize
    Ethernet ethernet;
    ethernet = Ethernet.deserializer().deserialize(packet, 0, packet.length);
    // Verify
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_IPV6.getSourceMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_IPV6.getDestinationMAC()));
    assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST));
    assertTrue(ethernet.getPayload() instanceof MPLS);
    MPLS mpls = (MPLS) ethernet.getPayload();
    assertThat(mpls.getLabel(), is(2));
    assertThat(mpls.getTtl(), is((byte) 0));
    assertThat(mpls.protocol, is(PROTOCOL_MPLS));
    assertThat(mpls.bos, is((byte) 0));
    assertTrue(mpls.getPayload() instanceof MPLS);
    mpls = (MPLS) mpls.getPayload();
    assertThat(mpls.getLabel(), is(201));
    assertThat(mpls.getTtl(), is((byte) 0));
    assertThat(mpls.protocol, is(PROTOCOL_IPV6));
    assertThat(mpls.bos, is((byte) 1));
    IPv6 ip = (IPv6) mpls.getPayload();
    assertThat(ip.getSourceAddress(), is(SRC_IPV6.toOctets()));
    assertThat(ip.getDestinationAddress(), is(DST_IPV6.toOctets()));
    assertTrue(ip.getPayload() instanceof ICMP6);
    ICMP6 icmp = (ICMP6) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(ECHO_REQUEST));
}
Also used : PROTOCOL_MPLS(org.onlab.packet.MPLS.PROTOCOL_MPLS) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 PROTOCOL_MPLS (org.onlab.packet.MPLS.PROTOCOL_MPLS)2 PROTOCOL_ICMP (org.onlab.packet.IPv4.PROTOCOL_ICMP)1