Search in sources :

Example 6 with IPv4

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

the class BfdSessionCommand method makeSessionConfigPayload.

private IPacket makeSessionConfigPayload(IOFSwitch sw) {
    final TransportPort udpPort = TransportPort.of(bfdSession.getUdpPortNumber());
    UDP l4 = new UDP().setSourcePort(udpPort).setDestinationPort(udpPort);
    InetAddress sourceIpAddress = bfdSession.getTarget().getInetAddress();
    InetAddress destIpAddress = bfdSession.getRemote().getInetAddress();
    IPacket l3 = new IPv4().setSourceAddress(IPv4Address.of(sourceIpAddress.getAddress())).setDestinationAddress(IPv4Address.of(destIpAddress.getAddress())).setProtocol(IpProtocol.UDP).setPayload(l4);
    DatapathId remoteDatapath = DatapathId.of(bfdSession.getRemote().getDatapath().toLong());
    return new Ethernet().setEtherType(EthType.IPv4).setSourceMACAddress(convertDpIdToMac(sw.getId())).setDestinationMACAddress(convertDpIdToMac(remoteDatapath)).setPayload(l3);
}
Also used : UDP(net.floodlightcontroller.packet.UDP) IPacket(net.floodlightcontroller.packet.IPacket) IPv4(net.floodlightcontroller.packet.IPv4) Ethernet(net.floodlightcontroller.packet.Ethernet) DatapathId(org.projectfloodlight.openflow.types.DatapathId) TransportPort(org.projectfloodlight.openflow.types.TransportPort) InetAddress(java.net.InetAddress)

Example 7 with IPv4

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

the class EnableBfdResource method makeSessionConfigPayload.

private IPacket makeSessionConfigPayload(IOFSwitch sw, ISwitchManager switchManager, NoviBfdSession bfdSession) {
    final TransportPort udpPort = TransportPort.of(bfdSession.getUdpPortNumber());
    UDP l4 = new UDP().setSourcePort(udpPort).setDestinationPort(udpPort);
    InetAddress sourceIpAddress = switchManager.getSwitchIpAddress(sw);
    InetAddress destIpAddress = bfdSession.getRemote().getInetAddress();
    IPacket l3 = new IPv4().setSourceAddress(IPv4Address.of(sourceIpAddress.getAddress())).setDestinationAddress(IPv4Address.of(destIpAddress.getAddress())).setProtocol(IpProtocol.UDP).setPayload(l4);
    DatapathId remoteDatapath = DatapathId.of(bfdSession.getRemote().getDatapath().toLong());
    return new Ethernet().setEtherType(EthType.IPv4).setSourceMACAddress(convertDpIdToMac(sw.getId())).setDestinationMACAddress(convertDpIdToMac(remoteDatapath)).setPayload(l3);
}
Also used : UDP(net.floodlightcontroller.packet.UDP) IPacket(net.floodlightcontroller.packet.IPacket) IPv4(net.floodlightcontroller.packet.IPv4) Ethernet(net.floodlightcontroller.packet.Ethernet) DatapathId(org.projectfloodlight.openflow.types.DatapathId) TransportPort(org.projectfloodlight.openflow.types.TransportPort) InetAddress(java.net.InetAddress)

Example 8 with IPv4

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

the class PathVerificationPacketInTest method getPacket.

private Ethernet getPacket() {
    UDP udp = new UDP().setDestinationPort(TransportPort.of(PathVerificationService.DISCOVERY_PACKET_UDP_PORT)).setSourcePort(TransportPort.of(PathVerificationService.DISCOVERY_PACKET_UDP_PORT));
    List<LLDPTLV> optional = Lists.newArrayList(// switch t0
    new LLDPTLV().setType(OPTIONAL_LLDPTV_PACKET_TYPE).setLength((short) 12).setValue(Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { SWITCH_T0_OPTIONAL_TYPE }, SWITCH_T0)), // switch t1
    new LLDPTLV().setType(OPTIONAL_LLDPTV_PACKET_TYPE).setLength((short) 12).setValue(Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { SWITCH_T1_OPTIONAL_TYPE }, SWITCH_T1)), // dpid
    new LLDPTLV().setType(OPTIONAL_LLDPTV_PACKET_TYPE).setLength((short) 12).setValue(Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { REMOTE_SWITCH_OPTIONAL_TYPE }, REMOTE_SWITCH_ID)), // timestamp
    new LLDPTLV().setType(OPTIONAL_LLDPTV_PACKET_TYPE).setLength((short) 12).setValue(Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { TIMESTAMP_OPTIONAL_TYPE }, TIMESTAMP)), // path ordinal
    new LLDPTLV().setType(OPTIONAL_LLDPTV_PACKET_TYPE).setLength((short) 8).setValue(Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { PATH_ORDINAL_OPTIONAL_TYPE }, PATH_ORDINAL)));
    DiscoveryPacket discoveryPacket = DiscoveryPacket.builder().chassisId(new LLDPTLV().setType(CHASSIS_ID_LLDPTV_PACKET_TYPE).setLength((short) 7).setValue(new byte[] { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 })).portId(new LLDPTLV().setType(PORT_ID_LLDPTV_PACKET_TYPE).setLength((short) 3).setValue(new byte[] { 0x02, 0x00, 0x01 })).ttl(new LLDPTLV().setType(TTL_LLDPTV_PACKET_TYPE).setLength((short) 2).setValue(new byte[] { 0x00, 0x78 })).optionalTlvList(optional).build();
    udp.setPayload(new Data(discoveryPacket.serialize()));
    IPv4 ip = new IPv4().setSourceAddress("192.168.0.1").setDestinationAddress(PathVerificationService.DISCOVERY_PACKET_IP_DST).setProtocol(IpProtocol.UDP);
    Ethernet eth = new Ethernet().setDestinationMACAddress("AA:BB:CC:DD:EE:FF").setSourceMACAddress("11:22:33:44:55:66").setEtherType(EthType.IPv4);
    eth.setPayload(ip);
    ip.setPayload(udp);
    return eth;
}
Also used : UDP(net.floodlightcontroller.packet.UDP) IPv4(net.floodlightcontroller.packet.IPv4) Ethernet(net.floodlightcontroller.packet.Ethernet) Data(net.floodlightcontroller.packet.Data) LLDPTLV(net.floodlightcontroller.packet.LLDPTLV)

Example 9 with IPv4

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

the class PathVerificationService method generateDiscoveryPacket.

/**
 * Return Discovery packet.
 *
 * @param srcSw source switch.
 * @param port port.
 * @param sign sign.
 * @param packetId id of the packet.
 * @return discovery packet.
 */
OFPacketOut generateDiscoveryPacket(IOFSwitch srcSw, OFPort port, boolean sign, Long packetId) {
    try {
        byte[] dpidArray = new byte[8];
        ByteBuffer dpidBb = ByteBuffer.wrap(dpidArray);
        DatapathId dpid = srcSw.getId();
        dpidBb.putLong(dpid.getLong());
        byte[] chassisId = new byte[] { 4, 0, 0, 0, 0, 0, 0 };
        System.arraycopy(dpidArray, 2, chassisId, 1, 6);
        // Set the optionalTLV to the full SwitchID
        byte[] dpidTlvValue = Arrays.concatenate(ORGANIZATIONALLY_UNIQUE_IDENTIFIER, new byte[] { REMOTE_SWITCH_OPTIONAL_TYPE, 0, 0, 0, 0, 0, 0, 0, 0 });
        System.arraycopy(dpidArray, 0, dpidTlvValue, LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES, 8);
        // Set src mac to be able to detect the origin of the packet.
        // NB: previously we set port's address instead of switch (some switches declare unique address per port)
        byte[] srcMac = new byte[6];
        System.arraycopy(dpidArray, 2, srcMac, 0, 6);
        byte[] portId = new byte[] { 2, 0, 0 };
        ByteBuffer portBb = ByteBuffer.wrap(portId, 1, 2);
        portBb.putShort(port.getShortPortNumber());
        byte[] ttlValue = new byte[] { 0, 0x78 };
        DiscoveryPacket dp = DiscoveryPacket.builder().chassisId(makeIdLldptvPacket(chassisId, CHASSIS_ID_LLDPTV_PACKET_TYPE)).portId(makeIdLldptvPacket(portId, PORT_ID_LLDPTV_PACKET_TYPE)).ttl(makeIdLldptvPacket(ttlValue, TTL_LLDPTV_PACKET_TYPE)).build();
        // Add TLV for t0, this will be overwritten by the switch if it supports switch timestamps
        dp.getOptionalTlvList().add(switchTimestampTlv(SWITCH_T0_OPTIONAL_TYPE));
        // Add TLV for t1, this will be overwritten by the switch if it supports switch timestamps
        dp.getOptionalTlvList().add(switchTimestampTlv(SWITCH_T1_OPTIONAL_TYPE));
        LLDPTLV dpidTlv = makeIdLldptvPacket(dpidTlvValue, OPTIONAL_LLDPTV_PACKET_TYPE);
        dp.getOptionalTlvList().add(dpidTlv);
        // Add T0 based on format from Floodlight LLDP
        long time = System.currentTimeMillis();
        long swLatency = srcSw.getLatency().getValue();
        byte[] timestampTlvValue = ByteBuffer.allocate(Long.SIZE / 8 + LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES).put(ORGANIZATIONALLY_UNIQUE_IDENTIFIER).put(// 0x01 is what we'll use to differentiate DPID 0x00 from time 0x01
        TIMESTAMP_OPTIONAL_TYPE).putLong(time + swLatency).array();
        LLDPTLV timestampTlv = makeIdLldptvPacket(timestampTlvValue, OPTIONAL_LLDPTV_PACKET_TYPE);
        dp.getOptionalTlvList().add(timestampTlv);
        // Type
        byte[] typeTlvValue = ByteBuffer.allocate(Integer.SIZE / 8 + LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES).put(ORGANIZATIONALLY_UNIQUE_IDENTIFIER).put(PATH_ORDINAL_OPTIONAL_TYPE).putInt(PathType.ISL.ordinal()).array();
        LLDPTLV typeTlv = makeIdLldptvPacket(typeTlvValue, OPTIONAL_LLDPTV_PACKET_TYPE);
        dp.getOptionalTlvList().add(typeTlv);
        if (sign) {
            Builder builder = JWT.create().withClaim("dpid", dpid.getLong()).withClaim("ts", time + swLatency);
            if (packetId != null) {
                builder.withClaim("id", packetId);
            }
            String token = builder.sign(algorithm);
            byte[] tokenBytes = token.getBytes(Charset.forName("UTF-8"));
            byte[] tokenTlvValue = ByteBuffer.allocate(LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES + tokenBytes.length).put(ORGANIZATIONALLY_UNIQUE_IDENTIFIER).put(TOKEN_OPTIONAL_TYPE).put(tokenBytes).array();
            LLDPTLV tokenTlv = makeIdLldptvPacket(tokenTlvValue, OPTIONAL_LLDPTV_PACKET_TYPE);
            dp.getOptionalTlvList().add(tokenTlv);
        }
        MacAddress dstMac = MacAddress.of(config.getVerificationBcastPacketDst());
        IPv4Address dstIp = IPv4Address.of(DISCOVERY_PACKET_IP_DST);
        IPv4 l3 = new IPv4().setSourceAddress(IPv4Address.of(((InetSocketAddress) srcSw.getInetAddress()).getAddress().getAddress())).setDestinationAddress(dstIp).setTtl((byte) 64).setProtocol(IpProtocol.UDP);
        UDP l4 = new UDP();
        l4.setSourcePort(TransportPort.of(DISCOVERY_PACKET_UDP_PORT));
        l4.setDestinationPort(TransportPort.of(DISCOVERY_PACKET_UDP_PORT));
        Ethernet l2 = new Ethernet().setSourceMACAddress(MacAddress.of(srcMac)).setDestinationMACAddress(dstMac).setEtherType(EthType.IPv4);
        l2.setPayload(l3);
        l3.setPayload(l4);
        l4.setPayload(dp);
        byte[] data = l2.serialize();
        OFPacketOut.Builder pob = srcSw.getOFFactory().buildPacketOut().setBufferId(OFBufferId.NO_BUFFER).setActions(getDiscoveryActions(srcSw, port)).setData(data);
        OFMessageUtils.setInPort(pob, OFPort.CONTROLLER);
        return pob.build();
    } catch (Exception e) {
        logger.error(String.format("error generating discovery packet: %s", e.getMessage()), e);
    }
    return null;
}
Also used : UDP(net.floodlightcontroller.packet.UDP) InetSocketAddress(java.net.InetSocketAddress) Builder(com.auth0.jwt.JWTCreator.Builder) IPv4(net.floodlightcontroller.packet.IPv4) DatapathId(org.projectfloodlight.openflow.types.DatapathId) MacAddress(org.projectfloodlight.openflow.types.MacAddress) ByteBuffer(java.nio.ByteBuffer) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) FloodlightModuleException(net.floodlightcontroller.core.module.FloodlightModuleException) OFPortDescPropEthernet(org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet) Ethernet(net.floodlightcontroller.packet.Ethernet) LLDPTLV(net.floodlightcontroller.packet.LLDPTLV)

Example 10 with IPv4

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

the class PathVerificationCommonTests method testDiscoveryPacketHeadersSize.

@Test
public void testDiscoveryPacketHeadersSize() {
    OFPacketOut packet = pvs.generateDiscoveryPacket(sw, OFPort.of(1), true, null);
    Ethernet ethernet = (Ethernet) new Ethernet().deserialize(packet.getData(), 0, packet.getData().length);
    IPv4 ipv4 = (IPv4) ethernet.getPayload();
    UDP udp = (UDP) ipv4.getPayload();
    assertEquals(ETHERNET_HEADER_SIZE, (ethernet.serialize().length - ipv4.getTotalLength()) * 8);
    assertEquals(IP_V4_HEADER_SIZE, (ipv4.getTotalLength() - udp.getLength()) * 8);
    assertEquals(UDP_HEADER_SIZE, (udp.getLength() - udp.getPayload().serialize().length) * 8);
}
Also used : UDP(net.floodlightcontroller.packet.UDP) Ethernet(net.floodlightcontroller.packet.Ethernet) IPv4(net.floodlightcontroller.packet.IPv4) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) Test(org.junit.Test)

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