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.NetUtils;
18 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
21 * Abstract class which provides the utilities for converting
22 * the Openflow port number to the equivalent NodeConnector and vice versa
27 public abstract class PortConverter {
28 private static final int maxOFPhysicalPort =
29 NetUtils.getUnsignedShort(OFPort.OFPP_MAX.getValue());
32 * Converts the Openflow port number to the equivalent NodeConnector.
34 public static NodeConnector toNodeConnector(short ofPort, Node node) {
35 // Restore original OF unsigned 16 bits value for the comparison
36 int unsignedOFPort = NetUtils.getUnsignedShort(ofPort);
38 if (unsignedOFPort > maxOFPhysicalPort) {
39 if (ofPort == OFPort.OFPP_LOCAL.getValue()) {
40 return NodeConnectorCreator.createNodeConnector(
41 NodeConnectorIDType.SWSTACK,
42 NodeConnector.SPECIALNODECONNECTORID, node);
43 } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) {
44 return NodeConnectorCreator.createNodeConnector(
45 NodeConnectorIDType.HWPATH,
46 NodeConnector.SPECIALNODECONNECTORID, node);
47 } else if (ofPort == OFPort.OFPP_CONTROLLER.getValue()) {
48 return NodeConnectorCreator.createNodeConnector(
49 NodeConnectorIDType.CONTROLLER,
50 NodeConnector.SPECIALNODECONNECTORID, node);
53 return NodeConnectorCreator.createNodeConnector(ofPort, node);
57 * Converts the NodeConnector to the equivalent Openflow port number
59 public static short toOFPort(NodeConnector salPort) {
60 if (salPort.getType().equals(NodeConnectorIDType.SWSTACK)) {
61 return OFPort.OFPP_LOCAL.getValue();
62 } else if (salPort.getType().equals(
63 NodeConnectorIDType.HWPATH)) {
64 return OFPort.OFPP_NORMAL.getValue();
65 } else if (salPort.getType().equals(
66 NodeConnectorIDType.CONTROLLER)) {
67 return OFPort.OFPP_CONTROLLER.getValue();
69 return (Short) salPort.getID();