Search in sources :

Example 1 with Vxlan

use of org.openkilda.floodlight.shared.packet.Vxlan 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 Vxlan

use of org.openkilda.floodlight.shared.packet.Vxlan in project open-kilda by telstra.

the class PingService method wrapData.

/**
 * Wrap ping data into L2, l3 and L4 network packages.
 */
public IPacket wrapData(Ping ping, byte[] payload) throws PingImpossibleException {
    Data l7 = new Data(payload);
    UDP l4 = new UDP();
    l4.setPayload(l7);
    l4.setSourcePort(TransportPort.of(NET_L3_PORT));
    l4.setDestinationPort(TransportPort.of(NET_L3_PORT));
    IPv4 l3 = new IPv4();
    l3.setPayload(l4);
    l3.setSourceAddress(NET_L3_ADDRESS);
    l3.setDestinationAddress(NET_L3_ADDRESS);
    l3.setTtl(NET_L3_TTL);
    Ethernet l2 = new Ethernet();
    l2.setPayload(l3);
    l2.setEtherType(EthType.IPv4);
    l2.setSourceMACAddress(magicSourceMacAddress);
    DatapathId egressSwitch = DatapathId.of(ping.getDest().getDatapath().toLong());
    l2.setDestinationMACAddress(MacAddress.of(egressSwitch));
    if (FlowEncapsulationType.TRANSIT_VLAN.equals(ping.getTransitEncapsulation().getType())) {
        l2.setVlanID(ping.getTransitEncapsulation().getId().shortValue());
        return l2;
    } else if (FlowEncapsulationType.VXLAN.equals(ping.getTransitEncapsulation().getType())) {
        Vxlan vxlan = new Vxlan();
        vxlan.setPayload(l2);
        vxlan.setVni(ping.getTransitEncapsulation().getId());
        UDP udp = new UDP();
        udp.setPayload(vxlan);
        udp.setSourcePort(TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
        udp.setDestinationPort(TransportPort.of(SwitchManager.VXLAN_UDP_DST));
        IPv4 ipv4 = new IPv4();
        ipv4.setPayload(udp);
        ipv4.setProtocol(IpProtocol.UDP);
        ipv4.setSourceAddress(SwitchManager.STUB_VXLAN_IPV4_SRC);
        ipv4.setDestinationAddress(SwitchManager.STUB_VXLAN_IPV4_DST);
        ipv4.setTtl(NET_L3_TTL);
        Ethernet ethernet = new Ethernet();
        ethernet.setPayload(ipv4);
        ethernet.setEtherType(EthType.IPv4);
        ethernet.setSourceMACAddress(magicSourceMacAddress);
        ethernet.setDestinationMACAddress(MacAddress.of(egressSwitch));
        return ethernet;
    }
    throw new PingImpossibleException(ping, Errors.INCORRECT_REQUEST);
}
Also used : UDP(net.floodlightcontroller.packet.UDP) Vxlan(org.openkilda.floodlight.shared.packet.Vxlan) PingImpossibleException(org.openkilda.floodlight.error.PingImpossibleException) IPv4(net.floodlightcontroller.packet.IPv4) Ethernet(net.floodlightcontroller.packet.Ethernet) Data(net.floodlightcontroller.packet.Data) DatapathId(org.projectfloodlight.openflow.types.DatapathId)

Aggregations

Ethernet (net.floodlightcontroller.packet.Ethernet)2 IPv4 (net.floodlightcontroller.packet.IPv4)2 UDP (net.floodlightcontroller.packet.UDP)2 Vxlan (org.openkilda.floodlight.shared.packet.Vxlan)2 Data (net.floodlightcontroller.packet.Data)1 IPacket (net.floodlightcontroller.packet.IPacket)1 Test (org.junit.Test)1 PingImpossibleException (org.openkilda.floodlight.error.PingImpossibleException)1 PingWiredView (org.openkilda.floodlight.model.PingWiredView)1 InputService (org.openkilda.floodlight.service.of.InputService)1 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)1 Ping (org.openkilda.messaging.model.Ping)1 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)1 SwitchId (org.openkilda.model.SwitchId)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1