Search in sources :

Example 16 with PacketException

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;
}
Also used : TCP(org.opendaylight.genius.mdsalutil.packet.TCP) UDP(org.opendaylight.genius.mdsalutil.packet.UDP) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with PacketException

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");
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)

Example 18 with PacketException

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);
    }
}
Also used : BufferException(org.opendaylight.openflowplugin.libraries.liblldp.BufferException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException)

Aggregations

PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)18 Ethernet (org.opendaylight.genius.mdsalutil.packet.Ethernet)10 BigInteger (java.math.BigInteger)6 ExecutionException (java.util.concurrent.ExecutionException)5 UnknownHostException (java.net.UnknownHostException)4 IPv4 (org.opendaylight.genius.mdsalutil.packet.IPv4)4 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)4 InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)3 UDP (org.opendaylight.genius.mdsalutil.packet.UDP)3 BufferException (org.opendaylight.openflowplugin.libraries.liblldp.BufferException)3 Packet (org.opendaylight.openflowplugin.libraries.liblldp.Packet)3 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 InetAddress (java.net.InetAddress)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)2 ARP (org.opendaylight.genius.mdsalutil.packet.ARP)2 DHCP (org.opendaylight.netvirt.dhcpservice.api.DHCP)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)2