let the XOS IP and port configurable
Change-Id: Iaeb0ac72408e145a39979266d45d8255970e8069
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/RestClient.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/RestClient.java
index b5c1322..e779fe7 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/RestClient.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/RestClient.java
@@ -29,18 +29,26 @@
import java.io.IOException;
+import org.onlab.packet.IpAddress;
import org.slf4j.Logger;
public class RestClient {
private final Logger log = getLogger(getClass());
- private final String hostName = "10.254.1.22";
- private final int xosServerPort = 8000;
private static final String UTF_8 = JSON_UTF_8.toString();
private static final ObjectMapper MAPPER = new ObjectMapper();
- private final String url = "http://" + hostName + ":" + xosServerPort
- + "/xoslib/rs/vbng_mapping/";
+ private final String url;
/**
+ * Constructor.
+ *
+ * @param xosServerIpAddress the IP address of the XOS server
+ * @param xosServerPort the port for the REST service on XOS server
+ */
+ RestClient(IpAddress xosServerIpAddress, int xosServerPort) {
+ this.url = "http://" + xosServerIpAddress.toString() + ":"
+ + xosServerPort + "/xoslib/rs/vbng_mapping/";
+ }
+ /**
* Gets a client web resource builder.
*
* @param url the URL to access remote resource
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfiguration.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfiguration.java
index 6957db0..ee2cbea 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfiguration.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfiguration.java
@@ -34,6 +34,8 @@
private final List<IpPrefix> localPublicIpPrefixes;
private final IpAddress nextHopIpAddress;
private final MacAddress publicFacingMac;
+ private final IpAddress xosIpAddress;
+ private final int xosRestPort;
/**
* Default constructor.
@@ -42,6 +44,8 @@
localPublicIpPrefixes = null;
nextHopIpAddress = null;
publicFacingMac = null;
+ xosIpAddress = null;
+ xosRestPort = 0;
}
/**
@@ -51,6 +55,8 @@
* @param prefixes the public IP prefix list for local SDN network
* @param publicFacingMac the MAC address configured for all local
* public IP addresses
+ * @param xosIpAddress the XOS server IP address
+ * @param xosRestPort the port of the XOS server for REST
*/
@JsonCreator
public VbngConfiguration(@JsonProperty("localPublicIpPrefixes")
@@ -58,10 +64,16 @@
@JsonProperty("nextHopIpAddress")
IpAddress nextHopIpAddress,
@JsonProperty("publicFacingMac")
- MacAddress publicFacingMac) {
+ MacAddress publicFacingMac,
+ @JsonProperty("xosIpAddress")
+ IpAddress xosIpAddress,
+ @JsonProperty("xosRestPort")
+ int xosRestPort) {
localPublicIpPrefixes = prefixes;
this.nextHopIpAddress = nextHopIpAddress;
this.publicFacingMac = publicFacingMac;
+ this.xosIpAddress = xosIpAddress;
+ this.xosRestPort = xosRestPort;
}
/**
@@ -90,4 +102,22 @@
public MacAddress getPublicFacingMac() {
return publicFacingMac;
}
+
+ /**
+ * Gets the IP address configured for XOS server.
+ *
+ * @return the IP address configured for the XOS server
+ */
+ public IpAddress getXosIpAddress() {
+ return xosIpAddress;
+ }
+
+ /**
+ * Gets the REST communication port configured for XOS server.
+ *
+ * @return the REST communication port configured for XOS server
+ */
+ public int getXosRestPort() {
+ return xosRestPort;
+ }
}
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
index 653a87d..d27d690 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
@@ -61,6 +61,8 @@
private IpAddress nextHopIpAddress;
private MacAddress macOfPublicIpAddresses;
+ private IpAddress xosIpAddress;
+ private int xosRestPort;
@Activate
public void activate() {
@@ -100,6 +102,8 @@
}
nextHopIpAddress = config.getNextHopIpAddress();
macOfPublicIpAddresses = config.getPublicFacingMac();
+ xosIpAddress = config.getXosIpAddress();
+ xosRestPort = config.getXosRestPort();
} catch (FileNotFoundException e) {
log.warn("Configuration file not found: {}", configFileName);
@@ -118,6 +122,16 @@
return macOfPublicIpAddresses;
}
+ @Override
+ public IpAddress getXosIpAddress() {
+ return xosIpAddress;
+ }
+
+ @Override
+ public int getXosRestPort() {
+ return xosRestPort;
+ }
+
// TODO handle the case: the number of public IP addresses is not enough
// for 1:1 mapping from public IP to private IP.
@Override
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
index 6f17ebc..ef8698a 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
@@ -40,6 +40,20 @@
MacAddress getPublicFacingMac();
/**
+ * Gets the IP address configured for XOS server.
+ *
+ * @return the IP address configured for the XOS server
+ */
+ IpAddress getXosIpAddress();
+
+ /**
+ * Gets the REST communication port configured for XOS server.
+ *
+ * @return the REST communication port configured for XOS server
+ */
+ int getXosRestPort();
+
+ /**
* Evaluates whether an IP address is an assigned public IP address.
*
* @param ipAddress the IP address to evaluate
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
index 8fae896..5e82b7e 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
@@ -136,7 +136,9 @@
*/
private void statusRecovery() {
log.info("vBNG starts to recover from XOS record......");
- RestClient restClient = new RestClient();
+ RestClient restClient =
+ new RestClient(vbngConfigurationService.getXosIpAddress(),
+ vbngConfigurationService.getXosRestPort());
ObjectNode map = restClient.getRest();
if (map == null) {
log.info("Stop to recover vBNG status due to the vBNG map "