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;
35 private ConcurrentMap<Node, Set<NodeConnector>> swPorts;
36 private short staticVlan;
37 private List<ContainerFlow> cFlowList;
43 * @return constructed ContainerData
45 public ContainerData() {
47 swPorts = new ConcurrentHashMap<Node, Set<NodeConnector>>();
49 cFlowList = new ArrayList<ContainerFlow>();
53 * Build a ContainerData from container configuration
55 * @param conf configuration from where the ContainerData need to be extracted
57 * @return the constructed containerData
59 public ContainerData(ContainerConfig conf) {
61 * Back-end Non-Configuration Classes store names in lower case
63 name = conf.getContainerName().toLowerCase(Locale.ENGLISH);
64 swPorts = new ConcurrentHashMap<Node, Set<NodeConnector>>();
65 cFlowList = new ArrayList<ContainerFlow>();
66 staticVlan = conf.getStaticVlanValue();
70 * getter for containerName
73 * @return the container name
75 public String getContainerName() {
80 * getter for static vlan
83 * @return attribute static vlan
85 public short getStaticVlan() {
90 * Check if the static vlan has non-zero value in that case is
91 * assumed to be assigned
94 * @return true if static vlan non-zero
96 public boolean hasStaticVlanAssigned() {
97 return (staticVlan != 0);
101 * retrieve all NodeConnectors on a given switch on the containerName
102 * used in this object
104 * @param switchId the Node for switch we want to retrieve the list of ports
106 * @return get all the ports in form of a set of nodeconnectors
108 public Set<NodeConnector> getPorts(Node switchId) {
109 Set<NodeConnector> swpinfo = swPorts.get(switchId);
110 if (swpinfo != null) {
117 * Returns the DB of all the association Node -> List of
118 * NodeConnectors composing this container
120 * @return the ConcurrentMap of all the association Node -> List
123 public ConcurrentMap<Node, Set<NodeConnector>> getSwPorts() {
128 * Add to the container a NodeConnector, that implicitely means also
129 * the Node being added
131 * @param port NodeConnector corresponding to the port being added
134 public void addPortToSwitch(NodeConnector port) {
135 Node switchId = port.getNode();
136 if (switchId == null) {
139 Set<NodeConnector> portSet = swPorts.get(switchId);
140 if (portSet == null) {
141 portSet = new HashSet<NodeConnector>();
142 swPorts.put(switchId, portSet);
148 * Remove from the container a NodeConnector, that implicitely means also
149 * the Node being removed
151 * @param port NodeConnector corresponding to the port being removed
154 public void removePortFromSwitch(NodeConnector port) {
155 Node switchId = port.getNode();
156 if (switchId == null) {
159 Set<NodeConnector> swpinfo = swPorts.get(switchId);
160 if (swpinfo != null) {
161 swpinfo.remove(port);
162 if (swpinfo.isEmpty()) {
163 // There are no more ports lets get ride of the switch
164 swPorts.remove(switchId);
170 * Existence check of a Node in a container
172 * @param switchId See if a particular node is part of the container
174 * @return true if the node is in it else false
176 public boolean isSwitchInContainer(Node switchId) {
177 if (swPorts.containsKey(switchId)) {
185 * Test for existance of NodeConnectors on a Node in a container
187 * @param switchId Node we are testing for port existance
189 * @return ture if the portset is non-empty
191 public boolean portListEmpty(Node switchId) {
192 Set<NodeConnector> swpinfo = swPorts.get(switchId);
193 if (swpinfo != null) {
194 if (!swpinfo.isEmpty()) {
201 public void deleteFlowSpec(ContainerFlow cFlow) {
202 cFlowList.remove(cFlow);
205 public void addFlowSpec(ContainerFlow cFlow) {
206 cFlowList.add(cFlow);
209 public boolean isFlowSpecEmpty() {
210 return (cFlowList.isEmpty());
214 public boolean containsFlowSpec(ContainerFlow cFlow) {
215 return cFlowList.contains(cFlow);
218 public int getFlowSpecCount() {
219 return cFlowList.size();
222 public List<ContainerFlow> getContainerFlowSpecs() {
226 public boolean matchName(String name) {
227 return this.name.equalsIgnoreCase(name);
231 * Returns all the node connectors part of the container
232 * @return The node connectors belonging to this container. The returning set is never null.
234 public Set<NodeConnector> getNodeConnectors() {
235 Set<NodeConnector> set = new HashSet<NodeConnector>();
236 for (Map.Entry<Node, Set<NodeConnector>> entry : swPorts.entrySet()) {
237 set.addAll(entry.getValue());