2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.learningswitch.multi;
11 import java.util.HashMap;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 public class PacketInDispatcherImpl implements PacketProcessingListener {
20 private Map<InstanceIdentifier<Node>, PacketProcessingListener> handlerMapping;
25 public PacketInDispatcherImpl() {
26 handlerMapping = new HashMap<>();
30 public void onPacketReceived(PacketReceived notification) {
31 // find corresponding handler
33 * Notification contains reference to ingress port
34 * in a form of path in inventory: /nodes/node/node-connector
36 * In order to get path we shorten path to the first node reference
37 * by using firstIdentifierOf helper method provided by InstanceIdentifier,
38 * this will effectively shorten the path to /nodes/node.
40 InstanceIdentifier<?> ingressPort = notification.getIngress().getValue();
41 InstanceIdentifier<Node> nodeOfPacket = ingressPort.firstIdentifierOf(Node.class);
43 * We lookup up the the packet-in listener for this node.
45 PacketProcessingListener nodeHandler = handlerMapping.get(nodeOfPacket);
48 * If we have packet-processing listener, we delegate notification.
50 if (nodeHandler != null) {
51 nodeHandler.onPacketReceived(notification);
56 * @return the handlerMapping
58 public Map<InstanceIdentifier<Node>, PacketProcessingListener> getHandlerMapping() {
59 return handlerMapping;