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.sal.utils;
12 import java.util.HashSet;
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;
24 * The class provides helper functions to create a node connector
28 public abstract class NodeConnectorCreator {
29 protected static final Logger logger = LoggerFactory
30 .getLogger(NodeConnectorCreator.class);
32 * Generic NodeConnector creator
33 * The nodeConnector type is inferred from the node type
39 public static NodeConnector createNodeConnector(Object portId, Node node) {
40 if (node.getType().equals(NodeIDType.OPENFLOW)) {
42 return new NodeConnector(NodeConnectorIDType.OPENFLOW,
44 } catch (ConstructionException e1) {
53 * Generic NodeConnector creator
54 * The nodeConnector type is inferred from the node type
56 * @param portId The string representing the port id
57 * @param node The network node as {@link org.opendaylight.controller.sal.core.Node Node} object
58 * @return The corresponding {@link org.opendaylight.controller.sal.core.NodeConnector NodeConnector} object
60 public static NodeConnector createNodeConnector(String portId, Node node) {
61 return NodeConnector.fromString(String.format("%s|%s@%s", node.getType(), portId, node.toString()));
65 * NodeConnector creator where NodeConnector type can be specified
66 * Needed to create special internal node connectors (like software stack)
68 * @param nodeConnectorType
73 public static NodeConnector createNodeConnector(
74 String nodeConnectorType, Object portId, Node node) {
76 if (nodeConnectorType.equals(Node.NodeIDType.OPENFLOW) && (portId.getClass() == String.class)) {
77 return new NodeConnector(nodeConnectorType, Short.parseShort((String) portId), node);
79 return new NodeConnector(nodeConnectorType, portId, node);
81 } catch (ConstructionException e1) {
87 public static NodeConnector createOFNodeConnector(Short portId, Node node) {
89 return new NodeConnector(NodeConnectorIDType.OPENFLOW, portId, node);
90 } catch (ConstructionException e1) {
96 public static Set<NodeConnector> createOFNodeConnectorSet(
97 Set<Short> portIds, Node n) {
99 Set<NodeConnector> nodeConnectors = new HashSet<NodeConnector>();
100 for (Short ofPortID : portIds) {
101 NodeConnector p = new NodeConnector(
102 NodeConnector.NodeConnectorIDType.OPENFLOW, Short
103 .valueOf(ofPortID), n);
104 nodeConnectors.add(p);
106 return nodeConnectors;
107 } catch (ConstructionException e1) {