@Override public String getContainerAdminRole() { return iContainerInternal.getContainerData(containerName).getContainerAdminRole(); }
public List<String> psd() { List<String> result = new ArrayList<String>(); for (String containerName : containerData.keySet()) { ContainerData sd = containerData.get(containerName); for (Node sid : sd.getSwPorts().keySet()) { Set<NodeConnector> s = sd.getSwPorts().get(sid); result.add("\t" + sid + " : " + s); } for (ContainerFlow s : sd.getContainerFlowSpecs()) { result.add("\t" + s.toString()); } } return result; }
private void removeNodeToContainersMapping(ContainerData container) { for (Entry<Node, Set<String>> entry : nodeToContainers.entrySet()) { Node node = entry.getKey(); for (String sdata : entry.getValue()) { if (sdata.equals(container.getContainerName())) { logger.debug("Removing Node->Containers mapping, node {} container {}", node, sdata); Set<String> value = nodeToContainers.get(node); value.remove(sdata); nodeToContainers.put(node, value); break; } } } }
Node node = port.getNode(); if (delete) { container.removePortFromSwitch(port); putContainerDataByName(containerName, container); if (container.portListEmpty(node)) { logger.debug("Port List empty for switch {}", node); putContainerDataByName(containerName, container); if (slist != null) { logger.debug("Removing container from switch-container list. node{}, container{}", node, containerName); slist.remove(container.getContainerName()); nodeToContainers.put(node, slist); if (slist.isEmpty()) { if (container.isSwitchInContainer(node) == false) { Set<String> value = nodeToContainers.get(node); logger.debug("Creating new Container Set for switch {}", node); value.add(container.getContainerName()); nodeToContainers.put(node, value); container.addPortToSwitch(port); putContainerDataByName(containerName, container); slist.add(container.getContainerName()); nodeConnectorToContainers.put(port, slist);
Set<NodeConnector> thisContainerPorts = container.getNodeConnectors(); Set<NodeConnector> commonPorts = entry.getValue().getNodeConnectors(); commonPorts.retainAll(thisContainerPorts); if (commonPorts.isEmpty()) { if (container.getFlowSpecCount() == 1) { if (!container.hasStaticVlanAssigned()) { Set<NodeConnector> thisContainerPorts = container.getNodeConnectors(); List<ContainerFlow> proposed = new ArrayList<ContainerFlow>(container.getContainerFlowSpecs()); proposed.add(cFlow); for (Map.Entry<String, ContainerData> entry : containerData.entrySet()) { Set<NodeConnector> commonPorts = otherContainer.getNodeConnectors(); commonPorts.retainAll(thisContainerPorts); Status status = checkCommonContainerFlow(otherContainer.getContainerFlowSpecs(), proposed); if (!status.isSuccess()) { return new Status(StatusCode.BADREQUEST, String.format(
private Status validatePortSharingInternal(List<NodeConnector> portList, List<ContainerFlow> flowSpecList) { for (NodeConnector port : portList) { List<String> slist = nodeConnectorToContainers.get(port); if (slist != null && !slist.isEmpty()) { for (String otherContainerName : slist) { String msg = null; ContainerData other = containerData.get(otherContainerName); if (flowSpecList.isEmpty()) { msg = String.format("Port %s is shared and flow spec is empty for this container", port); } else if (other.isFlowSpecEmpty()) { msg = String.format("Port %s is shared and flow spec is empty for the other container", port); } else if (!checkCommonContainerFlow(flowSpecList, other.getContainerFlowSpecs()).isSuccess()) { msg = String.format("Port %s is shared and other container has common flow spec", port); } if (msg != null) { logger.debug(msg); return new Status(StatusCode.BADREQUEST, msg); } } } } return new Status(StatusCode.SUCCESS); }
/** * Adds/Remove the list of flow specs to/from the specified container. This * function is supposed to be called after all the validation checks have * already been run on the proposed configuration. */ private Status updateContainerFlow(String containerName, List<ContainerFlowConfig> confList, boolean delete) { ContainerData container = getContainerByName(containerName); if (container == null) { return new Status(StatusCode.GONE, "Container not present"); } for (ContainerFlowConfig conf : confList) { // Validation was fine. Modify the database now. for (Match match : conf.getMatches()) { ContainerFlow cFlow = new ContainerFlow(match); if (delete) { logger.trace("Removing Flow Spec {} from Container {}", conf.getName(), containerName); container.deleteFlowSpec(cFlow); } else { logger.trace("Adding Flow Spec {} to Container {}", conf.getName(), containerName); container.addFlowSpec(cFlow); } // Update Database putContainerDataByName(containerName, container); } } return new Status(StatusCode.SUCCESS); }
@Override public List<ContainerFlow> getContainerFlows() { List<ContainerFlow> list = new ArrayList<ContainerFlow>(); ContainerData d = this.iContainerInternal.getContainerData(this.containerName); if (d != null) { list.addAll(d.getContainerFlowSpecs()); } return list; }
@Override public String getContainerOperatorRole() { return iContainerInternal.getContainerData(containerName).getContainerOperatorRole(); } }
} else { logger.debug("Adding container {}", containerName); container = new ContainerData(containerConf); putContainerDataByName(containerName, container);
void setIContainerListener(IContainerListener s) { if (this.iContainerListener != null) { this.iContainerListener.add(s); /* * At boot with startup, containers are created before listeners have * joined. Replaying here the first container creation notification for * the joining listener when containers are already present. Also * replaying all the node connectors and container flows additions * to the existing containers. */ if (!this.containerData.isEmpty()) { s.containerModeUpdated(UpdateType.ADDED); } for (ConcurrentMap.Entry<NodeConnector, CopyOnWriteArrayList<String>> entry : nodeConnectorToContainers .entrySet()) { NodeConnector port = entry.getKey(); for (String container : entry.getValue()) { s.nodeConnectorUpdated(container, port, UpdateType.ADDED); } } for (Map.Entry<String, ContainerData> container : containerData.entrySet()) { for (ContainerFlow cFlow : container.getValue().getContainerFlowSpecs()) { s.containerFlowUpdated(container.getKey(), cFlow, cFlow, UpdateType.ADDED); } } } }
public void _psd(CommandInterpreter ci) { for (String containerName : containerData.keySet()) { ContainerData sd = containerData.get(containerName); for (Node sid : sd.getSwPorts().keySet()) { Set<NodeConnector> s = sd.getSwPorts().get(sid); ci.println("\t" + sid + " : " + s); } for (ContainerFlow s : sd.getContainerFlowSpecs()) { ci.println("\t" + s.toString()); } } }
/** * Checks if the passed list of node connectors can be safely applied to the * specified existing container in terms of port sharing with other containers. * * @param containerName * the name of the existing container * @param portList * the list of node connectors to be added to the container * @return the status object representing the result of the check */ private Status validatePortSharing(String containerName, List<NodeConnector> portList) { ContainerData container = this.getContainerByName(containerName); if (container == null) { String error = String .format("Cannot validate port sharing for container %s: (container does not exist)", containerName); logger.error(error); return new Status(StatusCode.BADREQUEST, error); } return validatePortSharingInternal(portList, container.getContainerFlowSpecs()); }
private void removeNodeConnectorToContainersMapping(ContainerData container) { Iterator<Entry<NodeConnector, CopyOnWriteArrayList<String>>> it = nodeConnectorToContainers.entrySet().iterator(); String containerName = container.getContainerName(); for (; it.hasNext();) { Entry<NodeConnector, CopyOnWriteArrayList<String>> entry = it.next(); final NodeConnector nc = entry.getKey(); final CopyOnWriteArrayList<String> slist = entry.getValue(); for (final String sdata : slist) { if (sdata.equalsIgnoreCase(containerName)) { logger.debug("Removing NodeConnector->Containers mapping, nodeConnector: {}", nc); slist.remove(containerName); if (slist.isEmpty()) { nodeConnectorToContainers.remove(nc); } else { nodeConnectorToContainers.put(nc, slist); } break; } } } }