package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.getOfPortNum;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.Nullable;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig.EncapsulationFormat;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayNodeConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.nodes.node.ExternalInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlanGpe;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
LOG.error("No SwitchState for {} in deactivatingSwitch. This should not happen.",nodeId);
return;
}
- state.setHasEndpoints(false);;
+ state.setHasEndpoints(false);
state.updateStatus();
}
+ public synchronized InstanceIdentifier<NodeConnector> getNodeConnectorIidForPortName(Name portName) {
+ for (SwitchState sw : switches.values()) {
+ if (sw.fcncByNcIid == null) {
+ continue;
+ }
+ for (Entry<InstanceIdentifier<NodeConnector>, FlowCapableNodeConnector> fcncByNcIidEntry : sw.fcncByNcIid
+ .entrySet()) {
+ FlowCapableNodeConnector fcnc = fcncByNcIidEntry.getValue();
+ if (portName.getValue().equals(fcnc.getName())) {
+ return fcncByNcIidEntry.getKey();
+ }
+ }
+ }
+ return null;
+ }
+
/**
* Get the collection of switches that are in the "ready" state. Note
* that the collection is immutable.
public synchronized Set<NodeConnectorId> getExternalPorts(NodeId nodeId) {
SwitchState state = switches.get(nodeId);
- if (state == null)
+ if (state == null) {
return Collections.emptySet();
+ }
return ImmutableSet.copyOf(state.externalPorts);
}
- public static synchronized NodeConnectorId getTunnelPort(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
+ public Set<Long> getExternalPortNumbers(NodeId nodeId) {
+ Set<Long> extPortNumbers = new HashSet<>();
+ for(NodeConnectorId nc : getExternalPorts(nodeId)) {
+ long portNum;
+ try {
+ portNum = getOfPortNum(nc);
+ } catch (NumberFormatException ex) {
+ LOG.warn("Could not parse port number {}", nc, ex);
+ return null;
+ }
+ extPortNumbers.add(portNum);
+ }
+ return extPortNumbers;
+ }
+
+ public synchronized Collection<NodeConnectorId> getTunnelPorts(NodeId nodeId) {
+ Collection<NodeConnectorId> ncIds = new HashSet<>();
+ SwitchState state = switches.get(nodeId);
+ if (state == null ) {
+ return Collections.emptySet();
+ }
+ ncIds = Collections2.transform(state.tunnelBuilderByType.values(),new Function<TunnelBuilder, NodeConnectorId>() {
+
+ @Override
+ public NodeConnectorId apply(TunnelBuilder input) {
+ return input.getNodeConnectorId();
+ }
+ });
+
+ return ncIds;
+ }
+ public synchronized NodeConnectorId getTunnelPort(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
SwitchState state = switches.get(nodeId);
if (state == null) {
return null;
return tunnel.getNodeConnectorId();
}
- public static synchronized IpAddress getTunnelIP(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
+ public synchronized IpAddress getTunnelIP(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
SwitchState state = switches.get(nodeId);
if (state == null) {
return null;
/**
* Constructor used for tests
+ *
+ * @param node the node id
+ * @param tunnelPort the tunnel port
+ * @param externalPorts the set of expternal ports
+ * @param nodeConfig the ofoverlay node config
*/
public SwitchState(NodeId node, NodeConnectorId tunnelPort, Set<NodeConnectorId> externalPorts,
OfOverlayNodeConfig nodeConfig) {
private void update() {
tunnelBuilderByType = new HashMap<>();
externalPorts = new HashSet<>();
- for (Entry<InstanceIdentifier<NodeConnector>, FlowCapableNodeConnector> fcncByNcIidEntry : fcncByNcIid.entrySet()) {
- FlowCapableNodeConnector fcnc = fcncByNcIidEntry.getValue();
- if (fcnc.getName() == null) {
- continue;
- }
- InstanceIdentifier<NodeConnector> ncIid = fcncByNcIidEntry.getKey();
- NodeConnectorId ncId = ncIid.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();
- if (fcnc.getName().matches(".*(vxlan).*")) {
- TunnelBuilder tunnelBuilder = tunnelBuilderByType.get(TunnelTypeVxlan.class);
- if (tunnelBuilder == null) {
- tunnelBuilder = new TunnelBuilder().setTunnelType(TunnelTypeVxlan.class);
- tunnelBuilderByType.put(TunnelTypeVxlan.class, tunnelBuilder);
- }
- tunnelBuilder.setNodeConnectorId(ncId);
- }
- if (nodeConfig != null && nodeConfig.getExternalInterfaces() != null) {
- for (ExternalInterfaces extIf : nodeConfig.getExternalInterfaces()) {
- if (extIf.getNodeConnectorId() != null
- && ncId.equals(extIf.getNodeConnectorId())) {
- externalPorts.add(ncId);
- break;
- }
- }
+ if (nodeConfig != null && nodeConfig.getExternalInterfaces() != null) {
+ for (ExternalInterfaces nc : nodeConfig.getExternalInterfaces()) {
+ externalPorts.add(nc.getNodeConnectorId());
}
}
if (nodeConfig != null && nodeConfig.getTunnel() != null) {
}
}
}
+ for (Entry<InstanceIdentifier<NodeConnector>, FlowCapableNodeConnector> fcncByNcIidEntry : fcncByNcIid.entrySet()) {
+ FlowCapableNodeConnector fcnc = fcncByNcIidEntry.getValue();
+ if (fcnc.getName() == null) {
+ continue;
+ }
+ InstanceIdentifier<NodeConnector> ncIid = fcncByNcIidEntry.getKey();
+ NodeConnectorId ncId = ncIid.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();
+ if (fcnc.getName().matches(".*(vxlan-).*")) {
+ TunnelBuilder tunnelBuilder = tunnelBuilderByType.get(TunnelTypeVxlan.class);
+ if (tunnelBuilder == null) {
+ tunnelBuilder = new TunnelBuilder().setTunnelType(TunnelTypeVxlan.class);
+ tunnelBuilderByType.put(TunnelTypeVxlan.class, tunnelBuilder);
+ }
+ tunnelBuilder.setNodeConnectorId(ncId);
+ } else if (fcnc.getName().matches(".*(vxlangpe-).*")) {
+ TunnelBuilder tunnelBuilder = tunnelBuilderByType.get(TunnelTypeVxlanGpe.class);
+ if (tunnelBuilder == null) {
+ tunnelBuilder = new TunnelBuilder().setTunnelType(TunnelTypeVxlanGpe.class);
+ tunnelBuilderByType.put(TunnelTypeVxlanGpe.class, tunnelBuilder);
+ }
+ tunnelBuilder.setNodeConnectorId(ncId);
+ }
+ }
}
private void updateStatus() {
LOG.trace("Iterating over tunnel till tunnel with IP and node-connector is not found.");
for (TunnelBuilder tb : tunnelBuilderByType.values()) {
if (tb.getIp() != null && tb.getNodeConnectorId() != null) {
-// LOG.trace("Tunnel found. Type: {} IP: {} Port: {} Node-connector: {}", tb.getTunnelType()
-// .getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
- LOG.trace("Tunnel found.");
+ LOG.trace("Tunnel {} found.",tb.toString());
return true;
} else {
-// LOG.trace("Tunnel which is not completed: Type: {} IP: {} Port: {} Node-connector: {}",
-// tb.getTunnelType().getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
- LOG.trace("Tunnel which is not completed");
+ LOG.trace("Tunnel is not complete for node: {}", nodeId.getValue());
}
}
return false;
}
public boolean isConfigurationEmpty() {
- if (fcNode != null)
+ if (fcNode != null) {
return false;
- if (nodeConfig != null)
+ }
+ if (nodeConfig != null) {
return false;
- if (!fcncByNcIid.isEmpty())
+ }
+ if (!fcncByNcIid.isEmpty()) {
return false;
+ }
return true;
}