Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / NodeConnectorCreator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.utils;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import org.opendaylight.controller.sal.core.ConstructionException;
16 import org.opendaylight.controller.sal.core.Node;
17 import org.opendaylight.controller.sal.core.NodeConnector;
18 import org.opendaylight.controller.sal.core.Node.NodeIDType;
19 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * The class provides helper functions to create a node connector
25  *
26  *
27  */
28 @Deprecated
29 public abstract class NodeConnectorCreator {
30     protected static final Logger logger = LoggerFactory
31     .getLogger(NodeConnectorCreator.class);
32     /**
33      * Generic NodeConnector creator
34      * The nodeConnector type is inferred from the node type
35      *
36      * @param portId
37      * @param node
38      * @return
39      */
40     public static NodeConnector createNodeConnector(Object portId, Node node) {
41         if (node.getType().equals(NodeIDType.OPENFLOW)) {
42             try {
43                 return new NodeConnector(NodeConnectorIDType.OPENFLOW,
44                         portId, node);
45             } catch (ConstructionException e1) {
46                 logger.error("",e1);
47                 return null;
48             }
49         }
50         return null;
51     }
52
53     /**
54      * Generic NodeConnector creator
55      * The nodeConnector type is inferred from the node type
56      *
57      * @param portId The string representing the port id
58      * @param node The network node as {@link org.opendaylight.controller.sal.core.Node Node} object
59      * @return The corresponding {@link org.opendaylight.controller.sal.core.NodeConnector NodeConnector} object
60      */
61     public static NodeConnector createNodeConnector(String portId, Node node) {
62         return NodeConnector.fromString(String.format("%s|%s@%s", node.getType(), portId, node.toString()));
63     }
64
65     /**
66      * NodeConnector creator where NodeConnector type can be specified
67      * Needed to create special internal node connectors (like software stack)
68      *
69      * @param nodeConnectorType
70      * @param portId
71      * @param node
72      * @return
73      */
74     public static NodeConnector createNodeConnector(
75             String nodeConnectorType, Object portId, Node node) {
76         try {
77             if (nodeConnectorType.equals(Node.NodeIDType.OPENFLOW) && (portId.getClass() == String.class)) {
78                 return new NodeConnector(nodeConnectorType, Short.parseShort((String) portId), node);
79             } else {
80                 return new NodeConnector(nodeConnectorType, portId, node);
81             }
82         } catch (ConstructionException e1) {
83             logger.error("",e1);
84             return null;
85         }
86     }
87
88     public static NodeConnector createOFNodeConnector(Short portId, Node node) {
89         try {
90             return new NodeConnector(NodeConnectorIDType.OPENFLOW, portId, node);
91         } catch (ConstructionException e1) {
92             logger.error("",e1);
93             return null;
94         }
95     }
96
97     public static Set<NodeConnector> createOFNodeConnectorSet(
98             Set<Short> portIds, Node n) {
99         try {
100             Set<NodeConnector> nodeConnectors = new HashSet<NodeConnector>();
101             for (Short ofPortID : portIds) {
102                 NodeConnector p = new NodeConnector(
103                         NodeConnector.NodeConnectorIDType.OPENFLOW, Short
104                                 .valueOf(ofPortID), n);
105                 nodeConnectors.add(p);
106             }
107             return nodeConnectors;
108         } catch (ConstructionException e1) {
109             logger.error("",e1);
110             return null;
111         }
112     }
113 }