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.containermanager;
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Locale;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentMap;
22 import org.opendaylight.controller.sal.core.ContainerFlow;
23 import org.opendaylight.controller.sal.core.Node;
24 import org.opendaylight.controller.sal.core.NodeConnector;
28 * This Class contains all the configurations pertained to this container
31 public class ContainerData implements Serializable {
32 private static final long serialVersionUID = 1L;
33 private String containerAdminRole;
34 private String containerOperatorRole;
36 private ConcurrentMap<Node, Set<NodeConnector>> swPorts;
37 private short staticVlan;
38 private List<ContainerFlow> cFlowList;
41 * Build a ContainerData from container configuration
43 * @param conf configuration from where the ContainerData need to be extracted
45 * @return the constructed containerData
47 public ContainerData(ContainerConfig conf) {
49 * Back-end Non-Configuration Classes store names in lower case
51 name = conf.getContainerName().toLowerCase(Locale.ENGLISH);
52 swPorts = new ConcurrentHashMap<Node, Set<NodeConnector>>();
53 cFlowList = new ArrayList<ContainerFlow>();
54 staticVlan = conf.getStaticVlanValue();
55 containerAdminRole = conf.getContainerAdminRole();
56 containerOperatorRole = conf.getContainerOperatorRole();
60 * getter for containerName
63 * @return the container name
65 public String getContainerName() {
70 * getter for static vlan
73 * @return attribute static vlan
75 public short getStaticVlan() {
80 * Check if the static vlan has non-zero value in that case is
81 * assumed to be assigned
84 * @return true if static vlan non-zero
86 public boolean hasStaticVlanAssigned() {
87 return (staticVlan != 0);
91 * retrieve all NodeConnectors on a given switch on the containerName
94 * @param switchId the Node for switch we want to retrieve the list of ports
96 * @return get all the ports in form of a set of nodeconnectors
98 public Set<NodeConnector> getPorts(Node switchId) {
99 Set<NodeConnector> swpinfo = swPorts.get(switchId);
100 if (swpinfo != null) {
107 * Returns the DB of all the association Node -> List of
108 * NodeConnectors composing this container
110 * @return the ConcurrentMap of all the association Node -> List
113 public ConcurrentMap<Node, Set<NodeConnector>> getSwPorts() {
118 * Add to the container a NodeConnector, that implicitely means also
119 * the Node being added
121 * @param port NodeConnector corresponding to the port being added
124 public void addPortToSwitch(NodeConnector port) {
125 Node switchId = port.getNode();
126 if (switchId == null) {
129 Set<NodeConnector> portSet = swPorts.get(switchId);
130 if (portSet == null) {
131 portSet = new HashSet<NodeConnector>();
132 swPorts.put(switchId, portSet);
138 * Remove from the container a NodeConnector, that implicitely means also
139 * the Node being removed
141 * @param port NodeConnector corresponding to the port being removed
144 public void removePortFromSwitch(NodeConnector port) {
145 Node switchId = port.getNode();
146 if (switchId == null) {
149 Set<NodeConnector> swpinfo = swPorts.get(switchId);
150 if (swpinfo != null) {
151 swpinfo.remove(port);
152 if (swpinfo.isEmpty()) {
153 // There are no more ports lets get ride of the switch
154 swPorts.remove(switchId);
160 * Existence check of a Node in a container
162 * @param switchId See if a particular node is part of the container
164 * @return true if the node is in it else false
166 public boolean isSwitchInContainer(Node switchId) {
167 if (swPorts.containsKey(switchId)) {
175 * Test for existance of NodeConnectors on a Node in a container
177 * @param switchId Node we are testing for port existance
179 * @return ture if the portset is non-empty
181 public boolean portListEmpty(Node switchId) {
182 Set<NodeConnector> swpinfo = swPorts.get(switchId);
183 if (swpinfo != null) {
184 if (!swpinfo.isEmpty()) {
191 public void deleteFlowSpec(ContainerFlow cFlow) {
192 cFlowList.remove(cFlow);
195 public void addFlowSpec(ContainerFlow cFlow) {
196 cFlowList.add(cFlow);
199 public boolean isFlowSpecEmpty() {
200 return (cFlowList.isEmpty());
204 public boolean containsFlowSpec(ContainerFlow cFlow) {
205 return cFlowList.contains(cFlow);
208 public int getFlowSpecCount() {
209 return cFlowList.size();
212 public List<ContainerFlow> getContainerFlowSpecs() {
216 public boolean matchName(String name) {
217 return this.name.equalsIgnoreCase(name);
221 * Returns all the node connectors part of the container
222 * @return The node connectors belonging to this container. The returning set is never null.
224 public Set<NodeConnector> getNodeConnectors() {
225 Set<NodeConnector> set = new HashSet<NodeConnector>();
226 for (Map.Entry<Node, Set<NodeConnector>> entry : swPorts.entrySet()) {
227 set.addAll(entry.getValue());
232 public String getContainerAdminRole() {
233 return containerAdminRole;
236 public String getContainerOperatorRole() {
237 return containerOperatorRole;