Search in sources :

Example 11 with IPv4

use of net.floodlightcontroller.packet.IPv4 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

IPv4 (net.floodlightcontroller.packet.IPv4)11 UDP (net.floodlightcontroller.packet.UDP)11 Ethernet (net.floodlightcontroller.packet.Ethernet)10 DatapathId (org.projectfloodlight.openflow.types.DatapathId)5 IPacket (net.floodlightcontroller.packet.IPacket)4 OFPacketOut (org.projectfloodlight.openflow.protocol.OFPacketOut)4 LLDPTLV (net.floodlightcontroller.packet.LLDPTLV)3 MacAddress (org.projectfloodlight.openflow.types.MacAddress)3 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 FloodlightModuleException (net.floodlightcontroller.core.module.FloodlightModuleException)2 Data (net.floodlightcontroller.packet.Data)2 Test (org.junit.Test)2 PingWiredView (org.openkilda.floodlight.model.PingWiredView)2 Vxlan (org.openkilda.floodlight.shared.packet.Vxlan)2 OFPortDescPropEthernet (org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet)2