Search in sources :

Example 21 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4GatewayPair.

// Ping to a dh gateway
@Test
public void testPing4GatewayPair() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_GATEWAY_PAIR, CP2011);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_GATEWAY_PAIR.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 22 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4MyGateway.

// Ping to our gateway
@Test
public void testPing4MyGateway() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_MY, CP12);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_MY.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_MY.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_MY.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 23 with IPv4

use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.

the class DirectHostManager method transformAndSend.

private void transformAndSend(IP ip, short ethType, Interface egressInterface, MacAddress macAddress) {
    // Base processing for IPv4
    if (ethType == Ethernet.TYPE_IPV4) {
        IPv4 ipv4 = (IPv4) ip;
        ipv4.setTtl((byte) (ipv4.getTtl() - 1));
        ipv4.setChecksum((short) 0);
    // Base processing for IPv6.
    } else {
        IPv6 ipv6 = (IPv6) ip;
        ipv6.setHopLimit((byte) (ipv6.getHopLimit() - 1));
        ipv6.resetChecksum();
    }
    // Sends and serializes.
    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(macAddress);
    eth.setSourceMACAddress(egressInterface.mac());
    eth.setEtherType(ethType);
    eth.setPayload(ip);
    if (!egressInterface.vlan().equals(VlanId.NONE)) {
        eth.setVlanID(egressInterface.vlan().toShort());
    }
    send(eth, egressInterface.connectPoint());
}
Also used : IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet)

Example 24 with IPv4

use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.

the class DhcpRelayManagerTest method testWithRelayAgentConfig.

@Test
public void testWithRelayAgentConfig() throws DeserializationException {
    manager.v4Handler.setDefaultDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
    manager.v4Handler.setIndirectDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
    packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC, CLIENT2_VLAN, CLIENT2_CP, INTERFACE_IP.ipAddress().getIp4Address(), true));
    assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket));
    OutboundPacket outPacket = packetService.emittedPacket;
    byte[] outData = outPacket.data().array();
    Ethernet eth = Ethernet.deserializer().deserialize(outData, 0, outData.length);
    IPv4 ip = (IPv4) eth.getPayload();
    UDP udp = (UDP) ip.getPayload();
    DHCP dhcp = (DHCP) udp.getPayload();
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(RELAY_AGENT_IP.toInt(), dhcp.getGatewayIPAddress()));
}
Also used : UDP(org.onlab.packet.UDP) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DHCP(org.onlab.packet.DHCP) Test(org.junit.Test)

Example 25 with IPv4

use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.

the class PimInterface method processJoinPrune.

/**
 * Process an incoming PIM JoinPrune message.
 *
 * @param ethPkt the Ethernet packet header.
 */
public void processJoinPrune(Ethernet ethPkt) {
    IPv4 ip = (IPv4) ethPkt.getPayload();
    checkNotNull(ip);
    PIM pim = (PIM) ip.getPayload();
    checkNotNull(pim);
    PIMJoinPrune jpHdr = (PIMJoinPrune) pim.getPayload();
    checkNotNull(jpHdr);
    /*
         * The Join/Prune messages are grouped by Group address. We'll walk each group address
         * where we will possibly have to walk a list of source address for the joins and prunes.
         */
    Collection<PIMJoinPruneGroup> jpgs = jpHdr.getJoinPrunes();
    for (PIMJoinPruneGroup jpg : jpgs) {
        IpPrefix gpfx = jpg.getGroup();
        // Walk the joins first.
        for (IpPrefix spfx : jpg.getJoins().values()) {
        // We may need
        }
        for (IpPrefix spfx : jpg.getPrunes().values()) {
        // TODO: this is where we many need to remove multi-cast state and possibly intents.
        }
    }
}
Also used : PIMJoinPrune(org.onlab.packet.pim.PIMJoinPrune) IpPrefix(org.onlab.packet.IpPrefix) PIM(org.onlab.packet.PIM) PIMJoinPruneGroup(org.onlab.packet.pim.PIMJoinPruneGroup) IPv4(org.onlab.packet.IPv4)

Aggregations

IPv4 (org.onlab.packet.IPv4)54 Ethernet (org.onlab.packet.Ethernet)43 UDP (org.onlab.packet.UDP)24 DHCP (org.onlab.packet.DHCP)18 ICMP (org.onlab.packet.ICMP)17 IpAddress (org.onlab.packet.IpAddress)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 Test (org.junit.Test)12 Ip4Address (org.onlab.packet.Ip4Address)10 MacAddress (org.onlab.packet.MacAddress)10 ConnectPoint (org.onosproject.net.ConnectPoint)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 ByteBuffer (java.nio.ByteBuffer)8 Optional (java.util.Optional)8 Interface (org.onosproject.net.intf.Interface)8 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)8 DhcpOption (org.onlab.packet.dhcp.DhcpOption)7 ApplicationId (org.onosproject.core.ApplicationId)7