CORD-247 Add host management network interface to integration bridge
- Node can have management network connectivity by adding "hostManagementIface"
field to the network config "nodes" block, it's optional field
- Added Builder of CordVtnNode
- Improved cordvtn-node-check result
- Some renamings, intBrId -> integrationBridgeId, dpIp -> dataIp,
dpIntf -> dataIface, and dpPort -> dataPort
Change-Id: Iad16237e7f118886d5f3fa5a46f9e9f9649fe997
diff --git a/src/main/java/org/opencord/cordvtn/api/Constants.java b/src/main/java/org/opencord/cordvtn/api/Constants.java
index b4c7329..bee5734 100644
--- a/src/main/java/org/opencord/cordvtn/api/Constants.java
+++ b/src/main/java/org/opencord/cordvtn/api/Constants.java
@@ -15,6 +15,8 @@
*/
package org.opencord.cordvtn.api;
+import org.onlab.packet.TpPort;
+
/**
* Provides constants used in CORD VTN services.
*/
@@ -30,8 +32,10 @@
public static final String MSG_OK = "OK";
public static final String MSG_NO = "NO";
- public static final String PORT_NAME = "portName";
public static final String DEFAULT_TUNNEL = "vxlan";
- public static final String DEFAULT_BRIDGE = "br-int";
+ public static final String INTEGRATION_BRIDGE = "br-int";
public static final String VPORT_PREFIX = "tap";
+
+ public static final int OF_PORT = 6653;
+ public static final TpPort OVSDB_PORT = TpPort.tpPort(6640);
}
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java b/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
index 10bc6a1..29ffaea 100644
--- a/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
@@ -16,14 +16,13 @@
package org.opencord.cordvtn.api;
import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
-import org.onosproject.net.DeviceId;
import org.onosproject.net.config.Config;
import org.onosproject.xosclient.api.OpenStackAccess;
import org.onosproject.xosclient.api.XosAccess;
@@ -51,9 +50,10 @@
private static final String CORDVTN_NODES = "nodes";
private static final String HOSTNAME = "hostname";
private static final String HOST_MANAGEMENT_IP = "hostManagementIp";
- private static final String DATA_PLANE_IP = "dataPlaneIp";
- private static final String DATA_PLANE_INTF = "dataPlaneIntf";
- private static final String BRIDGE_ID = "bridgeId";
+ private static final String HOST_MANAGEMENT_IFACE = "hostManagementIface";
+ private static final String DATA_IP = "dataPlaneIp";
+ private static final String DATA_IFACE = "dataPlaneIntf";
+ private static final String INTEGRATION_BRIDGE_ID = "bridgeId";
private static final String SSH = "ssh";
private static final String SSH_PORT = "sshPort";
@@ -68,6 +68,8 @@
private static final String USER = "user";
private static final String PASSWORD = "password";
+ // TODO implement isValid
+
/**
* Returns the set of nodes read from network config.
*
@@ -77,6 +79,7 @@
Set<CordVtnNode> nodes = Sets.newHashSet();
+ // TODO implement isValid and move these blocks to it
JsonNode cordvtnNodes = object.get(CORDVTN_NODES);
if (cordvtnNodes == null) {
log.debug("No CORD VTN nodes found");
@@ -90,37 +93,42 @@
}
for (JsonNode cordvtnNode : cordvtnNodes) {
- try {
- NetworkAddress hostMgmt = NetworkAddress.valueOf(getConfig(cordvtnNode, HOST_MANAGEMENT_IP));
- NetworkAddress localMgmt = NetworkAddress.valueOf(getConfig(object, LOCAL_MANAGEMENT_IP));
- if (hostMgmt.prefix().contains(localMgmt.prefix()) ||
- localMgmt.prefix().contains(hostMgmt.prefix())) {
- log.error("hostMamt and localMgmt cannot be overlapped, skip this node");
- continue;
- }
-
- Ip4Address hostMgmtIp = hostMgmt.ip().getIp4Address();
- SshAccessInfo sshInfo = new SshAccessInfo(
- hostMgmtIp,
- TpPort.tpPort(Integer.parseInt(getConfig(sshNode, SSH_PORT))),
- getConfig(sshNode, SSH_USER), getConfig(sshNode, SSH_KEY_FILE));
-
- String hostname = getConfig(cordvtnNode, HOSTNAME);
- CordVtnNode newNode = new CordVtnNode(
- hostname, hostMgmt, localMgmt,
- NetworkAddress.valueOf(getConfig(cordvtnNode, DATA_PLANE_IP)),
- TpPort.tpPort(Integer.parseInt(getConfig(object, OVSDB_PORT))),
- sshInfo,
- DeviceId.deviceId(getConfig(cordvtnNode, BRIDGE_ID)),
- getConfig(cordvtnNode, DATA_PLANE_INTF),
- CordVtnNodeState.noState());
-
- nodes.add(newNode);
- } catch (IllegalArgumentException | NullPointerException e) {
- log.error("{}", e);
+ // TODO implement isValid and move this block to it
+ NetworkAddress hostMgmt = NetworkAddress.valueOf(getConfig(cordvtnNode, HOST_MANAGEMENT_IP));
+ NetworkAddress localMgmt = NetworkAddress.valueOf(getConfig(object, LOCAL_MANAGEMENT_IP));
+ if (hostMgmt.prefix().contains(localMgmt.prefix()) ||
+ localMgmt.prefix().contains(hostMgmt.prefix())) {
+ log.error("hostMamt and localMgmt cannot be overlapped, skip this node");
+ continue;
}
- }
+ String hostname = getConfig(cordvtnNode, HOSTNAME);
+ SshAccessInfo sshInfo = new SshAccessInfo(
+ hostMgmt.ip().getIp4Address(),
+ TpPort.tpPort(Integer.parseInt(getConfig(sshNode, SSH_PORT))),
+ getConfig(sshNode, SSH_USER), getConfig(sshNode, SSH_KEY_FILE));
+
+ CordVtnNode.Builder nodeBuilder = CordVtnNode.builder()
+ .hostname(hostname)
+ .hostMgmtIp(hostMgmt)
+ .localMgmtIp(localMgmt)
+ .dataIp(getConfig(cordvtnNode, DATA_IP))
+ .sshInfo(sshInfo)
+ .integrationBridgeId(getConfig(cordvtnNode, INTEGRATION_BRIDGE_ID))
+ .dataIface(getConfig(cordvtnNode, DATA_IFACE));
+
+ String ovsdbPort = getConfig(object, OVSDB_PORT);
+ if (!Strings.isNullOrEmpty(ovsdbPort)) {
+ nodeBuilder.ovsdbPort(Integer.parseInt(ovsdbPort));
+ }
+
+ String hostMgmtIface = getConfig(cordvtnNode, HOST_MANAGEMENT_IFACE);
+ if (!Strings.isNullOrEmpty(hostMgmtIface)) {
+ nodeBuilder.hostMgmtIface(hostMgmtIface);
+ }
+
+ nodes.add(nodeBuilder.build());
+ }
return nodes;
}
@@ -135,7 +143,7 @@
jsonNode = jsonNode.path(path);
if (jsonNode.isMissingNode()) {
- log.error("{} is not configured", path);
+ log.debug("{} is not configured", path);
return null;
} else {
return jsonNode.asText();
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnNode.java b/src/main/java/org/opencord/cordvtn/api/CordVtnNode.java
index b251b49..206220f 100644
--- a/src/main/java/org/opencord/cordvtn/api/CordVtnNode.java
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnNode.java
@@ -16,13 +16,20 @@
package org.opencord.cordvtn.api;
import com.google.common.base.MoreObjects;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
import org.onlab.packet.TpPort;
import org.onosproject.net.DeviceId;
import java.util.Comparator;
import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opencord.cordvtn.api.Constants.DEFAULT_TUNNEL;
+import static org.opencord.cordvtn.api.Constants.OVSDB_PORT;
/**
* Representation of a compute infrastructure node for CORD VTN service.
@@ -32,11 +39,12 @@
private final String hostname;
private final NetworkAddress hostMgmtIp;
private final NetworkAddress localMgmtIp;
- private final NetworkAddress dpIp;
- private final TpPort ovsdbPort;
+ private final NetworkAddress dataIp;
+ private final Optional<TpPort> ovsdbPort;
private final SshAccessInfo sshInfo;
- private final DeviceId bridgeId;
- private final String dpIntf;
+ private final DeviceId integrationBridgeId;
+ private final String dataIface;
+ private final Optional<String> hostMgmtIface;
private final CordVtnNodeState state;
public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
@@ -48,24 +56,33 @@
* @param hostname hostname
* @param hostMgmtIp host management network address
* @param localMgmtIp local management network address
- * @param dpIp data plane network address
- * @param ovsdbPort port number for OVSDB connection
- * @param sshInfo SSH access information
- * @param bridgeId integration bridge identifier
- * @param dpIntf data plane interface name
+ * @param dataIp data network address
+ * @param ovsdbPort port number for ovsdb connection
+ * @param sshInfo ssh access information
+ * @param integrationBridgeId integration bridge identifier
+ * @param dataIface data plane interface name
+ * @param hostMgmtIface host management network interface
* @param state cordvtn node state
*/
- public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp,
- NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo,
- DeviceId bridgeId, String dpIntf, CordVtnNodeState state) {
- this.hostname = checkNotNull(hostname, "hostname cannot be null");
- this.hostMgmtIp = checkNotNull(hostMgmtIp, "hostMgmtIp cannot be null");
- this.localMgmtIp = checkNotNull(localMgmtIp, "localMgmtIp cannot be null");
- this.dpIp = checkNotNull(dpIp, "dpIp cannot be null");
- this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null");
- this.sshInfo = checkNotNull(sshInfo, "sshInfo cannot be null");
- this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null");
- this.dpIntf = checkNotNull(dpIntf, "dpIntf cannot be null");
+ private CordVtnNode(String hostname,
+ NetworkAddress hostMgmtIp,
+ NetworkAddress localMgmtIp,
+ NetworkAddress dataIp,
+ Optional<TpPort> ovsdbPort,
+ SshAccessInfo sshInfo,
+ DeviceId integrationBridgeId,
+ String dataIface,
+ Optional<String> hostMgmtIface,
+ CordVtnNodeState state) {
+ this.hostname = hostname;
+ this.hostMgmtIp = hostMgmtIp;
+ this.localMgmtIp = localMgmtIp;
+ this.dataIp = dataIp;
+ this.ovsdbPort = ovsdbPort;
+ this.sshInfo = sshInfo;
+ this.integrationBridgeId = integrationBridgeId;
+ this.dataIface = dataIface;
+ this.hostMgmtIface = hostMgmtIface;
this.state = state;
}
@@ -78,11 +95,12 @@
*/
public static CordVtnNode getUpdatedNode(CordVtnNode node, CordVtnNodeState state) {
return new CordVtnNode(node.hostname,
- node.hostMgmtIp, node.localMgmtIp, node.dpIp,
+ node.hostMgmtIp, node.localMgmtIp, node.dataIp,
node.ovsdbPort,
node.sshInfo,
- node.bridgeId,
- node.dpIntf, state);
+ node.integrationBridgeId,
+ node.dataIface, node.hostMgmtIface,
+ state);
}
/**
@@ -113,21 +131,26 @@
}
/**
- * Returns the data plane network address.
+ * Returns the data network address.
*
* @return network address
*/
- public NetworkAddress dpIp() {
- return this.dpIp;
+ public NetworkAddress dataIp() {
+ return this.dataIp;
}
/**
* Returns the port number used for OVSDB connection.
+ * It returns default OVSDB port 6640, if it's not specified.
*
* @return port number
*/
public TpPort ovsdbPort() {
- return this.ovsdbPort;
+ if (this.ovsdbPort.isPresent()) {
+ return this.ovsdbPort.get();
+ } else {
+ return OVSDB_PORT;
+ }
}
/**
@@ -144,8 +167,8 @@
*
* @return device id
*/
- public DeviceId intBrId() {
- return this.bridgeId;
+ public DeviceId integrationBridgeId() {
+ return this.integrationBridgeId;
}
/**
@@ -158,12 +181,34 @@
}
/**
- * Returns data plane interface name.
+ * Returns data network interface name.
*
- * @return data plane interface name
+ * @return data network interface name
*/
- public String dpIntf() {
- return this.dpIntf;
+ public String dataIface() {
+ return this.dataIface;
+ }
+
+ /**
+ * Returns host management network interface name.
+ *
+ * @return host management network interface name
+ */
+ public Optional<String> hostMgmtIface() {
+ return this.hostMgmtIface;
+ }
+
+ /**
+ * Returns a set of network interfaces for the VTN service to work properly.
+ *
+ * @return set of interface names
+ */
+ public Set<String> systemIfaces() {
+ Set<String> ifaces = Sets.newHashSet(DEFAULT_TUNNEL, dataIface);
+ if (hostMgmtIface.isPresent()) {
+ ifaces.add(hostMgmtIface.get());
+ }
+ return ifaces;
}
/**
@@ -186,11 +231,12 @@
if (Objects.equals(hostname, that.hostname) &&
Objects.equals(hostMgmtIp, that.hostMgmtIp) &&
Objects.equals(localMgmtIp, that.localMgmtIp) &&
- Objects.equals(dpIp, that.dpIp) &&
+ Objects.equals(dataIp, that.dataIp) &&
Objects.equals(ovsdbPort, that.ovsdbPort) &&
Objects.equals(sshInfo, that.sshInfo) &&
- Objects.equals(bridgeId, that.bridgeId) &&
- Objects.equals(dpIntf, that.dpIntf)) {
+ Objects.equals(integrationBridgeId, that.integrationBridgeId) &&
+ Objects.equals(dataIface, that.dataIface) &&
+ Objects.equals(hostMgmtIface, that.hostMgmtIface)) {
return true;
}
}
@@ -199,8 +245,15 @@
@Override
public int hashCode() {
- return Objects.hash(hostname, hostMgmtIp, localMgmtIp, dpIp,
- ovsdbPort, sshInfo, bridgeId, dpIntf);
+ return Objects.hash(hostname,
+ hostMgmtIp,
+ localMgmtIp,
+ dataIp,
+ ovsdbPort,
+ sshInfo,
+ integrationBridgeId,
+ dataIface,
+ hostMgmtIface);
}
@Override
@@ -209,12 +262,240 @@
.add("hostname", hostname)
.add("hostMgmtIp", hostMgmtIp)
.add("localMgmtIp", localMgmtIp)
- .add("dpIp", dpIp)
+ .add("dataIp", dataIp)
.add("port", ovsdbPort)
.add("sshInfo", sshInfo)
- .add("bridgeId", bridgeId)
- .add("dpIntf", dpIntf)
+ .add("integrationBridgeId", integrationBridgeId)
+ .add("dataIface", dataIface)
+ .add("hostMgmtIface", hostMgmtIface)
.add("state", state)
.toString();
}
+
+ /**
+ * Returns new node builder instance.
+ *
+ * @return cordvtn node builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of node entities.
+ */
+ public static final class Builder {
+ private String hostname;
+ private NetworkAddress hostMgmtIp;
+ private NetworkAddress localMgmtIp;
+ private NetworkAddress dataIp;
+ private Optional<TpPort> ovsdbPort = Optional.of(OVSDB_PORT);
+ private SshAccessInfo sshInfo;
+ private DeviceId integrationBridgeId;
+ private String dataIface;
+ private Optional<String> hostMgmtIface = Optional.empty();
+ private CordVtnNodeState state = CordVtnNodeState.noState();
+
+ private Builder() {
+ }
+
+ /**
+ * Builds an immutable cordvtn node.
+ *
+ * @return cordvtn node
+ */
+ public CordVtnNode build() {
+ // validate attributes
+ checkArgument(!Strings.isNullOrEmpty(hostname));
+ checkNotNull(hostMgmtIp);
+ checkNotNull(localMgmtIp);
+ checkNotNull(dataIp);
+ checkNotNull(ovsdbPort);
+ checkNotNull(sshInfo);
+ checkNotNull(integrationBridgeId);
+ checkNotNull(dataIface);
+ checkNotNull(hostMgmtIface);
+ return new CordVtnNode(hostname,
+ hostMgmtIp, localMgmtIp, dataIp,
+ ovsdbPort,
+ sshInfo,
+ integrationBridgeId,
+ dataIface,
+ hostMgmtIface,
+ state);
+ }
+
+ /**
+ * Returns cordvtn node builder with hostname.
+ *
+ * @param hostname hostname
+ * @return cordvtn node builder
+ */
+ public Builder hostname(String hostname) {
+ checkArgument(!Strings.isNullOrEmpty(hostname));
+ this.hostname = hostname;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with host management network IP address.
+ *
+ * @param hostMgmtIp host management netework ip address
+ * @return cordvtn node builder
+ */
+ public Builder hostMgmtIp(NetworkAddress hostMgmtIp) {
+ checkNotNull(hostMgmtIp);
+ this.hostMgmtIp = hostMgmtIp;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with host management network IP address.
+ *
+ * @param cidr string value of the host management network ip address
+ * @return cordvtn node builder
+ */
+ public Builder hostMgmtIp(String cidr) {
+ this.hostMgmtIp = NetworkAddress.valueOf(cidr);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with local management network IP address.
+ *
+ * @param localMgmtIp local management network ip address
+ * @return cordvtn node builder
+ */
+ public Builder localMgmtIp(NetworkAddress localMgmtIp) {
+ checkNotNull(localMgmtIp);
+ this.localMgmtIp = localMgmtIp;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with local management netework IP address.
+ *
+ * @param cidr string value of the local management network ip address
+ * @return cordvtn node builder
+ */
+ public Builder localMgmtIp(String cidr) {
+ this.localMgmtIp = NetworkAddress.valueOf(cidr);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with data network IP address.
+ *
+ * @param dataIp data network ip address
+ * @return cordvtn node builder
+ */
+ public Builder dataIp(NetworkAddress dataIp) {
+ checkNotNull(dataIp);
+ this.dataIp = dataIp;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with data network IP address.
+ *
+ * @param cidr string value of the data network ip address
+ * @return cordvtn node builder
+ */
+ public Builder dataIp(String cidr) {
+ this.dataIp = NetworkAddress.valueOf(cidr);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with OVSDB server listen port number.
+ *
+ * @param port ovsdb server listen port number
+ * @return cordvtn node builder
+ */
+ public Builder ovsdbPort(TpPort port) {
+ checkNotNull(port);
+ this.ovsdbPort = Optional.of(port);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with OVSDB server listen port number.
+ *
+ * @param port int value of the ovsdb server listen port number
+ * @return cordvtn node builder
+ */
+ public Builder ovsdbPort(int port) {
+ this.ovsdbPort = Optional.of(TpPort.tpPort(port));
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with SSH access information.
+ * @param sshInfo ssh access information
+ * @return cordvtn node builder
+ */
+ public Builder sshInfo(SshAccessInfo sshInfo) {
+ checkNotNull(sshInfo);
+ this.sshInfo = sshInfo;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with integration bridge ID.
+ *
+ * @param deviceId device id of the integration bridge
+ * @return cordvtn node builder
+ */
+ public Builder integrationBridgeId(DeviceId deviceId) {
+ checkNotNull(deviceId);
+ this.integrationBridgeId = deviceId;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with integration bridge ID.
+ *
+ * @param deviceId string value of the integration bridge device id
+ * @return cordvtn node builder
+ */
+ public Builder integrationBridgeId(String deviceId) {
+ this.integrationBridgeId = DeviceId.deviceId(deviceId);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with data network interface name.
+ *
+ * @param dataIface data network interface name
+ * @return cordvtn node builder
+ */
+ public Builder dataIface(String dataIface) {
+ checkArgument(!Strings.isNullOrEmpty(dataIface));
+ this.dataIface = dataIface;
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with host management network interface.
+ *
+ * @param hostMgmtIface host management network interface name
+ * @return cordvtn node builder
+ */
+ public Builder hostMgmtIface(String hostMgmtIface) {
+ this.hostMgmtIface = Optional.ofNullable(hostMgmtIface);
+ return this;
+ }
+
+ /**
+ * Returns cordvtn node builder with init state.
+ *
+ * @param state init state
+ * @return cordvtn node builder
+ */
+ public Builder state(CordVtnNodeState state) {
+ checkNotNull(state);
+ this.state = state;
+ return this;
+ }
+ }
}
diff --git a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
index 6d591b0..d0189e4 100644
--- a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
+++ b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
@@ -16,14 +16,23 @@
package org.opencord.cordvtn.cli;
+import com.jcraft.jsch.Session;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
import org.opencord.cordvtn.api.CordVtnNode;
import org.opencord.cordvtn.impl.CordVtnNodeManager;
import org.onosproject.net.Device;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DriverService;
+
+import java.util.Set;
+
+import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.opencord.cordvtn.api.Constants.*;
+import static org.opencord.cordvtn.impl.RemoteIpCommandUtil.*;
/**
* Checks detailed node init state.
@@ -52,23 +61,74 @@
return;
}
- print(nodeManager.checkNodeInitState(node));
+ print("%n[Integration Bridge Status]");
+ Device device = deviceService.getDevice(node.integrationBridgeId());
+ if (device != null) {
+ print("%s %s=%s available=%s %s",
+ deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO,
+ INTEGRATION_BRIDGE,
+ device.id(),
+ deviceService.isAvailable(device.id()),
+ device.annotations());
- print("%n[DEBUG]");
- Device device = deviceService.getDevice(node.intBrId());
- String driver = get(DriverService.class).getDriver(device.id()).name();
- print("%s available=%s driver=%s %s",
- device.id(),
- deviceService.isAvailable(device.id()),
- driver,
- device.annotations());
+ node.systemIfaces().stream().forEach(iface -> print(
+ getPortState(deviceService, node.integrationBridgeId(), iface)));
+ } else {
+ print("%s %s=%s is not available",
+ MSG_NO,
+ INTEGRATION_BRIDGE,
+ node.integrationBridgeId());
+ }
- deviceService.getPorts(node.intBrId()).forEach(port -> {
- Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
- print("port=%s state=%s %s",
- port.number(),
- portIsEnabled,
- port.annotations());
- });
+ print("%n[Interfaces and IP setup]");
+ Session session = connect(node.sshInfo());
+ if (session != null) {
+ Set<IpAddress> ips = getCurrentIps(session, INTEGRATION_BRIDGE);
+ boolean isUp = isInterfaceUp(session, INTEGRATION_BRIDGE);
+ boolean isIp = ips.contains(node.dataIp().ip()) && ips.contains(node.localMgmtIp().ip());
+
+ print("%s %s up=%s Ips=%s",
+ isUp && isIp ? MSG_OK : MSG_NO,
+ INTEGRATION_BRIDGE,
+ isUp ? Boolean.TRUE : Boolean.FALSE,
+ getCurrentIps(session, INTEGRATION_BRIDGE));
+
+ print(getSystemIfaceState(session, node.dataIface()));
+ if (node.hostMgmtIface().isPresent()) {
+ print(getSystemIfaceState(session, node.hostMgmtIface().get()));
+ }
+
+ disconnect(session);
+ } else {
+ print("%s Unable to SSH to %s", MSG_NO, node.hostname());
+ }
+ }
+
+ private String getPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
+ Port port = deviceService.getPorts(deviceId).stream()
+ .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
+ p.isEnabled())
+ .findAny().orElse(null);
+
+ if (port != null) {
+ return String.format("%s %s portNum=%s enabled=%s %s",
+ port.isEnabled() ? MSG_OK : MSG_NO,
+ portName,
+ port.number(),
+ port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
+ port.annotations());
+ } else {
+ return String.format("%s %s does not exist", MSG_NO, portName);
+ }
+ }
+
+ private String getSystemIfaceState(Session session, String iface) {
+ boolean isUp = isInterfaceUp(session, iface);
+ boolean isIp = getCurrentIps(session, iface).isEmpty();
+ return String.format("%s %s up=%s IpFlushed=%s",
+ isUp && isIp ? MSG_OK : MSG_NO,
+ iface,
+ isUp ? Boolean.TRUE : Boolean.FALSE,
+ isIp ? Boolean.TRUE : Boolean.FALSE);
}
}
diff --git a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeListCommand.java b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeListCommand.java
index b8aa2cd..0b25e7b 100644
--- a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeListCommand.java
+++ b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeListCommand.java
@@ -47,12 +47,12 @@
print("%s", json(nodeManager, nodes));
} else {
for (CordVtnNode node : nodes) {
- print("hostname=%s, hostMgmtIp=%s, dpIp=%s, br-int=%s, dpIntf=%s, init=%s",
+ print("hostname=%s, hostMgmtIp=%s, dataIp=%s, br-int=%s, dataIface=%s, init=%s",
node.hostname(),
node.hostMgmtIp().cidr(),
- node.dpIp().cidr(),
- node.intBrId().toString(),
- node.dpIntf(),
+ node.dataIp().cidr(),
+ node.integrationBridgeId().toString(),
+ node.dataIface(),
getState(nodeManager, node));
}
print("Total %s nodes", nodeManager.getNodeCount());
@@ -66,9 +66,9 @@
result.add(mapper.createObjectNode()
.put("hostname", node.hostname())
.put("hostManagementIp", node.hostMgmtIp().cidr())
- .put("dataPlaneIp", node.dpIp().cidr())
- .put("bridgeId", node.intBrId().toString())
- .put("dataPlaneInterface", node.dpIntf())
+ .put("dataPlaneIp", node.dataIp().cidr())
+ .put("bridgeId", node.integrationBridgeId().toString())
+ .put("dataPlaneInterface", node.dataIface())
.put("init", getState(nodeManager, node)));
}
return result;
diff --git a/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java b/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
index 8f30931..463c5d5 100644
--- a/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
+++ b/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
@@ -15,7 +15,7 @@
*/
package org.opencord.cordvtn.impl;
-import com.google.common.collect.Sets;
+import com.google.common.base.Strings;
import com.jcraft.jsch.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -24,11 +24,15 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
-import org.onlab.util.ItemNotFoundException;
import org.onlab.util.KryoNamespace;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.behaviour.BridgeDescription;
+import org.onosproject.net.behaviour.DefaultBridgeDescription;
+import org.onosproject.net.behaviour.InterfaceConfig;
+import org.onosproject.net.behaviour.TunnelEndPoints;
+import org.onosproject.net.behaviour.TunnelKeys;
import org.opencord.cordvtn.api.ConnectionHandler;
import org.opencord.cordvtn.api.CordVtnConfig;
import org.opencord.cordvtn.api.CordVtnNode;
@@ -39,19 +43,15 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.Host;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.BridgeConfig;
import org.onosproject.net.behaviour.BridgeName;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.net.behaviour.DefaultTunnelDescription;
-import org.onosproject.net.behaviour.TunnelConfig;
import org.onosproject.net.behaviour.TunnelDescription;
-import org.onosproject.net.behaviour.TunnelName;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry;
@@ -73,10 +73,7 @@
import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
@@ -85,6 +82,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
+import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.net.Device.Type.SWITCH;
import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN;
import static org.opencord.cordvtn.api.Constants.*;
@@ -109,14 +107,7 @@
.register(SshAccessInfo.class)
.register(NetworkAddress.class);
- private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() {
- {
- put("key", "flow");
- put("remote_ip", "flow");
- }
- };
private static final int DPID_BEGIN = 3;
- private static final int OFPORT = 6653;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -134,7 +125,7 @@
protected DeviceAdminService adminService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected OvsdbController controller;
+ protected OvsdbController ovsdbController;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@@ -173,21 +164,27 @@
INIT {
@Override
public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
+ // make sure there is OVSDB connection
if (!nodeManager.isOvsdbConnected(node)) {
nodeManager.connectOvsdb(node);
- } else {
- nodeManager.createIntegrationBridge(node);
+ return;
}
+ nodeManager.createIntegrationBridge(node);
}
},
BRIDGE_CREATED {
@Override
public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
+ // make sure there is OVSDB connection
if (!nodeManager.isOvsdbConnected(node)) {
nodeManager.connectOvsdb(node);
- } else {
- nodeManager.createTunnelInterface(node);
- nodeManager.addDataPlaneInterface(node);
+ return;
+ }
+
+ nodeManager.createTunnelInterface(node);
+ nodeManager.addSystemInterface(node, node.dataIface());
+ if (node.hostMgmtIface().isPresent()) {
+ nodeManager.addSystemInterface(node, node.hostMgmtIface().get());
}
}
},
@@ -261,11 +258,10 @@
*/
public void deleteNode(CordVtnNode node) {
checkNotNull(node);
-
- if (isOvsdbConnected(node)) {
- disconnectOvsdb(node);
+ OvsdbClientService ovsdbClient = getOvsdbClient(node);
+ if (ovsdbClient != null && ovsdbClient.isConnected()) {
+ ovsdbClient.disconnect();
}
-
nodeStore.remove(node.hostname());
}
@@ -277,50 +273,7 @@
*/
public boolean isNodeInitComplete(CordVtnNode node) {
checkNotNull(node);
- return nodeStore.containsKey(node.hostname()) && getNodeState(node).equals(NodeState.COMPLETE);
- }
-
- /**
- * Returns detailed node initialization state.
- *
- * @param node cordvtn node
- * @return string including detailed node init state
- */
- public String checkNodeInitState(CordVtnNode node) {
- checkNotNull(node);
-
- if (!nodeStore.containsKey(node.hostname())) {
- log.warn("Node {} does not exist, add node first", node.hostname());
- return null;
- }
-
- Session session = connect(node.sshInfo());
- if (session == null) {
- log.debug("Failed to SSH to {}", node.hostname());
- return null;
- }
-
- Set<IpAddress> intBrIps = getCurrentIps(session, DEFAULT_BRIDGE);
- String result = String.format(
- "Current state : %s%n" +
- "br-int created and connected to ONOS : %s (%s)%n" +
- "VXLAN interface added to br-int : %s%n" +
- "Data plane interface is added to br-int and enabled : %s (%s)%n" +
- "IP flushed from data plane interface : %s (%s)%n" +
- "Data plane IP added to br-int : %s (%s)%n" +
- "Local management IP added to br-int : %s (%s)",
- node.state(),
- isBrIntCreated(node) ? MSG_OK : MSG_NO, node.intBrId(),
- isTunnelIntfCreated(node) ? MSG_OK : MSG_NO,
- isDataPlaneIntfAdded(node) ? MSG_OK : MSG_NO, node.dpIntf(),
- isInterfaceUp(session, node.dpIntf()) &&
- getCurrentIps(session, node.dpIntf()).isEmpty() ? MSG_OK : MSG_NO, node.dpIntf(),
- intBrIps.contains(node.dpIp().ip()) ? MSG_OK : MSG_NO, node.dpIp().cidr(),
- intBrIps.contains(node.localMgmtIp().ip()) ? MSG_OK : MSG_NO, node.localMgmtIp().cidr());
-
- disconnect(session);
-
- return result;
+ return getNodeState(node).equals(NodeState.COMPLETE);
}
/**
@@ -347,7 +300,8 @@
* @return set of nodes
*/
public Set<CordVtnNode> completeNodes() {
- return getNodes().stream().filter(this::isNodeInitComplete).collect(Collectors.toSet());
+ return getNodes().stream().filter(this::isNodeStateComplete)
+ .collect(Collectors.toSet());
}
/**
@@ -356,14 +310,14 @@
* @param deviceId integration bridge device id
* @return port number; null otherwise
*/
- public PortNumber dpPort(DeviceId deviceId) {
+ public PortNumber dataPort(DeviceId deviceId) {
CordVtnNode node = nodeByBridgeId(deviceId);
if (node == null) {
log.warn("Failed to get node for {}", deviceId);
return null;
}
Port port = deviceService.getPorts(deviceId).stream()
- .filter(p -> portName(p).contains(node.dpIntf()) &&
+ .filter(p -> portName(p).contains(node.dataIface()) &&
p.isEnabled())
.findFirst().orElse(null);
@@ -376,13 +330,13 @@
* @param deviceId integration bridge device id
* @return ip address; null otherwise
*/
- public IpAddress dpIp(DeviceId deviceId) {
+ public IpAddress dataIp(DeviceId deviceId) {
CordVtnNode node = nodeByBridgeId(deviceId);
if (node == null) {
log.warn("Failed to get node for {}", deviceId);
return null;
}
- return node.dpIp().ip();
+ return node.dataIp().ip();
}
/**
@@ -438,18 +392,29 @@
* @param node cordvtn node
*/
private void postInit(CordVtnNode node) {
- disconnectOvsdb(node);
- pipeline.initPipeline(node, dpPort(node.intBrId()), tunnelPort(node.intBrId()));
+ checkNotNull(node);
- deviceService.getPorts(node.intBrId()).stream()
+ // disconnect OVSDB session once the node bootstrap is done
+ OvsdbClientService ovsdbClient = getOvsdbClient(node);
+ if (ovsdbClient != null && ovsdbClient.isConnected()) {
+ ovsdbClient.disconnect();
+ }
+
+ pipeline.initPipeline(node, dataPort(node.integrationBridgeId()),
+ tunnelPort(node.integrationBridgeId()));
+
+ // adds existing instances to the host list
+ deviceService.getPorts(node.integrationBridgeId()).stream()
.filter(port -> portName(port).startsWith(VPORT_PREFIX) &&
port.isEnabled())
.forEach(port -> instanceService.addInstance(connectPoint(port)));
+ // removes stale instances from the host list
hostService.getHosts().forEach(host -> {
- if (deviceService.getPort(host.location().deviceId(),
- host.location().port()) == null) {
- instanceService.removeInstance(connectPoint(host));
+ if (deviceService.getPort(
+ host.location().deviceId(),
+ host.location().port()) == null) {
+ instanceService.removeInstance(host.location());
}
});
@@ -464,7 +429,6 @@
*/
private void setNodeState(CordVtnNode node, NodeState newState) {
checkNotNull(node);
-
log.debug("Changed {} state: {}", node.hostname(), newState);
nodeStore.put(node.hostname(), CordVtnNode.getUpdatedNode(node, newState));
}
@@ -477,17 +441,18 @@
*/
private NodeState getNodeState(CordVtnNode node) {
checkNotNull(node);
-
- if (isBrIntCreated(node) && isTunnelIntfCreated(node) &&
- isDataPlaneIntfAdded(node) && isIpAddressSet(node)) {
- return NodeState.COMPLETE;
- } else if (isDataPlaneIntfAdded(node) && isTunnelIntfCreated(node)) {
- return NodeState.PORTS_ADDED;
- } else if (isBrIntCreated(node)) {
- return NodeState.BRIDGE_CREATED;
- } else {
+ if (!isIntegrationBridgeCreated(node)) {
return NodeState.INIT;
}
+ for (String iface : node.systemIfaces()) {
+ if (!isIfaceCreated(node, iface)) {
+ return NodeState.BRIDGE_CREATED;
+ }
+ }
+ if (!isIpAddressSet(node)) {
+ return NodeState.PORTS_ADDED;
+ }
+ return NodeState.COMPLETE;
}
/**
@@ -498,10 +463,10 @@
*/
private boolean isOvsdbConnected(CordVtnNode node) {
checkNotNull(node);
-
OvsdbClientService ovsdbClient = getOvsdbClient(node);
return deviceService.isAvailable(node.ovsdbId()) &&
- ovsdbClient != null && ovsdbClient.isConnected();
+ ovsdbClient != null &&
+ ovsdbClient.isConnected();
}
/**
@@ -511,150 +476,83 @@
*/
private void connectOvsdb(CordVtnNode node) {
checkNotNull(node);
-
- if (!nodeStore.containsKey(node.hostname())) {
- log.warn("Node {} does not exist", node.hostname());
- return;
- }
-
- if (!isOvsdbConnected(node)) {
- controller.connect(node.hostMgmtIp().ip(), node.ovsdbPort());
- }
- }
-
- /**
- * Disconnects OVSDB server for a given node.
- *
- * @param node cordvtn node
- */
- private void disconnectOvsdb(CordVtnNode node) {
- checkNotNull(node);
-
- if (!nodeStore.containsKey(node.hostname())) {
- log.warn("Node {} does not exist", node.hostname());
- return;
- }
-
- if (isOvsdbConnected(node)) {
- OvsdbClientService ovsdbClient = getOvsdbClient(node);
- ovsdbClient.disconnect();
- }
+ ovsdbController.connect(node.hostMgmtIp().ip(), node.ovsdbPort());
}
/**
* Returns OVSDB client for a given node.
*
* @param node cordvtn node
- * @return OVSDB client, or null if it fails to get OVSDB client
+ * @return ovsdb client, or null if there's no ovsdb connection
*/
private OvsdbClientService getOvsdbClient(CordVtnNode node) {
checkNotNull(node);
-
- OvsdbClientService ovsdbClient = controller.getOvsdbClient(
- new OvsdbNodeId(node.hostMgmtIp().ip(), node.ovsdbPort().toInt()));
- if (ovsdbClient == null) {
- log.trace("Couldn't find OVSDB client for {}", node.hostname());
- }
- return ovsdbClient;
+ OvsdbNodeId ovsdb = new OvsdbNodeId(
+ node.hostMgmtIp().ip(), node.ovsdbPort().toInt());
+ return ovsdbController.getOvsdbClient(ovsdb);
}
- /**
- * Creates an integration bridge for a given node.
- *
- * @param node cordvtn node
- */
private void createIntegrationBridge(CordVtnNode node) {
- if (isBrIntCreated(node)) {
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (device == null || !device.is(BridgeConfig.class)) {
+ log.error("Failed to create integration bridge on {}", node.ovsdbId());
return;
}
- List<ControllerInfo> controllers = new ArrayList<>();
- Sets.newHashSet(clusterService.getNodes()).stream()
- .forEach(controller -> {
- ControllerInfo ctrlInfo = new ControllerInfo(controller.ip(), OFPORT, "tcp");
- controllers.add(ctrlInfo);
- });
+ List<ControllerInfo> controllers = clusterService.getNodes().stream()
+ .map(controller -> new ControllerInfo(controller.ip(), OF_PORT, "tcp"))
+ .collect(Collectors.toList());
- String dpid = node.intBrId().toString().substring(DPID_BEGIN);
+ String dpid = node.integrationBridgeId().toString().substring(DPID_BEGIN);
+ BridgeDescription bridgeDesc = DefaultBridgeDescription.builder()
+ .name(INTEGRATION_BRIDGE)
+ .failMode(BridgeDescription.FailMode.SECURE)
+ .datapathId(dpid)
+ .disableInBand()
+ .controllers(controllers)
+ .build();
- try {
- Device device = deviceService.getDevice(node.ovsdbId());
- if (device.is(BridgeConfig.class)) {
- BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
- bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers);
- } else {
- log.warn("The bridging behaviour is not supported in device {}", device.id());
- }
- } catch (ItemNotFoundException e) {
- log.warn("Failed to create integration bridge on {}", node.hostname());
- }
+ BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
+ bridgeConfig.addBridge(bridgeDesc);
}
- /**
- * Creates tunnel interface to the integration bridge for a given node.
- *
- * @param node cordvtn node
- */
private void createTunnelInterface(CordVtnNode node) {
- if (isTunnelIntfCreated(node)) {
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (device == null || !device.is(InterfaceConfig.class)) {
+ log.error("Failed to create tunnel interface on {}", node.ovsdbId());
return;
}
- DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder();
- for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) {
- optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key));
- }
+ TunnelDescription tunnelDesc = DefaultTunnelDescription.builder()
+ .deviceId(INTEGRATION_BRIDGE)
+ .ifaceName(DEFAULT_TUNNEL)
+ .type(VXLAN)
+ .remote(TunnelEndPoints.flowTunnelEndpoint())
+ .key(TunnelKeys.flowTunnelKey())
+ .build();
- TunnelDescription description = new DefaultTunnelDescription(
- null, null, VXLAN, TunnelName.tunnelName(DEFAULT_TUNNEL),
- optionBuilder.build());
-
- try {
- Device device = deviceService.getDevice(node.ovsdbId());
- if (device.is(TunnelConfig.class)) {
- TunnelConfig tunnelConfig = device.as(TunnelConfig.class);
- tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description);
- } else {
- log.warn("The tunneling behaviour is not supported in device {}", device.id());
- }
- } catch (ItemNotFoundException e) {
- log.warn("Failed to create tunnel interface on {}", node.hostname());
- }
+ InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
+ ifaceConfig.addTunnelMode(DEFAULT_TUNNEL, tunnelDesc);
}
- /**
- * Adds data plane interface to a given node.
- *
- * @param node cordvtn node
- */
- private void addDataPlaneInterface(CordVtnNode node) {
- if (isDataPlaneIntfAdded(node)) {
- return;
- }
-
+ private void addSystemInterface(CordVtnNode node, String ifaceName) {
Session session = connect(node.sshInfo());
- if (session == null) {
- log.debug("Failed to SSH to {}", node.hostname());
+ if (session == null || !isInterfaceUp(session, ifaceName)) {
+ log.warn("Interface {} is not available on {}", ifaceName, node.hostname());
+ disconnect(session);
+ return;
+ } else {
+ disconnect(session);
+ }
+
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (!device.is(BridgeConfig.class)) {
+ log.error("BridgeConfig is not supported for {}", node.ovsdbId());
return;
}
- if (!isInterfaceUp(session, node.dpIntf())) {
- log.warn("Interface {} is not available", node.dpIntf());
- return;
- }
- disconnect(session);
-
- try {
- Device device = deviceService.getDevice(node.ovsdbId());
- if (device.is(BridgeConfig.class)) {
- BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
- bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf());
- } else {
- log.warn("The bridging behaviour is not supported in device {}", device.id());
- }
- } catch (ItemNotFoundException e) {
- log.warn("Failed to add {} on {}", node.dpIntf(), node.hostname());
- }
+ BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
+ bridgeConfig.addPort(BridgeName.bridgeName(INTEGRATION_BRIDGE), ifaceName);
}
/**
@@ -669,62 +567,37 @@
log.debug("Failed to SSH to {}", node.hostname());
return;
}
-
- getCurrentIps(session, DEFAULT_BRIDGE).stream()
+ getCurrentIps(session, INTEGRATION_BRIDGE).stream()
.filter(ip -> !ip.equals(node.localMgmtIp().ip()))
- .filter(ip -> !ip.equals(node.dpIp().ip()))
- .forEach(ip -> deleteIp(session, ip, DEFAULT_BRIDGE));
+ .filter(ip -> !ip.equals(node.dataIp().ip()))
+ .forEach(ip -> deleteIp(session, ip, INTEGRATION_BRIDGE));
- boolean result = flushIp(session, node.dpIntf()) &&
- setInterfaceUp(session, node.dpIntf()) &&
- addIp(session, node.dpIp(), DEFAULT_BRIDGE) &&
- addIp(session, node.localMgmtIp(), DEFAULT_BRIDGE) &&
- setInterfaceUp(session, DEFAULT_BRIDGE);
+ boolean result = flushIp(session, node.dataIface()) &&
+ setInterfaceUp(session, node.dataIface()) &&
+ addIp(session, node.dataIp(), INTEGRATION_BRIDGE) &&
+ addIp(session, node.localMgmtIp(), INTEGRATION_BRIDGE) &&
+ setInterfaceUp(session, INTEGRATION_BRIDGE);
disconnect(session);
-
if (result) {
setNodeState(node, NodeState.COMPLETE);
}
}
- /**
- * Checks if integration bridge exists and available.
- *
- * @param node cordvtn node
- * @return true if the bridge is available, false otherwise
- */
- private boolean isBrIntCreated(CordVtnNode node) {
- return (deviceService.getDevice(node.intBrId()) != null
- && deviceService.isAvailable(node.intBrId()));
+ private boolean isIntegrationBridgeCreated(CordVtnNode node) {
+ return deviceService.getDevice(node.integrationBridgeId()) != null &&
+ deviceService.isAvailable(node.integrationBridgeId());
}
- /**
- * Checks if tunnel interface exists.
- *
- * @param node cordvtn node
- * @return true if the interface exists, false otherwise
- */
- private boolean isTunnelIntfCreated(CordVtnNode node) {
- return deviceService.getPorts(node.intBrId())
- .stream()
- .filter(p -> portName(p).contains(DEFAULT_TUNNEL) &&
- p.isEnabled())
- .findAny().isPresent();
- }
-
- /**
- * Checks if data plane interface exists.
- *
- * @param node cordvtn node
- * @return true if the interface exists, false otherwise
- */
- private boolean isDataPlaneIntfAdded(CordVtnNode node) {
- return deviceService.getPorts(node.intBrId())
- .stream()
- .filter(p -> portName(p).contains(node.dpIntf()) &&
- p.isEnabled())
- .findAny().isPresent();
+ private boolean isIfaceCreated(CordVtnNode node, String ifaceName) {
+ if (Strings.isNullOrEmpty(ifaceName)) {
+ return false;
+ }
+ return deviceService.getPorts(node.integrationBridgeId()).stream()
+ .filter(p -> portName(p).contains(ifaceName) &&
+ p.isEnabled())
+ .findAny()
+ .isPresent();
}
/**
@@ -740,12 +613,12 @@
return false;
}
- Set<IpAddress> intBrIps = getCurrentIps(session, DEFAULT_BRIDGE);
- boolean result = getCurrentIps(session, node.dpIntf()).isEmpty() &&
- isInterfaceUp(session, node.dpIntf()) &&
- intBrIps.contains(node.dpIp().ip()) &&
+ Set<IpAddress> intBrIps = getCurrentIps(session, INTEGRATION_BRIDGE);
+ boolean result = getCurrentIps(session, node.dataIface()).isEmpty() &&
+ isInterfaceUp(session, node.dataIface()) &&
+ intBrIps.contains(node.dataIp().ip()) &&
intBrIps.contains(node.localMgmtIp().ip()) &&
- isInterfaceUp(session, DEFAULT_BRIDGE);
+ isInterfaceUp(session, INTEGRATION_BRIDGE);
disconnect(session);
return result;
@@ -762,16 +635,6 @@
}
/**
- * Returns connect point of a given host.
- *
- * @param host host
- * @return connect point
- */
- private ConnectPoint connectPoint(Host host) {
- return new ConnectPoint(host.location().deviceId(), host.location().port());
- }
-
- /**
* Returns cordvtn node associated with a given OVSDB device.
*
* @param ovsdbId OVSDB device id
@@ -791,7 +654,7 @@
*/
private CordVtnNode nodeByBridgeId(DeviceId bridgeId) {
return getNodes().stream()
- .filter(node -> node.intBrId().equals(bridgeId))
+ .filter(node -> node.integrationBridgeId().equals(bridgeId))
.findFirst().orElse(null);
}
@@ -802,7 +665,7 @@
* @return port name
*/
private String portName(Port port) {
- return port.annotations().value("portName");
+ return port.annotations().value(PORT_NAME);
}
private class OvsdbHandler implements ConnectionHandler<Device> {
@@ -819,10 +682,8 @@
@Override
public void disconnected(Device device) {
- if (!deviceService.isAvailable(device.id())) {
- log.debug("Device {} is disconnected", device.id());
- adminService.removeDevice(device.id());
- }
+ log.debug("Device {} is disconnected", device.id());
+ adminService.removeDevice(device.id());
}
}
@@ -842,7 +703,7 @@
public void disconnected(Device device) {
CordVtnNode node = nodeByBridgeId(device.id());
if (node != null) {
- log.debug("Integration Bridge is disconnected from {}", node.hostname());
+ log.warn("Integration Bridge is disconnected from {}", node.hostname());
setNodeState(node, NodeState.INCOMPLETE);
}
}
@@ -869,9 +730,9 @@
if (isNodeStateComplete(node)) {
instanceService.addInstance(connectPoint(port));
} else {
- log.debug("VM is detected on incomplete node, ignore it.", portName);
+ log.warn("VM is detected on incomplete node, ignore it.", portName);
}
- } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.dpIntf())) {
+ } else if (node.systemIfaces().contains(portName)) {
setNodeState(node, getNodeState(node));
}
}
@@ -897,9 +758,9 @@
if (isNodeStateComplete(node)) {
instanceService.removeInstance(connectPoint(port));
} else {
- log.debug("VM is vanished from incomplete node, ignore it.", portName);
+ log.warn("VM is vanished from incomplete node, ignore it.", portName);
}
- } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.dpIntf())) {
+ } else if (node.systemIfaces().contains(portName)) {
setNodeState(node, NodeState.INCOMPLETE);
}
}
diff --git a/src/main/java/org/opencord/cordvtn/impl/CordVtnPipeline.java b/src/main/java/org/opencord/cordvtn/impl/CordVtnPipeline.java
index 8aa0946..2aa9f1f 100644
--- a/src/main/java/org/opencord/cordvtn/impl/CordVtnPipeline.java
+++ b/src/main/java/org/opencord/cordvtn/impl/CordVtnPipeline.java
@@ -115,26 +115,26 @@
* Installs table miss rule to a give device.
*
* @param node cordvtn node
- * @param dpPort data plane port number
+ * @param dataPort data plane port number
* @param tunnelPort tunnel port number
*/
- public void initPipeline(CordVtnNode node, PortNumber dpPort, PortNumber tunnelPort) {
+ public void initPipeline(CordVtnNode node, PortNumber dataPort, PortNumber tunnelPort) {
checkNotNull(node);
- processTableZero(node.intBrId(), dpPort, node.dpIp().ip());
- processInPortTable(node.intBrId(), tunnelPort, dpPort);
- processAccessTypeTable(node.intBrId(), dpPort);
- processVlanTable(node.intBrId(), dpPort);
+ processTableZero(node.integrationBridgeId(), dataPort, node.dataIp().ip());
+ processInPortTable(node.integrationBridgeId(), tunnelPort, dataPort);
+ processAccessTypeTable(node.integrationBridgeId(), dataPort);
+ processVlanTable(node.integrationBridgeId(), dataPort);
}
- private void processTableZero(DeviceId deviceId, PortNumber dpPort, IpAddress dpIp) {
+ private void processTableZero(DeviceId deviceId, PortNumber dataPort, IpAddress dataIp) {
// take vxlan packet out onto the physical port
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchInPort(PortNumber.LOCAL)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(dpPort)
+ .setOutput(dataPort)
.build();
FlowRule flowRule = DefaultFlowRule.builder()
@@ -151,7 +151,7 @@
// take a vxlan encap'd packet through the Linux stack
selector = DefaultTrafficSelector.builder()
- .matchInPort(dpPort)
+ .matchInPort(dataPort)
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT))
@@ -175,9 +175,9 @@
// take a packet to the data plane ip through Linux stack
selector = DefaultTrafficSelector.builder()
- .matchInPort(dpPort)
+ .matchInPort(dataPort)
.matchEthType(Ethernet.TYPE_IPV4)
- .matchIPDst(dpIp.toIpPrefix())
+ .matchIPDst(dataIp.toIpPrefix())
.build();
treatment = DefaultTrafficTreatment.builder()
@@ -198,9 +198,9 @@
// take an arp packet from physical through Linux stack
selector = DefaultTrafficSelector.builder()
- .matchInPort(dpPort)
+ .matchInPort(dataPort)
.matchEthType(Ethernet.TYPE_ARP)
- .matchArpTpa(dpIp.getIp4Address())
+ .matchArpTpa(dataIp.getIp4Address())
.build();
treatment = DefaultTrafficTreatment.builder()
@@ -261,7 +261,7 @@
processFlowRule(true, flowRule);
}
- private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber dpPort) {
+ private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber dataPort) {
checkNotNull(tunnelPort);
TrafficSelector selector = DefaultTrafficSelector.builder()
@@ -285,7 +285,7 @@
processFlowRule(true, flowRule);
selector = DefaultTrafficSelector.builder()
- .matchInPort(dpPort)
+ .matchInPort(dataPort)
.build();
treatment = DefaultTrafficTreatment.builder()
@@ -305,12 +305,12 @@
processFlowRule(true, flowRule);
}
- private void processAccessTypeTable(DeviceId deviceId, PortNumber dpPort) {
+ private void processAccessTypeTable(DeviceId deviceId, PortNumber dataPort) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(dpPort)
+ .setOutput(dataPort)
.build();
FlowRule flowRule = DefaultFlowRule.builder()
@@ -326,7 +326,7 @@
processFlowRule(true, flowRule);
}
- private void processVlanTable(DeviceId deviceId, PortNumber dpPort) {
+ private void processVlanTable(DeviceId deviceId, PortNumber dataPort) {
// for traffic going out to WAN, strip vid 500 and take through data plane interface
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchVlanId(VLAN_WAN)
@@ -334,7 +334,7 @@
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.popVlan()
- .setOutput(dpPort)
+ .setOutput(dataPort)
.build();
FlowRule flowRule = DefaultFlowRule.builder()
diff --git a/src/main/java/org/opencord/cordvtn/impl/DependencyManager.java b/src/main/java/org/opencord/cordvtn/impl/DependencyManager.java
index 2eb73db..eaebb69 100644
--- a/src/main/java/org/opencord/cordvtn/impl/DependencyManager.java
+++ b/src/main/java/org/opencord/cordvtn/impl/DependencyManager.java
@@ -157,7 +157,7 @@
GroupKey groupKey = getGroupKey(service.id());
Set<DeviceId> devices = nodeManager.completeNodes().stream()
- .map(CordVtnNode::intBrId)
+ .map(CordVtnNode::integrationBridgeId)
.collect(Collectors.toSet());
for (DeviceId deviceId : devices) {
@@ -217,7 +217,7 @@
Map<DeviceId, Set<PortNumber>> inPorts = Maps.newHashMap();
nodeManager.completeNodes().stream().forEach(node -> {
- DeviceId deviceId = node.intBrId();
+ DeviceId deviceId = node.integrationBridgeId();
GroupId groupId = createServiceGroup(deviceId, pService);
outGroups.put(deviceId, groupId);
@@ -279,7 +279,7 @@
.build();
nodeManager.completeNodes().stream().forEach(node -> {
- DeviceId deviceId = node.intBrId();
+ DeviceId deviceId = node.integrationBridgeId();
FlowRule flowRuleDirect = DefaultFlowRule.builder()
.fromApp(appId)
.withSelector(selector)
@@ -365,7 +365,7 @@
Set<Instance> instances) {
List<GroupBucket> buckets = Lists.newArrayList();
instances.stream().forEach(instance -> {
- Ip4Address tunnelIp = nodeManager.dpIp(instance.deviceId()).getIp4Address();
+ Ip4Address tunnelIp = nodeManager.dataIp(instance.deviceId()).getIp4Address();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (deviceId.equals(instance.deviceId())) {
diff --git a/src/main/java/org/opencord/cordvtn/impl/InstanceManager.java b/src/main/java/org/opencord/cordvtn/impl/InstanceManager.java
index ffbc9c9..2f73eee 100644
--- a/src/main/java/org/opencord/cordvtn/impl/InstanceManager.java
+++ b/src/main/java/org/opencord/cordvtn/impl/InstanceManager.java
@@ -69,6 +69,7 @@
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.dhcp.IpAssignment.AssignmentStatus.Option_RangeNotEnforced;
+import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.xosclient.api.VtnServiceApi.ServiceType.MANAGEMENT;
import static org.opencord.cordvtn.api.Constants.*;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/src/main/java/org/opencord/cordvtn/impl/RemoteIpCommandUtil.java b/src/main/java/org/opencord/cordvtn/impl/RemoteIpCommandUtil.java
index bd2d922..0be4fc4 100644
--- a/src/main/java/org/opencord/cordvtn/impl/RemoteIpCommandUtil.java
+++ b/src/main/java/org/opencord/cordvtn/impl/RemoteIpCommandUtil.java
@@ -204,7 +204,7 @@
* @param session session
*/
public static void disconnect(Session session) {
- if (session.isConnected()) {
+ if (session != null && session.isConnected()) {
session.disconnect();
}
}
diff --git a/src/main/java/org/opencord/cordvtn/impl/handler/DefaultInstanceHandler.java b/src/main/java/org/opencord/cordvtn/impl/handler/DefaultInstanceHandler.java
index 98673cf..a4ca067 100644
--- a/src/main/java/org/opencord/cordvtn/impl/handler/DefaultInstanceHandler.java
+++ b/src/main/java/org/opencord/cordvtn/impl/handler/DefaultInstanceHandler.java
@@ -152,7 +152,7 @@
}
private void dstIpRule(Instance instance, long vni, boolean install) {
- Ip4Address tunnelIp = nodeManager.dpIp(instance.deviceId()).getIp4Address();
+ Ip4Address tunnelIp = nodeManager.dataIp(instance.deviceId()).getIp4Address();
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
@@ -177,11 +177,12 @@
pipeline.processFlowRule(install, flowRule);
for (CordVtnNode node : nodeManager.completeNodes()) {
- if (node.intBrId().equals(instance.deviceId())) {
+ if (node.integrationBridgeId().equals(instance.deviceId())) {
continue;
}
- ExtensionTreatment tunnelDst = pipeline.tunnelDstTreatment(node.intBrId(), tunnelIp);
+ ExtensionTreatment tunnelDst =
+ pipeline.tunnelDstTreatment(node.integrationBridgeId(), tunnelIp);
if (tunnelDst == null) {
continue;
}
@@ -189,8 +190,8 @@
treatment = DefaultTrafficTreatment.builder()
.setEthDst(instance.mac())
.setTunnelId(vni)
- .extension(tunnelDst, node.intBrId())
- .setOutput(nodeManager.tunnelPort(node.intBrId()))
+ .extension(tunnelDst, node.integrationBridgeId())
+ .setOutput(nodeManager.tunnelPort(node.integrationBridgeId()))
.build();
flowRule = DefaultFlowRule.builder()
@@ -198,7 +199,7 @@
.withSelector(selector)
.withTreatment(treatment)
.withPriority(CordVtnPipeline.PRIORITY_DEFAULT)
- .forDevice(node.intBrId())
+ .forDevice(node.integrationBridgeId())
.forTable(CordVtnPipeline.TABLE_DST_IP)
.makePermanent()
.build();
@@ -248,7 +249,7 @@
.withSelector(selector)
.withTreatment(treatment)
.withPriority(CordVtnPipeline.PRIORITY_DEFAULT)
- .forDevice(node.intBrId())
+ .forDevice(node.integrationBridgeId())
.forTable(CordVtnPipeline.TABLE_ACCESS_TYPE)
.makePermanent()
.build();
@@ -273,7 +274,7 @@
.withSelector(selector)
.withTreatment(treatment)
.withPriority(CordVtnPipeline.PRIORITY_LOW)
- .forDevice(node.intBrId())
+ .forDevice(node.integrationBridgeId())
.forTable(CordVtnPipeline.TABLE_ACCESS_TYPE)
.makePermanent()
.build();
diff --git a/src/main/java/org/opencord/cordvtn/impl/handler/VsgInstanceHandler.java b/src/main/java/org/opencord/cordvtn/impl/handler/VsgInstanceHandler.java
index 1f96023..648c341 100644
--- a/src/main/java/org/opencord/cordvtn/impl/handler/VsgInstanceHandler.java
+++ b/src/main/java/org/opencord/cordvtn/impl/handler/VsgInstanceHandler.java
@@ -114,7 +114,7 @@
return;
}
populateVsgRules(vsgVm, getStag(vtnPort),
- nodeManager.dpPort(vsgVm.deviceId()),
+ nodeManager.dataPort(vsgVm.deviceId()),
vtnPort.addressPairs().keySet(),
true);
@@ -159,7 +159,7 @@
}
populateVsgRules(vsgVm, getStag(vtnPort),
- nodeManager.dpPort(vsgVm.deviceId()),
+ nodeManager.dataPort(vsgVm.deviceId()),
vtnPort.addressPairs().keySet(),
false);
}
@@ -229,11 +229,11 @@
instanceService.addNestedInstance(hostId, hostDesc);
}
- private void populateVsgRules(Instance vsgVm, VlanId stag, PortNumber dpPort,
+ private void populateVsgRules(Instance vsgVm, VlanId stag, PortNumber dataPort,
Set<IpAddress> vsgWanIps, boolean install) {
// for traffics with s-tag, strip the tag and take through the vSG VM
TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(dpPort)
+ .matchInPort(dataPort)
.matchVlanId(stag)
.build();
@@ -261,7 +261,7 @@
.build();
treatment = DefaultTrafficTreatment.builder()
- .setOutput(dpPort)
+ .setOutput(dataPort)
.build();
flowRule = DefaultFlowRule.builder()