Search in sources :

Example 1 with PingWiredView

use of org.openkilda.floodlight.model.PingWiredView 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)

Example 2 with PingWiredView

use of org.openkilda.floodlight.model.PingWiredView 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 3 with PingWiredView

use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.

the class PingResponseCommand method unwrap.

private byte[] unwrap() {
    if (input.packetInCookieMismatchAll(log, PingService.OF_CATCH_RULE_COOKIE, PingService.OF_CATCH_RULE_COOKIE_VXLAN)) {
        return null;
    }
    Ethernet ethernetPackage = input.getPacketInPayload();
    if (ethernetPackage == null) {
        log.error("{} - payload is missing", input);
        return null;
    }
    PingWiredView wiredView = getPingService().unwrapData(input.getDpId(), ethernetPackage);
    if (wiredView == null) {
        return null;
    }
    return wiredView.getPayload();
}
Also used : PingWiredView(org.openkilda.floodlight.model.PingWiredView) Ethernet(net.floodlightcontroller.packet.Ethernet)

Example 4 with PingWiredView

use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.

the class PingServiceTest method testWrapUnwrapCycleVlan.

@Test
public void testWrapUnwrapCycleVlan() throws Exception {
    Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 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 decoded = new Ethernet().deserialize(wrapped, 0, wrapped.length);
    Assert.assertTrue(decoded instanceof Ethernet);
    PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
    Assert.assertNotNull(parsed);
    Assert.assertArrayEquals(payload, parsed.getPayload());
    Assert.assertEquals(ping.getTransitEncapsulation().getId(), parsed.getVlanStack().get(0));
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) InputService(org.openkilda.floodlight.service.of.InputService) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) PingWiredView(org.openkilda.floodlight.model.PingWiredView) Ping(org.openkilda.messaging.model.Ping) Ethernet(net.floodlightcontroller.packet.Ethernet) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Aggregations

PingWiredView (org.openkilda.floodlight.model.PingWiredView)4 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 IPv4 (net.floodlightcontroller.packet.IPv4)2 UDP (net.floodlightcontroller.packet.UDP)2 Test (org.junit.Test)2 InputService (org.openkilda.floodlight.service.of.InputService)2 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)2 Ping (org.openkilda.messaging.model.Ping)2 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)2 SwitchId (org.openkilda.model.SwitchId)2 ArrayList (java.util.ArrayList)1 Vxlan (org.openkilda.floodlight.shared.packet.Vxlan)1 MacAddress (org.projectfloodlight.openflow.types.MacAddress)1