Search in sources :

Example 1 with IPacket

use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.

the class EthernetPacketToolbox method extractPayload.

/**
 * Read through intermediate vlan headers up to actual packet payload. Return both payload and vlan stack.
 */
public static IPacket extractPayload(Ethernet packet, List<Integer> vlanStack) {
    short rootVlan = packet.getVlanID();
    if (0 < rootVlan) {
        vlanStack.add((int) rootVlan);
    }
    IPacket payload = packet.getPayload();
    while (payload instanceof VlanTag) {
        short vlanId = ((VlanTag) payload).getVlanId();
        vlanStack.add((int) vlanId);
        payload = payload.getPayload();
    }
    return payload;
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) VlanTag(org.openkilda.floodlight.shared.packet.VlanTag)

Example 2 with IPacket

use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.

the class ConnectedDevicesService method deserializeArp.

@VisibleForTesting
ArpPacketData deserializeArp(Ethernet eth, SwitchId switchId, long cookie) {
    try {
        List<Integer> vlans = new ArrayList<>();
        IPacket payload = EthernetPacketToolbox.extractPayload(eth, vlans);
        if (payload instanceof ARP) {
            return new ArpPacketData((ARP) payload, vlans);
        }
    } catch (Exception exception) {
        logger.info("Could not deserialize ARP packet {} on switch {}. Cookie {}. Deserialization failure: {}", eth, switchId, Cookie.toString(cookie), exception.getMessage(), exception);
        return null;
    }
    logger.info("Got invalid ARP packet: {} on switch {}. Cookie {}", eth, switchId, cookie);
    return null;
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) ArrayList(java.util.ArrayList) ARP(net.floodlightcontroller.packet.ARP) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with IPacket

use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.

the class ConnectedDevicesService method deserializeLldp.

@VisibleForTesting
LldpPacketData deserializeLldp(Ethernet eth, SwitchId switchId, long cookie) {
    try {
        List<Integer> vlans = new ArrayList<>();
        IPacket payload = EthernetPacketToolbox.extractPayload(eth, vlans);
        if (payload instanceof LLDP) {
            LldpPacket lldpPacket = new LldpPacket((LLDP) payload);
            return new LldpPacketData(lldpPacket, vlans);
        }
    } catch (Exception exception) {
        logger.info("Could not deserialize LLDP packet {} on switch {}. Cookie {}. Deserialization failure: {}", eth, switchId, Cookie.toString(cookie), exception.getMessage(), exception);
        return null;
    }
    logger.info("Got invalid lldp packet: {} on switch {}. Cookie {}", eth, switchId, cookie);
    return null;
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) ArrayList(java.util.ArrayList) LLDP(net.floodlightcontroller.packet.LLDP) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with IPacket

use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.

the class PingService method unwrapData.

/**
 * Unpack network package.
 * Verify all particular qualities used during discovery package creation time. Return packet payload.
 */
public PingWiredView unwrapData(DatapathId dpId, Ethernet packet) {
    MacAddress targetL2Address = MacAddress.of(dpId);
    if (!packet.getDestinationMACAddress().equals(targetL2Address)) {
        return null;
    }
    List<Integer> vlanStack = new ArrayList<>();
    IPacket payload = EthernetPacketToolbox.extractPayload(packet, vlanStack);
    if (!(payload instanceof IPv4)) {
        return null;
    }
    IPv4 ip = (IPv4) payload;
    if (!NET_L3_ADDRESS.equals(ip.getSourceAddress().toString())) {
        return null;
    }
    if (!NET_L3_ADDRESS.equals(ip.getDestinationAddress().toString())) {
        return null;
    }
    if (!(ip.getPayload() instanceof UDP)) {
        return null;
    }
    UDP udp = (UDP) ip.getPayload();
    if (udp.getSourcePort().getPort() != NET_L3_PORT) {
        return null;
    }
    if (udp.getDestinationPort().getPort() != NET_L3_PORT) {
        return null;
    }
    return new PingWiredView(vlanStack, udp.getPayload().serialize());
}
Also used : UDP(net.floodlightcontroller.packet.UDP) IPacket(net.floodlightcontroller.packet.IPacket) PingWiredView(org.openkilda.floodlight.model.PingWiredView) IPv4(net.floodlightcontroller.packet.IPv4) ArrayList(java.util.ArrayList) MacAddress(org.projectfloodlight.openflow.types.MacAddress)

Example 5 with IPacket

use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.

the class PingServiceTest method testWrapUnwrapCycleVxlan.

@Test
public void testWrapUnwrapCycleVxlan() throws Exception {
    Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.VXLAN), 3);
    moduleContext.getServiceImpl(InputService.class).addTranslator(eq(OFType.PACKET_IN), anyObject(PingInputTranslator.class));
    replayAll();
    pingService.setup(moduleContext);
    byte[] payload = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
    byte[] wrapped = pingService.wrapData(ping, payload).serialize();
    IPacket ethernet = new Ethernet().deserialize(wrapped, 0, wrapped.length);
    Assert.assertTrue(ethernet instanceof Ethernet);
    IPacket ipv4 = ethernet.getPayload();
    Assert.assertTrue(ipv4 instanceof IPv4);
    IPacket udp = ipv4.getPayload();
    Assert.assertTrue(udp instanceof UDP);
    Assert.assertEquals(((UDP) udp).getSourcePort(), TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
    Assert.assertEquals(((UDP) udp).getDestinationPort(), TransportPort.of(SwitchManager.VXLAN_UDP_DST));
    byte[] udpPayload = udp.getPayload().serialize();
    Vxlan vxlan = (Vxlan) new Vxlan().deserialize(udpPayload, 0, udpPayload.length);
    Assert.assertEquals((int) ping.getTransitEncapsulation().getId(), vxlan.getVni());
    byte[] vxlanPayload = vxlan.getPayload().serialize();
    IPacket decoded = new Ethernet().deserialize(vxlanPayload, 0, vxlanPayload.length);
    Assert.assertTrue(decoded instanceof Ethernet);
    PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
    Assert.assertNotNull(parsed);
    Assert.assertArrayEquals(payload, parsed.getPayload());
    Assert.assertTrue(parsed.getVlanStack().isEmpty());
}
Also used : UDP(net.floodlightcontroller.packet.UDP) IPacket(net.floodlightcontroller.packet.IPacket) Vxlan(org.openkilda.floodlight.shared.packet.Vxlan) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) IPv4(net.floodlightcontroller.packet.IPv4) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) InputService(org.openkilda.floodlight.service.of.InputService) PingWiredView(org.openkilda.floodlight.model.PingWiredView) Ping(org.openkilda.messaging.model.Ping) Ethernet(net.floodlightcontroller.packet.Ethernet) Test(org.junit.Test)

Aggregations

IPacket (net.floodlightcontroller.packet.IPacket)13 Ethernet (net.floodlightcontroller.packet.Ethernet)9 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 IPv4 (net.floodlightcontroller.packet.IPv4)4 UDP (net.floodlightcontroller.packet.UDP)4 DatapathId (org.projectfloodlight.openflow.types.DatapathId)4 PingWiredView (org.openkilda.floodlight.model.PingWiredView)3 InputService (org.openkilda.floodlight.service.of.InputService)3 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)3 Ping (org.openkilda.messaging.model.Ping)3 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)3 SwitchId (org.openkilda.model.SwitchId)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 InetAddress (java.net.InetAddress)2 FloodlightContext (net.floodlightcontroller.core.FloodlightContext)2 OfInput (org.openkilda.floodlight.model.OfInput)2 OFPacketIn (org.projectfloodlight.openflow.protocol.OFPacketIn)2 OFPacketOut (org.projectfloodlight.openflow.protocol.OFPacketOut)2 TransportPort (org.projectfloodlight.openflow.types.TransportPort)2