use of org.opendaylight.openflowplugin.libraries.liblldp.PacketException in project netvirt by opendaylight.
the class NaptEventHandler method buildNaptPacketOut.
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
protected byte[] buildNaptPacketOut(Ethernet etherPkt) {
LOG.debug("removeNatFlows : About to build Napt Packet Out");
if (etherPkt.getPayload() instanceof IPv4) {
byte[] rawPkt;
IPv4 ipPkt = (IPv4) etherPkt.getPayload();
if (ipPkt.getPayload() instanceof TCP || ipPkt.getPayload() instanceof UDP) {
try {
rawPkt = etherPkt.serialize();
return rawPkt;
} catch (PacketException e2) {
LOG.error("failed to build NAPT Packet out ", e2);
return null;
}
} else {
LOG.error("removeNatFlows : Unable to build NaptPacketOut since its neither TCP nor UDP");
return null;
}
}
LOG.error("removeNatFlows : Unable to build NaptPacketOut since its not IPv4 packet");
return null;
}
use of org.opendaylight.openflowplugin.libraries.liblldp.PacketException in project openflowplugin by opendaylight.
the class LLDPSpeaker method nodeConnectorAdded.
@Override
public void nodeConnectorAdded(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId, final FlowCapableNodeConnector flowConnector) {
NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(nodeConnectorInstanceId).getId();
// port, so first we check if we actually need to perform any action
if (nodeConnectorMap.containsKey(nodeConnectorInstanceId)) {
LOG.debug("Port {} already in LLDPSpeaker.nodeConnectorMap, no need for additional processing", nodeConnectorId.getValue());
return;
}
// Prepare to build LLDP payload
InstanceIdentifier<Node> nodeInstanceId = nodeConnectorInstanceId.firstIdentifierOf(Node.class);
NodeId nodeId = InstanceIdentifier.keyOf(nodeInstanceId).getId();
MacAddress srcMacAddress = flowConnector.getHardwareAddress();
Long outputPortNo = flowConnector.getPortNumber().getUint32();
// No need to send LLDP frames on local ports
if (outputPortNo == null) {
LOG.debug("Port {} is local, not sending LLDP frames through it", nodeConnectorId.getValue());
return;
}
// Generate packet with destination switch and port
TransmitPacketInput packet;
try {
packet = new TransmitPacketInputBuilder().setEgress(new NodeConnectorRef(nodeConnectorInstanceId)).setNode(new NodeRef(nodeInstanceId)).setPayload(LLDPUtil.buildLldpFrame(nodeId, nodeConnectorId, srcMacAddress, outputPortNo, addressDestionation)).build();
} catch (NoSuchAlgorithmException | PacketException e) {
LOG.error("Error building LLDP frame", e);
return;
}
// Save packet to node connector id -> packet map to transmit it periodically on the configured interval.
nodeConnectorMap.put(nodeConnectorInstanceId, packet);
LOG.debug("Port {} added to LLDPSpeaker.nodeConnectorMap", nodeConnectorId.getValue());
// Transmit packet for first time immediately
final Future<RpcResult<Void>> resultFuture = packetProcessingService.transmitPacket(packet);
JdkFutures.addErrorLogging(resultFuture, LOG, "transmitPacket");
}
use of org.opendaylight.openflowplugin.libraries.liblldp.PacketException in project genius by opendaylight.
the class IPv4 method postSerializeCustomOperation.
@Override
protected /**
* Method to perform post serialization - like computation of checksum of serialized header
* @param data
* @return void
* @Exception throws PacketException
*/
void postSerializeCustomOperation(byte[] data) throws PacketException {
// Recompute the total length field here
byte[] totalLength = BitBufferHelper.toByteArray((short) data.length);
try {
BitBufferHelper.setBytes(data, totalLength, getfieldOffset(TOTLENGTH), getfieldnumBits(TOTLENGTH));
} catch (BufferException e) {
throw new PacketException(e.getMessage(), e);
}
// Now compute the Header Checksum
byte[] checkSum = BitBufferHelper.toByteArray(computeChecksum(data, 0));
try {
BitBufferHelper.setBytes(data, checkSum, getfieldOffset(CHECKSUM), getfieldnumBits(CHECKSUM));
} catch (BufferException e) {
throw new PacketException(e.getMessage(), e);
}
}
Aggregations