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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations