Search in sources :

Example 11 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class PacketReceivedTranslator method translate.

@Override
public PacketReceived translate(final PacketInMessage input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
    PacketReceivedBuilder packetReceivedBuilder = new PacketReceivedBuilder();
    BigInteger datapathId = deviceInfo.getDatapathId();
    // TODO: connection cookie from connection distinguisher
    packetReceivedBuilder.setPayload(input.getData());
    // get the Cookie if it exists
    if (input.getCookie() != null) {
        packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
    }
    // Try to create the NodeConnectorRef
    BigInteger dataPathId = deviceInfo.getDatapathId();
    NodeConnectorRef nodeConnectorRef = NodeConnectorRefToPortTranslator.toNodeConnectorRef(input, dataPathId);
    // If we was able to create NodeConnectorRef, use it
    if (nodeConnectorRef != null) {
        packetReceivedBuilder.setIngress(nodeConnectorRef);
    }
    packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
    if (input.getTableId() != null) {
        packetReceivedBuilder.setTableId(new TableId(input.getTableId().getValue().shortValue()));
    }
    if (input.getMatch() != null) {
        org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
        packetReceivedBuilder.setMatch(packetInMatch);
    }
    return packetReceivedBuilder.build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) BigInteger(java.math.BigInteger) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder)

Example 12 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class PacketInDispatcherImpl method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    // find corresponding handler
    /*
         * Notification contains reference to ingress port
         * in a form of path in inventory: /nodes/node/node-connector
         *
         * In order to get path we shorten path to the first node reference
         * by using firstIdentifierOf helper method provided by InstanceIdentifier,
         * this will effectively shorten the path to /nodes/node.
         */
    InstanceIdentifier<?> ingressPort = notification.getIngress().getValue();
    InstanceIdentifier<Node> nodeOfPacket = ingressPort.firstIdentifierOf(Node.class);
    /**
     * We lookup up the the packet-in listener for this node.
     */
    PacketProcessingListener nodeHandler = handlerMapping.get(nodeOfPacket);
    /**
     * If we have packet-processing listener, we delegate notification.
     */
    if (nodeHandler != null) {
        nodeHandler.onPacketReceived(notification);
    }
}
Also used : Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener)

Example 13 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class AbstractDropTest method processPacket.

@SuppressWarnings("checkstyle:IllegalCatch")
private void processPacket(final PacketReceived notification) {
    try {
        final byte[] rawPacket = notification.getPayload();
        final byte[] srcMac = Arrays.copyOfRange(rawPacket, 6, 12);
        final MatchBuilder match = new MatchBuilder();
        final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
        final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
        // TODO: use HEX, use binary form
        // Hex.decodeHex("000000000001".toCharArray());
        ethSourceBuilder.setAddress(new MacAddress(macAddressToString(srcMac)));
        ethernetMatch.setEthernetSource(ethSourceBuilder.build());
        match.setEthernetMatch(ethernetMatch.build());
        // Get the Ingress nodeConnectorRef
        final NodeConnectorRef ncr = notification.getIngress();
        // Get the instance identifier for the nodeConnectorRef
        final InstanceIdentifier<?> ncri = ncr.getValue();
        processPacket(ncri.firstIdentifierOf(Node.class), match.build(), DROP_INSTRUCTIONS);
        SENT_UPDATER.incrementAndGet(this);
    } catch (RuntimeException e) {
        LOG.warn("Failed to process packet: {}", e.getMessage());
        LOG.debug("Failed to process packet.. ", e);
        EXCS_UPDATER.incrementAndGet(this);
    }
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) EthernetSourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)

Example 14 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class LearningSwitchHandlerSimpleImpl method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    if (!isLearning) {
        // ignoring packets - this should not happen
        return;
    }
    LOG.debug("Received packet via match: {}", notification.getMatch());
    // detect and compare node - we support one switch
    if (!nodePath.contains(notification.getIngress().getValue())) {
        return;
    }
    // read src MAC and dst MAC
    byte[] dstMacRaw = PacketUtils.extractDstMac(notification.getPayload());
    byte[] srcMacRaw = PacketUtils.extractSrcMac(notification.getPayload());
    byte[] etherType = PacketUtils.extractEtherType(notification.getPayload());
    MacAddress dstMac = PacketUtils.rawMacToMac(dstMacRaw);
    MacAddress srcMac = PacketUtils.rawMacToMac(srcMacRaw);
    NodeConnectorKey ingressKey = InstanceIdentifierUtils.getNodeConnectorKey(notification.getIngress().getValue());
    LOG.debug("Received packet from MAC match: {}, ingress: {}", srcMac, ingressKey.getId());
    LOG.debug("Received packet to   MAC match: {}", dstMac);
    LOG.debug("Ethertype: {}", Integer.toHexString(0x0000ffff & ByteBuffer.wrap(etherType).getShort()));
    // learn by IPv4 traffic only
    if (Arrays.equals(ETH_TYPE_IPV4, etherType)) {
        NodeConnectorRef previousPort = mac2portMapping.put(srcMac, notification.getIngress());
        if (previousPort != null && !notification.getIngress().equals(previousPort)) {
            NodeConnectorKey previousPortKey = InstanceIdentifierUtils.getNodeConnectorKey(previousPort.getValue());
            LOG.debug("mac2port mapping changed by mac {}: {} -> {}", srcMac, previousPortKey, ingressKey.getId());
        }
        // if dst MAC mapped:
        NodeConnectorRef destNodeConnector = mac2portMapping.get(dstMac);
        if (destNodeConnector != null) {
            synchronized (coveredMacPaths) {
                if (!destNodeConnector.equals(notification.getIngress())) {
                    // add flow
                    addBridgeFlow(srcMac, dstMac, destNodeConnector);
                    addBridgeFlow(dstMac, srcMac, notification.getIngress());
                } else {
                    LOG.debug("useless rule ignoring - both MACs are behind the same port");
                }
            }
            LOG.debug("packetIn-directing.. to {}", InstanceIdentifierUtils.getNodeConnectorKey(destNodeConnector.getValue()).getId());
            sendPacketOut(notification.getPayload(), notification.getIngress(), destNodeConnector);
        } else {
            // flood
            LOG.debug("packetIn-still flooding.. ");
            flood(notification.getPayload(), notification.getIngress());
        }
    } else {
        // non IPv4 package
        flood(notification.getPayload(), notification.getIngress());
    }
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Example 15 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project genius by opendaylight.

the class ArpUtilTestUtil method createPayload.

public static PacketReceived createPayload(int oc) {
    final short ID = 2;
    byte[] payload = bytePayload(// Destination MAC
    "1F 1F 1F 1F 1F 1F", // Source MAC
    "00 01 02 03 04 05", // Ethernet type
    "08 06", // Hardware type
    "0 1", // Protocol type
    "8 0", // Hardware size
    "6", // Protocol size
    "4", // Opcode
    OP_CODE[oc], // Sender MAC Address
    "00 01 02 03 04 05", // Sender IP Address
    "C0 A8 0 2", // Target MAC Address
    "00 01 02 03 04 05", // Target IP Address
    "C0 A8 0 2");
    return new PacketReceivedBuilder().setPacketInReason(SendToController.class).setTableId(new TableId(ID)).setPayload(payload).setIngress(new NodeConnectorRef(InstanceIdentifier.create(Node.class))).setMatch(new MatchBuilder().setMetadata(new MetadataBuilder().setMetadata(META_DATA).build()).build()).build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) SendToController(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController) MetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder)

Aggregations

BigInteger (java.math.BigInteger)5 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)5 PacketReceived (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)5 Ethernet (org.opendaylight.genius.mdsalutil.packet.Ethernet)4 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)4 PacketReceivedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder)4 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 UnknownHostException (java.net.UnknownHostException)2 InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)2 Packet (org.opendaylight.openflowplugin.libraries.liblldp.Packet)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)2 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)2 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)2 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)2 Optional (com.google.common.base.Optional)1