Hyunsun Moon
Committed by Gerrit Code Review

CORD-524 Added a state to set data plane IP to br-int

Added new config fields
- SSH port, user, private key file
- localManagementIp for connection b/w a compute node and VM

Renamed some config fields and methods
- phyPortName is changed to dataPlaneIntf
- localIp is changed to dataPlaneIp
- ovsdbIp is changed to hostManagementIp and it is used to SSH as well
- checkXXX methods with boolean return are renamed to isXXX

Removed unnecessary OVSDB_CONNECTED state
Removed cordvtn-node-add CLI due to too many arguments

Change-Id: If5efb65fc58bfa8a10767047f01598dc2ac02a04
...@@ -265,7 +265,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -265,7 +265,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
265 SparseAnnotations annotations = DefaultAnnotations.builder() 265 SparseAnnotations annotations = DefaultAnnotations.builder()
266 .set(OPENSTACK_VM_ID, vPort.deviceId()) 266 .set(OPENSTACK_VM_ID, vPort.deviceId())
267 .set(SERVICE_ID, vPort.networkId()) 267 .set(SERVICE_ID, vPort.networkId())
268 - .set(LOCATION_IP, node.localIp().toString()) 268 + .set(LOCATION_IP, node.dpIp().ip().toString())
269 .build(); 269 .build();
270 270
271 HostDescription hostDesc = new DefaultHostDescription( 271 HostDescription hostDesc = new DefaultHostDescription(
......
...@@ -17,7 +17,6 @@ package org.onosproject.cordvtn; ...@@ -17,7 +17,6 @@ package org.onosproject.cordvtn;
17 17
18 import com.fasterxml.jackson.databind.JsonNode; 18 import com.fasterxml.jackson.databind.JsonNode;
19 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
20 -import org.onlab.packet.IpAddress;
21 import org.onlab.packet.MacAddress; 20 import org.onlab.packet.MacAddress;
22 import org.onlab.packet.TpPort; 21 import org.onlab.packet.TpPort;
23 import org.onosproject.core.ApplicationId; 22 import org.onosproject.core.ApplicationId;
...@@ -37,14 +36,19 @@ public class CordVtnConfig extends Config<ApplicationId> { ...@@ -37,14 +36,19 @@ public class CordVtnConfig extends Config<ApplicationId> {
37 36
38 protected final Logger log = getLogger(getClass()); 37 protected final Logger log = getLogger(getClass());
39 38
39 + public static final String GATEWAY_MAC = "gatewayMac";
40 + public static final String LOCAL_MANAGEMENT_IP = "localManagementIp";
41 + public static final String OVSDB_PORT = "ovsdbPort";
42 + public static final String SSH_PORT = "sshPort";
43 + public static final String SSH_USER = "sshUser";
44 + public static final String SSH_KEY_FILE = "sshKeyFile";
40 public static final String CORDVTN_NODES = "nodes"; 45 public static final String CORDVTN_NODES = "nodes";
46 +
41 public static final String HOSTNAME = "hostname"; 47 public static final String HOSTNAME = "hostname";
42 - public static final String OVSDB_IP = "ovsdbIp"; 48 + public static final String HOST_MANAGEMENT_IP = "hostManagementIp";
43 - public static final String OVSDB_PORT = "ovsdbPort"; 49 + public static final String DATA_PLANE_IP = "dataPlaneIp";
50 + public static final String DATA_PLANE_INTF = "dataPlaneIntf";
44 public static final String BRIDGE_ID = "bridgeId"; 51 public static final String BRIDGE_ID = "bridgeId";
45 - public static final String PHYSICAL_PORT_NAME = "phyPortName";
46 - public static final String LOCAL_IP = "localIp";
47 - public static final String GATEWAY_MAC = "gatewayMac";
48 52
49 /** 53 /**
50 * Returns the set of nodes read from network config. 54 * Returns the set of nodes read from network config.
...@@ -58,13 +62,19 @@ public class CordVtnConfig extends Config<ApplicationId> { ...@@ -58,13 +62,19 @@ public class CordVtnConfig extends Config<ApplicationId> {
58 if (jsonNodes == null) { 62 if (jsonNodes == null) {
59 return null; 63 return null;
60 } 64 }
61 - jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( 65 +
66 + jsonNodes.forEach(jsonNode -> {
67 + try {
68 + nodes.add(new CordVtnNodeConfig(
62 jsonNode.path(HOSTNAME).asText(), 69 jsonNode.path(HOSTNAME).asText(),
63 - IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), 70 + NetworkAddress.valueOf(jsonNode.path(HOST_MANAGEMENT_IP).asText()),
64 - TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), 71 + NetworkAddress.valueOf(jsonNode.path(DATA_PLANE_IP).asText()),
65 - DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()), 72 + jsonNode.path(DATA_PLANE_INTF).asText(),
66 - jsonNode.path(PHYSICAL_PORT_NAME).asText(), 73 + DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())));
67 - IpAddress.valueOf(jsonNode.path(LOCAL_IP).asText())))); 74 + } catch (IllegalArgumentException | NullPointerException e) {
75 + log.error("Failed to read {}", e.toString());
76 + }
77 + });
68 78
69 return nodes; 79 return nodes;
70 } 80 }
...@@ -89,25 +99,108 @@ public class CordVtnConfig extends Config<ApplicationId> { ...@@ -89,25 +99,108 @@ public class CordVtnConfig extends Config<ApplicationId> {
89 } 99 }
90 100
91 /** 101 /**
102 + * Returns local management network address.
103 + *
104 + * @return network address
105 + */
106 + public NetworkAddress localMgmtIp() {
107 + JsonNode jsonNode = object.get(LOCAL_MANAGEMENT_IP);
108 + if (jsonNode == null) {
109 + return null;
110 + }
111 +
112 + try {
113 + return NetworkAddress.valueOf(jsonNode.asText());
114 + } catch (IllegalArgumentException e) {
115 + log.error("Wrong address format {}", jsonNode.asText());
116 + return null;
117 + }
118 + }
119 +
120 + /**
121 + * Returns the port number used for OVSDB connection.
122 + *
123 + * @return port number, or null
124 + */
125 + public TpPort ovsdbPort() {
126 + JsonNode jsonNode = object.get(OVSDB_PORT);
127 + if (jsonNode == null) {
128 + return null;
129 + }
130 +
131 + try {
132 + return TpPort.tpPort(jsonNode.asInt());
133 + } catch (IllegalArgumentException e) {
134 + log.error("Wrong TCP port format {}", jsonNode.asText());
135 + return null;
136 + }
137 + }
138 +
139 + /**
140 + * Returns the port number used for SSH connection.
141 + *
142 + * @return port number, or null
143 + */
144 + public TpPort sshPort() {
145 + JsonNode jsonNode = object.get(SSH_PORT);
146 + if (jsonNode == null) {
147 + return null;
148 + }
149 +
150 + try {
151 + return TpPort.tpPort(jsonNode.asInt());
152 + } catch (IllegalArgumentException e) {
153 + log.error("Wrong TCP port format {}", jsonNode.asText());
154 + return null;
155 + }
156 + }
157 +
158 + /**
159 + * Returns the user name for SSH connection.
160 + *
161 + * @return user name, or null
162 + */
163 + public String sshUser() {
164 + JsonNode jsonNode = object.get(SSH_USER);
165 + if (jsonNode == null) {
166 + return null;
167 + }
168 +
169 + return jsonNode.asText();
170 + }
171 +
172 + /**
173 + * Returns the private key file for SSH connection.
174 + *
175 + * @return file path, or null
176 + */
177 + public String sshKeyFile() {
178 + JsonNode jsonNode = object.get(SSH_KEY_FILE);
179 + if (jsonNode == null) {
180 + return null;
181 + }
182 +
183 + return jsonNode.asText();
184 + }
185 +
186 + /**
92 * Configuration for CordVtn node. 187 * Configuration for CordVtn node.
93 */ 188 */
94 public static class CordVtnNodeConfig { 189 public static class CordVtnNodeConfig {
95 190
96 private final String hostname; 191 private final String hostname;
97 - private final IpAddress ovsdbIp; 192 + private final NetworkAddress hostMgmtIp;
98 - private final TpPort ovsdbPort; 193 + private final NetworkAddress dpIp;
194 + private final String dpIntf;
99 private final DeviceId bridgeId; 195 private final DeviceId bridgeId;
100 - private final String phyPortName;
101 - private final IpAddress localIp;
102 196
103 - public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, 197 + public CordVtnNodeConfig(String hostname, NetworkAddress hostMgmtIp, NetworkAddress dpIp,
104 - DeviceId bridgeId, String phyPortName, IpAddress localIp) { 198 + String dpIntf, DeviceId bridgeId) {
105 this.hostname = checkNotNull(hostname); 199 this.hostname = checkNotNull(hostname);
106 - this.ovsdbIp = checkNotNull(ovsdbIp); 200 + this.hostMgmtIp = checkNotNull(hostMgmtIp);
107 - this.ovsdbPort = checkNotNull(ovsdbPort); 201 + this.dpIp = checkNotNull(dpIp);
202 + this.dpIntf = checkNotNull(dpIntf);
108 this.bridgeId = checkNotNull(bridgeId); 203 this.bridgeId = checkNotNull(bridgeId);
109 - this.phyPortName = checkNotNull(phyPortName);
110 - this.localIp = checkNotNull(localIp);
111 } 204 }
112 205
113 /** 206 /**
...@@ -120,48 +213,39 @@ public class CordVtnConfig extends Config<ApplicationId> { ...@@ -120,48 +213,39 @@ public class CordVtnConfig extends Config<ApplicationId> {
120 } 213 }
121 214
122 /** 215 /**
123 - * Returns OVSDB ip address of the node. 216 + * Returns the host management network address of the node.
124 - *
125 - * @return OVSDB server IP address
126 - */
127 - public IpAddress ovsdbIp() {
128 - return this.ovsdbIp;
129 - }
130 -
131 - /**
132 - * Returns OVSDB port number of the node.
133 * 217 *
134 - * @return port number 218 + * @return management network address
135 */ 219 */
136 - public TpPort ovsdbPort() { 220 + public NetworkAddress hostMgmtIp() {
137 - return this.ovsdbPort; 221 + return this.hostMgmtIp;
138 } 222 }
139 223
140 /** 224 /**
141 - * Returns integration bridge id of the node. 225 + * Returns the data plane network address.
142 * 226 *
143 - * @return device id 227 + * @return network address
144 */ 228 */
145 - public DeviceId bridgeId() { 229 + public NetworkAddress dpIp() {
146 - return this.bridgeId; 230 + return this.dpIp;
147 } 231 }
148 232
149 /** 233 /**
150 - * Returns physical port name. 234 + * Returns the data plane interface name.
151 * 235 *
152 - * @return physical port name 236 + * @return interface name
153 */ 237 */
154 - public String phyPortName() { 238 + public String dpIntf() {
155 - return this.phyPortName; 239 + return this.dpIntf;
156 } 240 }
157 241
158 /** 242 /**
159 - * Returns local IP address. 243 + * Returns integration bridge id of the node.
160 * 244 *
161 - * @return ip address 245 + * @return device id
162 */ 246 */
163 - public IpAddress localIp() { 247 + public DeviceId bridgeId() {
164 - return this.localIp; 248 + return this.bridgeId;
165 } 249 }
166 } 250 }
167 } 251 }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.cordvtn; 16 package org.onosproject.cordvtn;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 -import org.onlab.packet.IpAddress;
20 import org.onlab.packet.TpPort; 19 import org.onlab.packet.TpPort;
21 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
22 21
...@@ -31,11 +30,13 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -31,11 +30,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
31 public final class CordVtnNode { 30 public final class CordVtnNode {
32 31
33 private final String hostname; 32 private final String hostname;
34 - private final IpAddress ovsdbIp; 33 + private final NetworkAddress hostMgmtIp;
34 + private final NetworkAddress localMgmtIp;
35 + private final NetworkAddress dpIp;
35 private final TpPort ovsdbPort; 36 private final TpPort ovsdbPort;
37 + private final SshAccessInfo sshInfo;
36 private final DeviceId bridgeId; 38 private final DeviceId bridgeId;
37 - private final String phyPortName; 39 + private final String dpIntf;
38 - private final IpAddress localIp;
39 40
40 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR = 41 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
41 (node1, node2) -> node1.hostname().compareTo(node2.hostname()); 42 (node1, node2) -> node1.hostname().compareTo(node2.hostname());
...@@ -44,33 +45,65 @@ public final class CordVtnNode { ...@@ -44,33 +45,65 @@ public final class CordVtnNode {
44 * Creates a new node. 45 * Creates a new node.
45 * 46 *
46 * @param hostname hostname 47 * @param hostname hostname
47 - * @param ovsdbIp OVSDB server IP address 48 + * @param hostMgmtIp host management network address
48 - * @param ovsdbPort OVSDB server port number 49 + * @param localMgmtIp local management network address
50 + * @param dpIp data plane network address
51 + * @param ovsdbPort port number for OVSDB connection
52 + * @param sshInfo SSH access information
49 * @param bridgeId integration bridge identifier 53 * @param bridgeId integration bridge identifier
50 - * @param phyPortName physical port name 54 + * @param dpIntf data plane interface name
51 - * @param localIp local ip address of data plane
52 */ 55 */
53 - public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, 56 + public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp,
54 - DeviceId bridgeId, String phyPortName, IpAddress localIp) { 57 + NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo,
55 - this.hostname = checkNotNull(hostname); 58 + DeviceId bridgeId, String dpIntf) {
56 - this.ovsdbIp = checkNotNull(ovsdbIp); 59 + this.hostname = checkNotNull(hostname, "hostname cannot be null");
57 - this.ovsdbPort = checkNotNull(ovsdbPort); 60 + this.hostMgmtIp = checkNotNull(hostMgmtIp, "hostMgmtIp cannot be null");
58 - this.bridgeId = checkNotNull(bridgeId); 61 + this.localMgmtIp = checkNotNull(localMgmtIp, "localMgmtIp cannot be null");
59 - this.phyPortName = checkNotNull(phyPortName); 62 + this.dpIp = checkNotNull(dpIp, "dpIp cannot be null");
60 - this.localIp = checkNotNull(localIp); 63 + this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null");
64 + this.sshInfo = checkNotNull(sshInfo, "sshInfo cannot be null");
65 + this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null");
66 + this.dpIntf = checkNotNull(dpIntf, "dpIntf cannot be null");
61 } 67 }
62 68
63 /** 69 /**
64 - * Returns the OVSDB server IP address. 70 + * Returns the hostname.
71 + *
72 + * @return hostname
73 + */
74 + public String hostname() {
75 + return this.hostname;
76 + }
77 +
78 + /**
79 + * Returns the host management network address.
80 + *
81 + * @return network address
82 + */
83 + public NetworkAddress hostMgmtIp() {
84 + return this.hostMgmtIp;
85 + }
86 +
87 + /**
88 + * Returns the local management network address.
65 * 89 *
66 - * @return ip address 90 + * @return network address
67 */ 91 */
68 - public IpAddress ovsdbIp() { 92 + public NetworkAddress localMgmtIp() {
69 - return this.ovsdbIp; 93 + return this.localMgmtIp;
70 } 94 }
71 95
72 /** 96 /**
73 - * Returns the OVSDB server port number. 97 + * Returns the data plane network address.
98 + *
99 + * @return network address
100 + */
101 + public NetworkAddress dpIp() {
102 + return this.dpIp;
103 + }
104 +
105 + /**
106 + * Returns the port number used for OVSDB connection.
74 * 107 *
75 * @return port number 108 * @return port number
76 */ 109 */
...@@ -79,12 +112,12 @@ public final class CordVtnNode { ...@@ -79,12 +112,12 @@ public final class CordVtnNode {
79 } 112 }
80 113
81 /** 114 /**
82 - * Returns the hostname. 115 + * Returns the SSH access information.
83 * 116 *
84 - * @return hostname 117 + * @return ssh access information
85 */ 118 */
86 - public String hostname() { 119 + public SshAccessInfo sshInfo() {
87 - return this.hostname; 120 + return this.sshInfo;
88 } 121 }
89 122
90 /** 123 /**
...@@ -102,25 +135,16 @@ public final class CordVtnNode { ...@@ -102,25 +135,16 @@ public final class CordVtnNode {
102 * @return device id 135 * @return device id
103 */ 136 */
104 public DeviceId ovsdbId() { 137 public DeviceId ovsdbId() {
105 - return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString()); 138 + return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString());
106 - }
107 -
108 - /**
109 - * Returns physical port name.
110 - *
111 - * @return physical port name
112 - */
113 - public String phyPortName() {
114 - return this.phyPortName;
115 } 139 }
116 140
117 /** 141 /**
118 - * Returns local IP address. 142 + * Returns data plane interface name.
119 * 143 *
120 - * @return ip address 144 + * @return data plane interface name
121 */ 145 */
122 - public IpAddress localIp() { 146 + public String dpIntf() {
123 - return this.localIp; 147 + return this.dpIntf;
124 } 148 }
125 149
126 @Override 150 @Override
...@@ -129,6 +153,8 @@ public final class CordVtnNode { ...@@ -129,6 +153,8 @@ public final class CordVtnNode {
129 return true; 153 return true;
130 } 154 }
131 155
156 + // hostname here is a network hostname and it is intended to be
157 + // unique throughout the service.
132 if (obj instanceof CordVtnNode) { 158 if (obj instanceof CordVtnNode) {
133 CordVtnNode that = (CordVtnNode) obj; 159 CordVtnNode that = (CordVtnNode) obj;
134 if (Objects.equals(hostname, that.hostname)) { 160 if (Objects.equals(hostname, that.hostname)) {
...@@ -146,12 +172,14 @@ public final class CordVtnNode { ...@@ -146,12 +172,14 @@ public final class CordVtnNode {
146 @Override 172 @Override
147 public String toString() { 173 public String toString() {
148 return MoreObjects.toStringHelper(getClass()) 174 return MoreObjects.toStringHelper(getClass())
149 - .add("host", hostname) 175 + .add("hostname", hostname)
150 - .add("ip", ovsdbIp) 176 + .add("hostMgmtIp", hostMgmtIp)
177 + .add("localMgmtIp", localMgmtIp)
178 + .add("dpIp", dpIp)
151 .add("port", ovsdbPort) 179 .add("port", ovsdbPort)
180 + .add("sshInfo", sshInfo)
152 .add("bridgeId", bridgeId) 181 .add("bridgeId", bridgeId)
153 - .add("phyPortName", phyPortName) 182 + .add("dpIntf", dpIntf)
154 - .add("localIp", localIp)
155 .toString(); 183 .toString();
156 } 184 }
157 } 185 }
......
...@@ -16,12 +16,15 @@ ...@@ -16,12 +16,15 @@
16 package org.onosproject.cordvtn; 16 package org.onosproject.cordvtn;
17 17
18 import com.google.common.collect.Sets; 18 import com.google.common.collect.Sets;
19 +import com.jcraft.jsch.Session;
19 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 +import org.onlab.packet.IpAddress;
27 +import org.onlab.packet.TpPort;
25 import org.onlab.util.ItemNotFoundException; 28 import org.onlab.util.ItemNotFoundException;
26 import org.onlab.util.KryoNamespace; 29 import org.onlab.util.KryoNamespace;
27 import org.onosproject.cluster.ClusterService; 30 import org.onosproject.cluster.ClusterService;
...@@ -67,6 +70,7 @@ import java.util.ArrayList; ...@@ -67,6 +70,7 @@ import java.util.ArrayList;
67 import java.util.HashMap; 70 import java.util.HashMap;
68 import java.util.List; 71 import java.util.List;
69 import java.util.Map; 72 import java.util.Map;
73 +import java.util.Set;
70 import java.util.concurrent.ExecutorService; 74 import java.util.concurrent.ExecutorService;
71 75
72 import static com.google.common.base.Preconditions.checkNotNull; 76 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -89,8 +93,11 @@ public class CordVtnNodeManager { ...@@ -89,8 +93,11 @@ public class CordVtnNodeManager {
89 93
90 private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() 94 private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder()
91 .register(KryoNamespaces.API) 95 .register(KryoNamespaces.API)
96 + .register(KryoNamespaces.MISC)
92 .register(CordVtnNode.class) 97 .register(CordVtnNode.class)
93 - .register(NodeState.class); 98 + .register(NodeState.class)
99 + .register(SshAccessInfo.class)
100 + .register(NetworkAddress.class);
94 101
95 private static final String DEFAULT_BRIDGE = "br-int"; 102 private static final String DEFAULT_BRIDGE = "br-int";
96 private static final String DEFAULT_TUNNEL = "vxlan"; 103 private static final String DEFAULT_TUNNEL = "vxlan";
...@@ -167,13 +174,7 @@ public class CordVtnNodeManager { ...@@ -167,13 +174,7 @@ public class CordVtnNodeManager {
167 INIT { 174 INIT {
168 @Override 175 @Override
169 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { 176 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
170 - nodeManager.connectOvsdb(node); 177 + if (!nodeManager.isOvsdbConnected(node)) {
171 - }
172 - },
173 - OVSDB_CONNECTED {
174 - @Override
175 - public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
176 - if (!nodeManager.getOvsdbConnectionState(node)) {
177 nodeManager.connectOvsdb(node); 178 nodeManager.connectOvsdb(node);
178 } else { 179 } else {
179 nodeManager.createIntegrationBridge(node); 180 nodeManager.createIntegrationBridge(node);
...@@ -183,21 +184,18 @@ public class CordVtnNodeManager { ...@@ -183,21 +184,18 @@ public class CordVtnNodeManager {
183 BRIDGE_CREATED { 184 BRIDGE_CREATED {
184 @Override 185 @Override
185 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { 186 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
186 - if (!nodeManager.getOvsdbConnectionState(node)) { 187 + if (!nodeManager.isOvsdbConnected(node)) {
187 nodeManager.connectOvsdb(node); 188 nodeManager.connectOvsdb(node);
188 } else { 189 } else {
189 nodeManager.createTunnelInterface(node); 190 nodeManager.createTunnelInterface(node);
191 + nodeManager.addDataPlaneInterface(node);
190 } 192 }
191 } 193 }
192 }, 194 },
193 - TUNNEL_INTERFACE_CREATED { 195 + PORTS_ADDED {
194 @Override 196 @Override
195 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { 197 public void process(CordVtnNodeManager nodeManager, CordVtnNode node) {
196 - if (!nodeManager.getOvsdbConnectionState(node)) { 198 + nodeManager.setIpAddress(node);
197 - nodeManager.connectOvsdb(node);
198 - } else {
199 - nodeManager.createPhyInterface(node);
200 - }
201 } 199 }
202 200
203 }, 201 },
...@@ -213,8 +211,6 @@ public class CordVtnNodeManager { ...@@ -213,8 +211,6 @@ public class CordVtnNodeManager {
213 } 211 }
214 }; 212 };
215 213
216 - // TODO Add physical port add state
217 -
218 public abstract void process(CordVtnNodeManager nodeManager, CordVtnNode node); 214 public abstract void process(CordVtnNodeManager nodeManager, CordVtnNode node);
219 } 215 }
220 216
...@@ -256,7 +252,7 @@ public class CordVtnNodeManager { ...@@ -256,7 +252,7 @@ public class CordVtnNodeManager {
256 public void addNode(CordVtnNode node) { 252 public void addNode(CordVtnNode node) {
257 checkNotNull(node); 253 checkNotNull(node);
258 254
259 - nodeStore.putIfAbsent(node, checkNodeState(node)); 255 + nodeStore.putIfAbsent(node, getNodeState(node));
260 initNode(node); 256 initNode(node);
261 } 257 }
262 258
...@@ -268,7 +264,7 @@ public class CordVtnNodeManager { ...@@ -268,7 +264,7 @@ public class CordVtnNodeManager {
268 public void deleteNode(CordVtnNode node) { 264 public void deleteNode(CordVtnNode node) {
269 checkNotNull(node); 265 checkNotNull(node);
270 266
271 - if (getOvsdbConnectionState(node)) { 267 + if (isOvsdbConnected(node)) {
272 disconnectOvsdb(node); 268 disconnectOvsdb(node);
273 } 269 }
274 270
...@@ -288,7 +284,7 @@ public class CordVtnNodeManager { ...@@ -288,7 +284,7 @@ public class CordVtnNodeManager {
288 return; 284 return;
289 } 285 }
290 286
291 - NodeState state = checkNodeState(node); 287 + NodeState state = getNodeState(node);
292 state.process(this, node); 288 state.process(this, node);
293 } 289 }
294 290
...@@ -298,20 +294,13 @@ public class CordVtnNodeManager { ...@@ -298,20 +294,13 @@ public class CordVtnNodeManager {
298 * @param node cordvtn node 294 * @param node cordvtn node
299 * @return true if initial node setup is completed, otherwise false 295 * @return true if initial node setup is completed, otherwise false
300 */ 296 */
301 - public boolean getNodeInitState(CordVtnNode node) { 297 + public boolean isNodeInitComplete(CordVtnNode node) {
302 checkNotNull(node); 298 checkNotNull(node);
303 - 299 + return nodeStore.containsKey(node) && getNodeState(node).equals(NodeState.COMPLETE);
304 - NodeState state = getNodeState(node);
305 - return state != null && state.equals(NodeState.COMPLETE);
306 } 300 }
307 301
308 /** 302 /**
309 * Returns detailed node initialization state. 303 * Returns detailed node initialization state.
310 - * Return string includes the following information.
311 - *
312 - * Integration bridge created/connected: OK or NO
313 - * VXLAN interface created: OK or NO
314 - * Physical interface added: OK or NO
315 * 304 *
316 * @param node cordvtn node 305 * @param node cordvtn node
317 * @return string including detailed node init state 306 * @return string including detailed node init state
...@@ -319,19 +308,34 @@ public class CordVtnNodeManager { ...@@ -319,19 +308,34 @@ public class CordVtnNodeManager {
319 public String checkNodeInitState(CordVtnNode node) { 308 public String checkNodeInitState(CordVtnNode node) {
320 checkNotNull(node); 309 checkNotNull(node);
321 310
322 - NodeState state = getNodeState(node); 311 + if (!nodeStore.containsKey(node)) {
323 - if (state == null) { 312 + log.warn("Node {} does not exist, add node first", node.hostname());
324 - log.warn("Failed to get init state of {}", node.hostname());
325 return null; 313 return null;
326 } 314 }
327 315
316 + Session session = RemoteIpCommandUtil.connect(node.sshInfo());
317 + if (session == null) {
318 + log.debug("Failed to SSH to {}", node.hostname());
319 + return null;
320 + }
321 +
322 + Set<IpAddress> intBrIps = RemoteIpCommandUtil.getCurrentIps(session, DEFAULT_BRIDGE);
328 String result = String.format( 323 String result = String.format(
329 "Integration bridge created/connected : %s (%s)%n" + 324 "Integration bridge created/connected : %s (%s)%n" +
330 "VXLAN interface created : %s%n" + 325 "VXLAN interface created : %s%n" +
331 - "Physical interface added : %s (%s)", 326 + "Data plane interface added : %s (%s)%n" +
332 - checkIntegrationBridge(node) ? OK : NO, DEFAULT_BRIDGE, 327 + "IP flushed from %s : %s%n" +
333 - checkTunnelInterface(node) ? OK : NO, 328 + "Data plane IP added to br-int : %s (%s)%n" +
334 - checkPhyInterface(node) ? OK : NO, node.phyPortName()); 329 + "Local management IP added to br-int : %s (%s)",
330 + isBrIntCreated(node) ? OK : NO, DEFAULT_BRIDGE,
331 + isTunnelIntfCreated(node) ? OK : NO,
332 + isDataPlaneIntfAdded(node) ? OK : NO, node.dpIntf(),
333 + node.dpIntf(),
334 + RemoteIpCommandUtil.getCurrentIps(session, node.dpIntf()).isEmpty() ? OK : NO,
335 + intBrIps.contains(node.dpIp().ip()) ? OK : NO, node.dpIp().cidr(),
336 + intBrIps.contains(node.localMgmtIp().ip()) ? OK : NO, node.localMgmtIp().cidr());
337 +
338 + RemoteIpCommandUtil.disconnect(session);
335 339
336 return result; 340 return result;
337 } 341 }
...@@ -381,23 +385,6 @@ public class CordVtnNodeManager { ...@@ -381,23 +385,6 @@ public class CordVtnNodeManager {
381 } 385 }
382 386
383 /** 387 /**
384 - * Returns state of a given cordvtn node.
385 - *
386 - * @param node cordvtn node
387 - * @return node state, or null if no such node exists
388 - */
389 - private NodeState getNodeState(CordVtnNode node) {
390 - checkNotNull(node);
391 -
392 - try {
393 - return nodeStore.get(node).value();
394 - } catch (NullPointerException e) {
395 - log.error("Failed to get state of {}", node.hostname());
396 - return null;
397 - }
398 - }
399 -
400 - /**
401 * Sets a new state for a given cordvtn node. 388 * Sets a new state for a given cordvtn node.
402 * 389 *
403 * @param node cordvtn node 390 * @param node cordvtn node
...@@ -418,18 +405,16 @@ public class CordVtnNodeManager { ...@@ -418,18 +405,16 @@ public class CordVtnNodeManager {
418 * @param node cordvtn node 405 * @param node cordvtn node
419 * @return node state 406 * @return node state
420 */ 407 */
421 - private NodeState checkNodeState(CordVtnNode node) { 408 + private NodeState getNodeState(CordVtnNode node) {
422 checkNotNull(node); 409 checkNotNull(node);
423 410
424 - if (checkIntegrationBridge(node) && checkTunnelInterface(node) && 411 + if (isBrIntCreated(node) && isTunnelIntfCreated(node) &&
425 - checkPhyInterface(node)) { 412 + isDataPlaneIntfAdded(node) && isIpAddressSet(node)) {
426 return NodeState.COMPLETE; 413 return NodeState.COMPLETE;
427 - } else if (checkTunnelInterface(node)) { 414 + } else if (isDataPlaneIntfAdded(node) && isTunnelIntfCreated(node)) {
428 - return NodeState.TUNNEL_INTERFACE_CREATED; 415 + return NodeState.PORTS_ADDED;
429 - } else if (checkIntegrationBridge(node)) { 416 + } else if (isBrIntCreated(node)) {
430 return NodeState.BRIDGE_CREATED; 417 return NodeState.BRIDGE_CREATED;
431 - } else if (getOvsdbConnectionState(node)) {
432 - return NodeState.OVSDB_CONNECTED;
433 } else { 418 } else {
434 return NodeState.INIT; 419 return NodeState.INIT;
435 } 420 }
...@@ -445,7 +430,7 @@ public class CordVtnNodeManager { ...@@ -445,7 +430,7 @@ public class CordVtnNodeManager {
445 private void postInit(CordVtnNode node) { 430 private void postInit(CordVtnNode node) {
446 disconnectOvsdb(node); 431 disconnectOvsdb(node);
447 432
448 - ruleInstaller.init(node.intBrId(), node.phyPortName(), node.localIp()); 433 + ruleInstaller.init(node.intBrId(), node.dpIntf(), node.dpIp().ip());
449 434
450 // add existing hosts to the service 435 // add existing hosts to the service
451 deviceService.getPorts(node.intBrId()).stream() 436 deviceService.getPorts(node.intBrId()).stream()
...@@ -480,7 +465,7 @@ public class CordVtnNodeManager { ...@@ -480,7 +465,7 @@ public class CordVtnNodeManager {
480 * @param node cordvtn node 465 * @param node cordvtn node
481 * @return true if it is connected, false otherwise 466 * @return true if it is connected, false otherwise
482 */ 467 */
483 - private boolean getOvsdbConnectionState(CordVtnNode node) { 468 + private boolean isOvsdbConnected(CordVtnNode node) {
484 checkNotNull(node); 469 checkNotNull(node);
485 470
486 OvsdbClientService ovsdbClient = getOvsdbClient(node); 471 OvsdbClientService ovsdbClient = getOvsdbClient(node);
...@@ -501,8 +486,8 @@ public class CordVtnNodeManager { ...@@ -501,8 +486,8 @@ public class CordVtnNodeManager {
501 return; 486 return;
502 } 487 }
503 488
504 - if (!getOvsdbConnectionState(node)) { 489 + if (!isOvsdbConnected(node)) {
505 - controller.connect(node.ovsdbIp(), node.ovsdbPort()); 490 + controller.connect(node.hostMgmtIp().ip(), node.ovsdbPort());
506 } 491 }
507 } 492 }
508 493
...@@ -519,7 +504,7 @@ public class CordVtnNodeManager { ...@@ -519,7 +504,7 @@ public class CordVtnNodeManager {
519 return; 504 return;
520 } 505 }
521 506
522 - if (getOvsdbConnectionState(node)) { 507 + if (isOvsdbConnected(node)) {
523 OvsdbClientService ovsdbClient = getOvsdbClient(node); 508 OvsdbClientService ovsdbClient = getOvsdbClient(node);
524 ovsdbClient.disconnect(); 509 ovsdbClient.disconnect();
525 } 510 }
...@@ -535,7 +520,7 @@ public class CordVtnNodeManager { ...@@ -535,7 +520,7 @@ public class CordVtnNodeManager {
535 checkNotNull(node); 520 checkNotNull(node);
536 521
537 OvsdbClientService ovsdbClient = controller.getOvsdbClient( 522 OvsdbClientService ovsdbClient = controller.getOvsdbClient(
538 - new OvsdbNodeId(node.ovsdbIp(), node.ovsdbPort().toInt())); 523 + new OvsdbNodeId(node.hostMgmtIp().ip(), node.ovsdbPort().toInt()));
539 if (ovsdbClient == null) { 524 if (ovsdbClient == null) {
540 log.trace("Couldn't find OVSDB client for {}", node.hostname()); 525 log.trace("Couldn't find OVSDB client for {}", node.hostname());
541 } 526 }
...@@ -548,7 +533,7 @@ public class CordVtnNodeManager { ...@@ -548,7 +533,7 @@ public class CordVtnNodeManager {
548 * @param node cordvtn node 533 * @param node cordvtn node
549 */ 534 */
550 private void createIntegrationBridge(CordVtnNode node) { 535 private void createIntegrationBridge(CordVtnNode node) {
551 - if (checkIntegrationBridge(node)) { 536 + if (isBrIntCreated(node)) {
552 return; 537 return;
553 } 538 }
554 539
...@@ -576,7 +561,7 @@ public class CordVtnNodeManager { ...@@ -576,7 +561,7 @@ public class CordVtnNodeManager {
576 * @param node cordvtn node 561 * @param node cordvtn node
577 */ 562 */
578 private void createTunnelInterface(CordVtnNode node) { 563 private void createTunnelInterface(CordVtnNode node) {
579 - if (checkTunnelInterface(node)) { 564 + if (isTunnelIntfCreated(node)) {
580 return; 565 return;
581 } 566 }
582 567
...@@ -599,21 +584,47 @@ public class CordVtnNodeManager { ...@@ -599,21 +584,47 @@ public class CordVtnNodeManager {
599 } 584 }
600 585
601 /** 586 /**
602 - * Creates physical interface to a given node. 587 + * Adds data plane interface to a given node.
603 * 588 *
604 * @param node cordvtn node 589 * @param node cordvtn node
605 */ 590 */
606 - private void createPhyInterface(CordVtnNode node) { 591 + private void addDataPlaneInterface(CordVtnNode node) {
607 - if (checkPhyInterface(node)) { 592 + if (isDataPlaneIntfAdded(node)) {
608 return; 593 return;
609 } 594 }
610 595
611 try { 596 try {
612 DriverHandler handler = driverService.createHandler(node.ovsdbId()); 597 DriverHandler handler = driverService.createHandler(node.ovsdbId());
613 BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); 598 BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
614 - bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.phyPortName()); 599 + bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf());
615 } catch (ItemNotFoundException e) { 600 } catch (ItemNotFoundException e) {
616 - log.warn("Failed to add {} on {}", node.phyPortName(), node.hostname()); 601 + log.warn("Failed to add {} on {}", node.dpIntf(), node.hostname());
602 + }
603 + }
604 +
605 + /**
606 + * Flushes IP address from data plane interface and adds data plane IP address
607 + * to integration bridge.
608 + *
609 + * @param node cordvtn node
610 + */
611 + private void setIpAddress(CordVtnNode node) {
612 + Session session = RemoteIpCommandUtil.connect(node.sshInfo());
613 + if (session == null) {
614 + log.debug("Failed to SSH to {}", node.hostname());
615 + return;
616 + }
617 +
618 + boolean result = RemoteIpCommandUtil.flushIp(session, node.dpIntf()) &&
619 + RemoteIpCommandUtil.setInterfaceUp(session, node.dpIntf()) &&
620 + RemoteIpCommandUtil.addIp(session, node.dpIp(), DEFAULT_BRIDGE) &&
621 + RemoteIpCommandUtil.addIp(session, node.localMgmtIp(), DEFAULT_BRIDGE) &&
622 + RemoteIpCommandUtil.setInterfaceUp(session, DEFAULT_BRIDGE);
623 +
624 + RemoteIpCommandUtil.disconnect(session);
625 +
626 + if (result) {
627 + setNodeState(node, NodeState.COMPLETE);
617 } 628 }
618 } 629 }
619 630
...@@ -623,7 +634,7 @@ public class CordVtnNodeManager { ...@@ -623,7 +634,7 @@ public class CordVtnNodeManager {
623 * @param node cordvtn node 634 * @param node cordvtn node
624 * @return true if the bridge is available, false otherwise 635 * @return true if the bridge is available, false otherwise
625 */ 636 */
626 - private boolean checkIntegrationBridge(CordVtnNode node) { 637 + private boolean isBrIntCreated(CordVtnNode node) {
627 return (deviceService.getDevice(node.intBrId()) != null 638 return (deviceService.getDevice(node.intBrId()) != null
628 && deviceService.isAvailable(node.intBrId())); 639 && deviceService.isAvailable(node.intBrId()));
629 } 640 }
...@@ -634,7 +645,7 @@ public class CordVtnNodeManager { ...@@ -634,7 +645,7 @@ public class CordVtnNodeManager {
634 * @param node cordvtn node 645 * @param node cordvtn node
635 * @return true if the interface exists, false otherwise 646 * @return true if the interface exists, false otherwise
636 */ 647 */
637 - private boolean checkTunnelInterface(CordVtnNode node) { 648 + private boolean isTunnelIntfCreated(CordVtnNode node) {
638 return deviceService.getPorts(node.intBrId()) 649 return deviceService.getPorts(node.intBrId())
639 .stream() 650 .stream()
640 .filter(p -> getPortName(p).contains(DEFAULT_TUNNEL) && 651 .filter(p -> getPortName(p).contains(DEFAULT_TUNNEL) &&
...@@ -643,20 +654,44 @@ public class CordVtnNodeManager { ...@@ -643,20 +654,44 @@ public class CordVtnNodeManager {
643 } 654 }
644 655
645 /** 656 /**
646 - * Checks if physical interface exists. 657 + * Checks if data plane interface exists.
647 * 658 *
648 * @param node cordvtn node 659 * @param node cordvtn node
649 * @return true if the interface exists, false otherwise 660 * @return true if the interface exists, false otherwise
650 */ 661 */
651 - private boolean checkPhyInterface(CordVtnNode node) { 662 + private boolean isDataPlaneIntfAdded(CordVtnNode node) {
652 return deviceService.getPorts(node.intBrId()) 663 return deviceService.getPorts(node.intBrId())
653 .stream() 664 .stream()
654 - .filter(p -> getPortName(p).contains(node.phyPortName()) && 665 + .filter(p -> getPortName(p).contains(node.dpIntf()) &&
655 p.isEnabled()) 666 p.isEnabled())
656 .findAny().isPresent(); 667 .findAny().isPresent();
657 } 668 }
658 669
659 /** 670 /**
671 + * Checks if the IP addresses are correctly set.
672 + *
673 + * @param node cordvtn node
674 + * @return true if the IP is set, false otherwise
675 + */
676 + private boolean isIpAddressSet(CordVtnNode node) {
677 + Session session = RemoteIpCommandUtil.connect(node.sshInfo());
678 + if (session == null) {
679 + log.debug("Failed to SSH to {}", node.hostname());
680 + return false;
681 + }
682 +
683 + Set<IpAddress> intBrIps = RemoteIpCommandUtil.getCurrentIps(session, DEFAULT_BRIDGE);
684 + boolean result = RemoteIpCommandUtil.getCurrentIps(session, node.dpIntf()).isEmpty() &&
685 + RemoteIpCommandUtil.isInterfaceUp(session, node.dpIntf()) &&
686 + intBrIps.contains(node.dpIp().ip()) &&
687 + intBrIps.contains(node.localMgmtIp().ip()) &&
688 + RemoteIpCommandUtil.isInterfaceUp(session, DEFAULT_BRIDGE);
689 +
690 + RemoteIpCommandUtil.disconnect(session);
691 + return result;
692 + }
693 +
694 + /**
660 * Returns connect point of a given port. 695 * Returns connect point of a given port.
661 * 696 *
662 * @param port port 697 * @param port port
...@@ -682,7 +717,7 @@ public class CordVtnNodeManager { ...@@ -682,7 +717,7 @@ public class CordVtnNodeManager {
682 public void connected(Device device) { 717 public void connected(Device device) {
683 CordVtnNode node = getNodeByOvsdbId(device.id()); 718 CordVtnNode node = getNodeByOvsdbId(device.id());
684 if (node != null) { 719 if (node != null) {
685 - setNodeState(node, checkNodeState(node)); 720 + setNodeState(node, getNodeState(node));
686 } else { 721 } else {
687 log.debug("{} is detected on unregistered node, ignore it.", device.id()); 722 log.debug("{} is detected on unregistered node, ignore it.", device.id());
688 } 723 }
...@@ -702,7 +737,7 @@ public class CordVtnNodeManager { ...@@ -702,7 +737,7 @@ public class CordVtnNodeManager {
702 public void connected(Device device) { 737 public void connected(Device device) {
703 CordVtnNode node = getNodeByBridgeId(device.id()); 738 CordVtnNode node = getNodeByBridgeId(device.id());
704 if (node != null) { 739 if (node != null) {
705 - setNodeState(node, checkNodeState(node)); 740 + setNodeState(node, getNodeState(node));
706 } else { 741 } else {
707 log.debug("{} is detected on unregistered node, ignore it.", device.id()); 742 log.debug("{} is detected on unregistered node, ignore it.", device.id());
708 } 743 }
...@@ -719,8 +754,8 @@ public class CordVtnNodeManager { ...@@ -719,8 +754,8 @@ public class CordVtnNodeManager {
719 754
720 /** 755 /**
721 * Handles port added situation. 756 * Handles port added situation.
722 - * If the added port is tunnel or physical port, proceed remaining node 757 + * If the added port is tunnel or data plane interface, proceed to the remaining
723 - * initialization. Otherwise, do nothing. 758 + * node initialization. Otherwise, do nothing.
724 * 759 *
725 * @param port port 760 * @param port port
726 */ 761 */
...@@ -736,20 +771,20 @@ public class CordVtnNodeManager { ...@@ -736,20 +771,20 @@ public class CordVtnNodeManager {
736 log.debug("Port {} is added to {}", portName, node.hostname()); 771 log.debug("Port {} is added to {}", portName, node.hostname());
737 772
738 if (portName.startsWith(VPORT_PREFIX)) { 773 if (portName.startsWith(VPORT_PREFIX)) {
739 - if (getNodeInitState(node)) { 774 + if (isNodeInitComplete(node)) {
740 cordVtnService.addServiceVm(node, getConnectPoint(port)); 775 cordVtnService.addServiceVm(node, getConnectPoint(port));
741 } else { 776 } else {
742 log.debug("VM is detected on incomplete node, ignore it.", portName); 777 log.debug("VM is detected on incomplete node, ignore it.", portName);
743 } 778 }
744 - } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.phyPortName())) { 779 + } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.dpIntf())) {
745 - setNodeState(node, checkNodeState(node)); 780 + setNodeState(node, getNodeState(node));
746 } 781 }
747 } 782 }
748 783
749 /** 784 /**
750 * Handles port removed situation. 785 * Handles port removed situation.
751 - * If the removed port is tunnel or physical port, proceed remaining node 786 + * If the removed port is tunnel or data plane interface, proceed to the remaining
752 - * initialization.Others, do nothing. 787 + * node initialization.Others, do nothing.
753 * 788 *
754 * @param port port 789 * @param port port
755 */ 790 */
...@@ -764,12 +799,12 @@ public class CordVtnNodeManager { ...@@ -764,12 +799,12 @@ public class CordVtnNodeManager {
764 log.debug("Port {} is removed from {}", portName, node.hostname()); 799 log.debug("Port {} is removed from {}", portName, node.hostname());
765 800
766 if (portName.startsWith(VPORT_PREFIX)) { 801 if (portName.startsWith(VPORT_PREFIX)) {
767 - if (getNodeInitState(node)) { 802 + if (isNodeInitComplete(node)) {
768 cordVtnService.removeServiceVm(getConnectPoint(port)); 803 cordVtnService.removeServiceVm(getConnectPoint(port));
769 } else { 804 } else {
770 log.debug("VM is vanished from incomplete node, ignore it.", portName); 805 log.debug("VM is vanished from incomplete node, ignore it.", portName);
771 } 806 }
772 - } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.phyPortName())) { 807 + } else if (portName.contains(DEFAULT_TUNNEL) || portName.equals(node.dpIntf())) {
773 setNodeState(node, NodeState.INCOMPLETE); 808 setNodeState(node, NodeState.INCOMPLETE);
774 } 809 }
775 } 810 }
...@@ -818,14 +853,26 @@ public class CordVtnNodeManager { ...@@ -818,14 +853,26 @@ public class CordVtnNodeManager {
818 return; 853 return;
819 } 854 }
820 855
856 + NetworkAddress localMgmtIp = config.localMgmtIp();
857 + TpPort ovsdbPort = config.ovsdbPort();
858 + TpPort sshPort = config.sshPort();
859 + String sshUser = config.sshUser();
860 + String sshKeyFile = config.sshKeyFile();
861 +
821 config.cordVtnNodes().forEach(node -> { 862 config.cordVtnNodes().forEach(node -> {
863 + log.debug("Read node {}", node.hostname());
822 CordVtnNode cordVtnNode = new CordVtnNode( 864 CordVtnNode cordVtnNode = new CordVtnNode(
823 node.hostname(), 865 node.hostname(),
824 - node.ovsdbIp(), 866 + node.hostMgmtIp(),
825 - node.ovsdbPort(), 867 + localMgmtIp,
868 + node.dpIp(),
869 + ovsdbPort,
870 + new SshAccessInfo(node.hostMgmtIp().ip().getIp4Address(),
871 + sshPort,
872 + sshUser,
873 + sshKeyFile),
826 node.bridgeId(), 874 node.bridgeId(),
827 - node.phyPortName(), 875 + node.dpIntf());
828 - node.localIp());
829 876
830 addNode(cordVtnNode); 877 addNode(cordVtnNode);
831 }); 878 });
......
...@@ -96,6 +96,7 @@ public class CordVtnRuleInstaller { ...@@ -96,6 +96,7 @@ public class CordVtnRuleInstaller {
96 96
97 protected final Logger log = getLogger(getClass()); 97 protected final Logger log = getLogger(getClass());
98 98
99 + private static final String PORT_NAME = "portName";
99 private static final int TABLE_FIRST = 0; 100 private static final int TABLE_FIRST = 0;
100 private static final int TABLE_IN_PORT = 1; 101 private static final int TABLE_IN_PORT = 1;
101 private static final int TABLE_ACCESS_TYPE = 2; 102 private static final int TABLE_ACCESS_TYPE = 2;
...@@ -150,18 +151,18 @@ public class CordVtnRuleInstaller { ...@@ -150,18 +151,18 @@ public class CordVtnRuleInstaller {
150 * Installs table miss rule to a give device. 151 * Installs table miss rule to a give device.
151 * 152 *
152 * @param deviceId device id to install the rules 153 * @param deviceId device id to install the rules
153 - * @param phyPortName physical port name 154 + * @param dpIntf data plane interface name
154 - * @param localIp local data plane ip address 155 + * @param dpIp data plane ip address
155 */ 156 */
156 - public void init(DeviceId deviceId, String phyPortName, IpAddress localIp) { 157 + public void init(DeviceId deviceId, String dpIntf, IpAddress dpIp) {
157 // default is drop packets which can be accomplished without 158 // default is drop packets which can be accomplished without
158 // a table miss entry for all table. 159 // a table miss entry for all table.
159 PortNumber tunnelPort = getTunnelPort(deviceId); 160 PortNumber tunnelPort = getTunnelPort(deviceId);
160 - PortNumber phyPort = getPhyPort(deviceId, phyPortName); 161 + PortNumber dpPort = getDpPort(deviceId, dpIntf);
161 162
162 - processFirstTable(deviceId, phyPort, localIp); 163 + processFirstTable(deviceId, dpPort, dpIp);
163 - processInPortTable(deviceId, tunnelPort, phyPort); 164 + processInPortTable(deviceId, tunnelPort, dpPort);
164 - processAccessTypeTable(deviceId, phyPort); 165 + processAccessTypeTable(deviceId, dpPort);
165 } 166 }
166 167
167 /** 168 /**
...@@ -510,21 +511,21 @@ public class CordVtnRuleInstaller { ...@@ -510,21 +511,21 @@ public class CordVtnRuleInstaller {
510 511
511 /** 512 /**
512 * Populates default rules on the first table. 513 * Populates default rules on the first table.
513 - * The rules are for shuttling vxlan-encapped packets and supporting physical 514 + * It includes the rules for shuttling vxlan-encapped packets between ovs and
514 - * network connectivity. 515 + * linux stack,and external network connectivity.
515 * 516 *
516 * @param deviceId device id 517 * @param deviceId device id
517 - * @param phyPort physical port number 518 + * @param dpPort data plane interface port number
518 - * @param localIp local data plane ip address 519 + * @param dpIp data plane ip address
519 */ 520 */
520 - private void processFirstTable(DeviceId deviceId, PortNumber phyPort, IpAddress localIp) { 521 + private void processFirstTable(DeviceId deviceId, PortNumber dpPort, IpAddress dpIp) {
521 // take vxlan packet out onto the physical port 522 // take vxlan packet out onto the physical port
522 TrafficSelector selector = DefaultTrafficSelector.builder() 523 TrafficSelector selector = DefaultTrafficSelector.builder()
523 .matchInPort(PortNumber.LOCAL) 524 .matchInPort(PortNumber.LOCAL)
524 .build(); 525 .build();
525 526
526 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 527 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
527 - .setOutput(phyPort) 528 + .setOutput(dpPort)
528 .build(); 529 .build();
529 530
530 FlowRule flowRule = DefaultFlowRule.builder() 531 FlowRule flowRule = DefaultFlowRule.builder()
...@@ -541,7 +542,7 @@ public class CordVtnRuleInstaller { ...@@ -541,7 +542,7 @@ public class CordVtnRuleInstaller {
541 542
542 // take a vxlan encap'd packet through the Linux stack 543 // take a vxlan encap'd packet through the Linux stack
543 selector = DefaultTrafficSelector.builder() 544 selector = DefaultTrafficSelector.builder()
544 - .matchInPort(phyPort) 545 + .matchInPort(dpPort)
545 .matchEthType(Ethernet.TYPE_IPV4) 546 .matchEthType(Ethernet.TYPE_IPV4)
546 .matchIPProtocol(IPv4.PROTOCOL_UDP) 547 .matchIPProtocol(IPv4.PROTOCOL_UDP)
547 .matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT)) 548 .matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT))
...@@ -563,11 +564,11 @@ public class CordVtnRuleInstaller { ...@@ -563,11 +564,11 @@ public class CordVtnRuleInstaller {
563 564
564 processFlowRule(true, flowRule); 565 processFlowRule(true, flowRule);
565 566
566 - // take a packet to the local ip through Linux stack 567 + // take a packet to the data plane ip through Linux stack
567 selector = DefaultTrafficSelector.builder() 568 selector = DefaultTrafficSelector.builder()
568 - .matchInPort(phyPort) 569 + .matchInPort(dpPort)
569 .matchEthType(Ethernet.TYPE_IPV4) 570 .matchEthType(Ethernet.TYPE_IPV4)
570 - .matchIPDst(localIp.toIpPrefix()) 571 + .matchIPDst(dpIp.toIpPrefix())
571 .build(); 572 .build();
572 573
573 treatment = DefaultTrafficTreatment.builder() 574 treatment = DefaultTrafficTreatment.builder()
...@@ -588,7 +589,7 @@ public class CordVtnRuleInstaller { ...@@ -588,7 +589,7 @@ public class CordVtnRuleInstaller {
588 589
589 // take an arp packet from physical through Linux stack 590 // take an arp packet from physical through Linux stack
590 selector = DefaultTrafficSelector.builder() 591 selector = DefaultTrafficSelector.builder()
591 - .matchInPort(phyPort) 592 + .matchInPort(dpPort)
592 .matchEthType(Ethernet.TYPE_ARP) 593 .matchEthType(Ethernet.TYPE_ARP)
593 .build(); 594 .build();
594 595
...@@ -630,17 +631,17 @@ public class CordVtnRuleInstaller { ...@@ -630,17 +631,17 @@ public class CordVtnRuleInstaller {
630 } 631 }
631 632
632 /** 633 /**
633 - * Forward table miss packets in ACCESS_TYPE table to physical port. 634 + * Forward table miss packets in ACCESS_TYPE table to data plane port.
634 * 635 *
635 * @param deviceId device id 636 * @param deviceId device id
636 - * @param phyPort physical port number 637 + * @param dpPort data plane interface port number
637 */ 638 */
638 - private void processAccessTypeTable(DeviceId deviceId, PortNumber phyPort) { 639 + private void processAccessTypeTable(DeviceId deviceId, PortNumber dpPort) {
639 TrafficSelector selector = DefaultTrafficSelector.builder() 640 TrafficSelector selector = DefaultTrafficSelector.builder()
640 .build(); 641 .build();
641 642
642 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 643 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
643 - .setOutput(phyPort) 644 + .setOutput(dpPort)
644 .build(); 645 .build();
645 646
646 FlowRule flowRule = DefaultFlowRule.builder() 647 FlowRule flowRule = DefaultFlowRule.builder()
...@@ -659,13 +660,13 @@ public class CordVtnRuleInstaller { ...@@ -659,13 +660,13 @@ public class CordVtnRuleInstaller {
659 /** 660 /**
660 * Populates default rules for IN_PORT table. 661 * Populates default rules for IN_PORT table.
661 * All packets from tunnel port are forwarded to TUNNEL_ID table and all packets 662 * All packets from tunnel port are forwarded to TUNNEL_ID table and all packets
662 - * from physical port to ACCESS_TYPE table. 663 + * from data plane interface port to ACCESS_TYPE table.
663 * 664 *
664 * @param deviceId device id to install the rules 665 * @param deviceId device id to install the rules
665 * @param tunnelPort tunnel port number 666 * @param tunnelPort tunnel port number
666 - * @param phyPort physical port number 667 + * @param dpPort data plane interface port number
667 */ 668 */
668 - private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber phyPort) { 669 + private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber dpPort) {
669 checkNotNull(tunnelPort); 670 checkNotNull(tunnelPort);
670 671
671 TrafficSelector selector = DefaultTrafficSelector.builder() 672 TrafficSelector selector = DefaultTrafficSelector.builder()
...@@ -689,7 +690,7 @@ public class CordVtnRuleInstaller { ...@@ -689,7 +690,7 @@ public class CordVtnRuleInstaller {
689 processFlowRule(true, flowRule); 690 processFlowRule(true, flowRule);
690 691
691 selector = DefaultTrafficSelector.builder() 692 selector = DefaultTrafficSelector.builder()
692 - .matchInPort(phyPort) 693 + .matchInPort(dpPort)
693 .build(); 694 .build();
694 695
695 treatment = DefaultTrafficTreatment.builder() 696 treatment = DefaultTrafficTreatment.builder()
...@@ -1027,22 +1028,22 @@ public class CordVtnRuleInstaller { ...@@ -1027,22 +1028,22 @@ public class CordVtnRuleInstaller {
1027 */ 1028 */
1028 private PortNumber getTunnelPort(DeviceId deviceId) { 1029 private PortNumber getTunnelPort(DeviceId deviceId) {
1029 Port port = deviceService.getPorts(deviceId).stream() 1030 Port port = deviceService.getPorts(deviceId).stream()
1030 - .filter(p -> p.annotations().value("portName").contains(tunnelType)) 1031 + .filter(p -> p.annotations().value(PORT_NAME).contains(tunnelType))
1031 .findFirst().orElse(null); 1032 .findFirst().orElse(null);
1032 1033
1033 return port == null ? null : port.number(); 1034 return port == null ? null : port.number();
1034 } 1035 }
1035 1036
1036 /** 1037 /**
1037 - * Returns physical port name of a given device. 1038 + * Returns data plane interface port name of a given device.
1038 * 1039 *
1039 * @param deviceId device id 1040 * @param deviceId device id
1040 - * @param phyPortName physical port name 1041 + * @param dpIntf data plane interface port name
1041 - * @return physical port number, or null if no physical port exists 1042 + * @return data plane interface port number, or null if no such port exists
1042 */ 1043 */
1043 - private PortNumber getPhyPort(DeviceId deviceId, String phyPortName) { 1044 + private PortNumber getDpPort(DeviceId deviceId, String dpIntf) {
1044 Port port = deviceService.getPorts(deviceId).stream() 1045 Port port = deviceService.getPorts(deviceId).stream()
1045 - .filter(p -> p.annotations().value("portName").contains(phyPortName) && 1046 + .filter(p -> p.annotations().value(PORT_NAME).contains(dpIntf) &&
1046 p.isEnabled()) 1047 p.isEnabled())
1047 .findFirst().orElse(null); 1048 .findFirst().orElse(null);
1048 1049
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cordvtn;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import org.onlab.packet.IpAddress;
20 +import org.onlab.packet.IpPrefix;
21 +
22 +import java.util.Objects;
23 +
24 +import static com.google.common.base.Preconditions.checkArgument;
25 +
26 +/**
27 + * Representation of a network address, which consists of IP address and prefix.
28 + */
29 +public final class NetworkAddress {
30 + private final IpAddress ip;
31 + private final IpPrefix prefix;
32 +
33 + /**
34 + * Constructor for a given IP address and prefix.
35 + *
36 + * @param ip ip address
37 + * @param prefix ip prefix
38 + */
39 + public NetworkAddress(IpAddress ip, IpPrefix prefix) {
40 + this.ip = ip;
41 + this.prefix = prefix;
42 + }
43 +
44 + /**
45 + * Converts a CIDR notation string into a network address.
46 + *
47 + * @param cidr cidr
48 + * @return network address
49 + * @throws IllegalArgumentException if the cidr is not valid
50 + */
51 + public static NetworkAddress valueOf(String cidr) {
52 + checkArgument(cidr.contains("/"));
53 +
54 + IpAddress ipAddress = IpAddress.valueOf(cidr.split("/")[0]);
55 + IpPrefix ipPrefix = IpPrefix.valueOf(cidr);
56 +
57 + return new NetworkAddress(ipAddress, ipPrefix);
58 + }
59 +
60 + /**
61 + * Returns the IP address value of the network address.
62 + *
63 + * @return ip address
64 + */
65 + public IpAddress ip() {
66 + return this.ip;
67 + }
68 +
69 + /**
70 + * Returns the IP prefix value of the network address.
71 + *
72 + * @return ip prefix
73 + */
74 + public IpPrefix prefix() {
75 + return this.prefix;
76 + }
77 +
78 + /**
79 + * Converts a network address to a CIDR notation.
80 + *
81 + * @return cidr notation string
82 + */
83 + public String cidr() {
84 + return ip.toString() + "/" + prefix.prefixLength();
85 + }
86 +
87 + @Override
88 + public boolean equals(Object obj) {
89 + if (this == obj) {
90 + return true;
91 + }
92 +
93 + if (obj instanceof NetworkAddress) {
94 + NetworkAddress that = (NetworkAddress) obj;
95 + if (Objects.equals(ip, that.ip) && Objects.equals(prefix, that.prefix)) {
96 + return true;
97 + }
98 + }
99 + return false;
100 + }
101 +
102 + @Override
103 + public int hashCode() {
104 + return Objects.hash(ip, prefix);
105 + }
106 +
107 + @Override
108 + public String toString() {
109 + return MoreObjects.toStringHelper(getClass())
110 + .add("IpAddress", ip)
111 + .add("IpPrefix", prefix)
112 + .toString();
113 + }
114 +}
...@@ -22,7 +22,7 @@ import com.jcraft.jsch.ChannelExec; ...@@ -22,7 +22,7 @@ import com.jcraft.jsch.ChannelExec;
22 import com.jcraft.jsch.JSch; 22 import com.jcraft.jsch.JSch;
23 import com.jcraft.jsch.JSchException; 23 import com.jcraft.jsch.JSchException;
24 import com.jcraft.jsch.Session; 24 import com.jcraft.jsch.Session;
25 -import org.onlab.packet.IpPrefix; 25 +import org.onlab.packet.IpAddress;
26 import org.slf4j.Logger; 26 import org.slf4j.Logger;
27 27
28 import java.io.IOException; 28 import java.io.IOException;
...@@ -48,8 +48,10 @@ public final class RemoteIpCommandUtil { ...@@ -48,8 +48,10 @@ public final class RemoteIpCommandUtil {
48 private static final String DEFAULT_STRICT_HOST_CHECKING = "no"; 48 private static final String DEFAULT_STRICT_HOST_CHECKING = "no";
49 private static final int DEFAULT_SESSION_TIMEOUT = 60000; // milliseconds 49 private static final int DEFAULT_SESSION_TIMEOUT = 60000; // milliseconds
50 50
51 - private static final String IP_PATTERN = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.)" + 51 + private static final String IP_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
52 - "{3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$"; 52 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
53 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
54 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
53 55
54 private static final String IP_ADDR_SHOW = "sudo ip addr show %s"; 56 private static final String IP_ADDR_SHOW = "sudo ip addr show %s";
55 private static final String IP_ADDR_FLUSH = "sudo ip addr flush %s"; 57 private static final String IP_ADDR_FLUSH = "sudo ip addr flush %s";
...@@ -68,18 +70,18 @@ public final class RemoteIpCommandUtil { ...@@ -68,18 +70,18 @@ public final class RemoteIpCommandUtil {
68 * Adds a given IP address to a given device. 70 * Adds a given IP address to a given device.
69 * 71 *
70 * @param session ssh connection 72 * @param session ssh connection
71 - * @param ip ip address 73 + * @param ip network address
72 * @param device device name to assign the ip address 74 * @param device device name to assign the ip address
73 * @return true if the command succeeds, or false 75 * @return true if the command succeeds, or false
74 */ 76 */
75 - public static boolean addIp(Session session, IpPrefix ip, String device) { 77 + public static boolean addIp(Session session, NetworkAddress ip, String device) {
76 if (session == null || !session.isConnected()) { 78 if (session == null || !session.isConnected()) {
77 return false; 79 return false;
78 } 80 }
79 81
80 - executeCommand(session, String.format(IP_ADDR_ADD, ip, device)); 82 + executeCommand(session, String.format(IP_ADDR_ADD, ip.cidr(), device));
81 - Set<IpPrefix> result = getCurrentIps(session, device); 83 + Set<IpAddress> result = getCurrentIps(session, device);
82 - return result.contains(ip); 84 + return result.contains(ip.ip());
83 } 85 }
84 86
85 /** 87 /**
...@@ -90,13 +92,13 @@ public final class RemoteIpCommandUtil { ...@@ -90,13 +92,13 @@ public final class RemoteIpCommandUtil {
90 * @param device device name 92 * @param device device name
91 * @return true if the command succeeds, or false 93 * @return true if the command succeeds, or false
92 */ 94 */
93 - public static boolean deleteIp(Session session, IpPrefix ip, String device) { 95 + public static boolean deleteIp(Session session, IpAddress ip, String device) {
94 if (session == null || !session.isConnected()) { 96 if (session == null || !session.isConnected()) {
95 return false; 97 return false;
96 } 98 }
97 99
98 executeCommand(session, String.format(IP_ADDR_DELETE, ip, device)); 100 executeCommand(session, String.format(IP_ADDR_DELETE, ip, device));
99 - Set<IpPrefix> result = getCurrentIps(session, device); 101 + Set<IpAddress> result = getCurrentIps(session, device);
100 return !result.contains(ip); 102 return !result.contains(ip);
101 } 103 }
102 104
...@@ -123,16 +125,16 @@ public final class RemoteIpCommandUtil { ...@@ -123,16 +125,16 @@ public final class RemoteIpCommandUtil {
123 * @param device device name 125 * @param device device name
124 * @return set of IP prefix or empty set 126 * @return set of IP prefix or empty set
125 */ 127 */
126 - public static Set<IpPrefix> getCurrentIps(Session session, String device) { 128 + public static Set<IpAddress> getCurrentIps(Session session, String device) {
127 if (session == null || !session.isConnected()) { 129 if (session == null || !session.isConnected()) {
128 return Sets.newHashSet(); 130 return Sets.newHashSet();
129 } 131 }
130 132
131 String output = executeCommand(session, String.format(IP_ADDR_SHOW, device)); 133 String output = executeCommand(session, String.format(IP_ADDR_SHOW, device));
132 - Set<IpPrefix> result = Pattern.compile(" ") 134 + Set<IpAddress> result = Pattern.compile(" |/")
133 .splitAsStream(output) 135 .splitAsStream(output)
134 .filter(s -> s.matches(IP_PATTERN)) 136 .filter(s -> s.matches(IP_PATTERN))
135 - .map(IpPrefix::valueOf) 137 + .map(IpAddress::valueOf)
136 .collect(Collectors.toSet()); 138 .collect(Collectors.toSet());
137 139
138 return result; 140 return result;
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.cordvtn.cli;
18 -
19 -import org.apache.karaf.shell.commands.Argument;
20 -import org.apache.karaf.shell.commands.Command;
21 -import org.onlab.packet.IpAddress;
22 -import org.onlab.packet.TpPort;
23 -import org.onosproject.cli.AbstractShellCommand;
24 -import org.onosproject.cordvtn.CordVtnNodeManager;
25 -import org.onosproject.cordvtn.CordVtnNode;
26 -import org.onosproject.net.DeviceId;
27 -
28 -import static com.google.common.base.Preconditions.checkArgument;
29 -
30 -/**
31 - * Adds a new node to the service.
32 - */
33 -@Command(scope = "onos", name = "cordvtn-node-add",
34 - description = "Adds a new node to CORD VTN service")
35 -public class CordVtnNodeAddCommand extends AbstractShellCommand {
36 -
37 - @Argument(index = 0, name = "hostname", description = "Hostname",
38 - required = true, multiValued = false)
39 - private String hostname = null;
40 -
41 - @Argument(index = 1, name = "ovsdb",
42 - description = "OVSDB server listening address (ip:port)",
43 - required = true, multiValued = false)
44 - private String ovsdb = null;
45 -
46 - @Argument(index = 2, name = "bridgeId",
47 - description = "Device ID of integration bridge",
48 - required = true, multiValued = false)
49 - private String bridgeId = null;
50 -
51 - @Argument(index = 3, name = "phyPortName",
52 - description = "Physical port name",
53 - required = true, multiValued = false)
54 - private String phyPortName = null;
55 -
56 - @Argument(index = 4, name = "localIp",
57 - description = "Local data plane IP address",
58 - required = true, multiValued = false)
59 - private String localIp = null;
60 -
61 - @Override
62 - protected void execute() {
63 - checkArgument(ovsdb.contains(":"), "OVSDB address should be ip:port format");
64 - checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format");
65 -
66 - CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
67 - String[] ipPort = ovsdb.split(":");
68 - CordVtnNode node = new CordVtnNode(hostname,
69 - IpAddress.valueOf(ipPort[0]),
70 - TpPort.tpPort(Integer.parseInt(ipPort[1])),
71 - DeviceId.deviceId(bridgeId),
72 - phyPortName,
73 - IpAddress.valueOf(localIp));
74 - nodeManager.addNode(node);
75 - }
76 -}
...@@ -34,6 +34,9 @@ import java.util.List; ...@@ -34,6 +34,9 @@ import java.util.List;
34 description = "Lists all nodes registered in CORD VTN service") 34 description = "Lists all nodes registered in CORD VTN service")
35 public class CordVtnNodeListCommand extends AbstractShellCommand { 35 public class CordVtnNodeListCommand extends AbstractShellCommand {
36 36
37 + private static final String COMPLETE = "COMPLETE";
38 + private static final String INCOMPLETE = "INCOMPLETE";
39 +
37 @Override 40 @Override
38 protected void execute() { 41 protected void execute() {
39 CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); 42 CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
...@@ -44,12 +47,12 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { ...@@ -44,12 +47,12 @@ public class CordVtnNodeListCommand extends AbstractShellCommand {
44 print("%s", json(nodeManager, nodes)); 47 print("%s", json(nodeManager, nodes));
45 } else { 48 } else {
46 for (CordVtnNode node : nodes) { 49 for (CordVtnNode node : nodes) {
47 - print("hostname=%s, ovsdb=%s, br-int=%s, phyPort=%s, localIp=%s, init=%s", 50 + print("hostname=%s, hostMgmtIp=%s, dpIp=%s, br-int=%s, dpIntf=%s, init=%s",
48 node.hostname(), 51 node.hostname(),
49 - node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString(), 52 + node.hostMgmtIp().cidr(),
53 + node.dpIp().cidr(),
50 node.intBrId().toString(), 54 node.intBrId().toString(),
51 - node.phyPortName(), 55 + node.dpIntf(),
52 - node.localIp().toString(),
53 getState(nodeManager, node)); 56 getState(nodeManager, node));
54 } 57 }
55 print("Total %s nodes", nodeManager.getNodeCount()); 58 print("Total %s nodes", nodeManager.getNodeCount());
...@@ -60,19 +63,18 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { ...@@ -60,19 +63,18 @@ public class CordVtnNodeListCommand extends AbstractShellCommand {
60 ObjectMapper mapper = new ObjectMapper(); 63 ObjectMapper mapper = new ObjectMapper();
61 ArrayNode result = mapper.createArrayNode(); 64 ArrayNode result = mapper.createArrayNode();
62 for (CordVtnNode node : nodes) { 65 for (CordVtnNode node : nodes) {
63 - String ipPort = node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString();
64 result.add(mapper.createObjectNode() 66 result.add(mapper.createObjectNode()
65 .put("hostname", node.hostname()) 67 .put("hostname", node.hostname())
66 - .put("ovsdb", ipPort) 68 + .put("hostManagementIp", node.hostMgmtIp().cidr())
67 - .put("brInt", node.intBrId().toString()) 69 + .put("dataPlaneIp", node.dpIp().cidr())
68 - .put("phyPort", node.phyPortName()) 70 + .put("bridgeId", node.intBrId().toString())
69 - .put("localIp", node.localIp().toString()) 71 + .put("dataPlaneInterface", node.dpIntf())
70 .put("init", getState(nodeManager, node))); 72 .put("init", getState(nodeManager, node)));
71 } 73 }
72 return result; 74 return result;
73 } 75 }
74 76
75 private String getState(CordVtnNodeManager nodeManager, CordVtnNode node) { 77 private String getState(CordVtnNodeManager nodeManager, CordVtnNode node) {
76 - return nodeManager.getNodeInitState(node) ? "COMPLETE" : "INCOMPLETE"; 78 + return nodeManager.isNodeInitComplete(node) ? COMPLETE : INCOMPLETE;
77 } 79 }
78 } 80 }
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
20 <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/> 20 <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/>
21 </command> 21 </command>
22 <command> 22 <command>
23 - <action class="org.onosproject.cordvtn.cli.CordVtnNodeAddCommand"/>
24 - </command>
25 - <command>
26 <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/> 23 <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/>
27 </command> 24 </command>
28 <command> 25 <command>
......