3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
12 import org.openflow.protocol.OFPort;
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.core.NodeConnector;
16 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
17 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
20 * Abstract class which provides the utilities for converting
21 * the Openflow port number to the equivalent NodeConnector and vice versa
26 public abstract class PortConverter {
27 private static final int maxOFPhysicalPort = (OFPort.OFPP_MAX.getValue() & 0x7FFF) | 0x8000;
30 * Converts the Openflow port number to the equivalent NodeConnector.
32 public static NodeConnector toNodeConnector(short ofPort, Node node) {
33 // Restore original OF unsigned 16 bits value for the comparison
34 int unsignedOFPort = (ofPort & 0x7FFF) | 0x8000;
36 if (unsignedOFPort > maxOFPhysicalPort) {
37 if (ofPort == OFPort.OFPP_LOCAL.getValue()) {
38 return NodeConnectorCreator.createNodeConnector(
39 NodeConnectorIDType.SWSTACK,
40 NodeConnector.SPECIALNODECONNECTORID, node);
41 } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) {
42 return NodeConnectorCreator.createNodeConnector(
43 NodeConnectorIDType.HWPATH,
44 NodeConnector.SPECIALNODECONNECTORID, node);
45 } else if (ofPort == OFPort.OFPP_CONTROLLER.getValue()) {
46 return NodeConnectorCreator.createNodeConnector(
47 NodeConnectorIDType.CONTROLLER,
48 NodeConnector.SPECIALNODECONNECTORID, node);
51 return NodeConnectorCreator.createNodeConnector(ofPort, node);
55 * Converts the NodeConnector to the equivalent Openflow port number
57 public static short toOFPort(NodeConnector salPort) {
58 if (salPort.getType().equals(NodeConnectorIDType.SWSTACK)) {
59 return OFPort.OFPP_LOCAL.getValue();
60 } else if (salPort.getType().equals(
61 NodeConnectorIDType.HWPATH)) {
62 return OFPort.OFPP_NORMAL.getValue();
63 } else if (salPort.getType().equals(
64 NodeConnectorIDType.CONTROLLER)) {
65 return OFPort.OFPP_CONTROLLER.getValue();
67 return (Short) salPort.getID();