Pingping Lin
Committed by Gerrit Code Review

let the XOS IP and port configurable

Change-Id: Iaeb0ac72408e145a39979266d45d8255970e8069
......@@ -29,18 +29,26 @@ import com.sun.jersey.api.client.WebResource;
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
......
......@@ -34,6 +34,8 @@ public final class VbngConfiguration {
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 @@ public final class VbngConfiguration {
localPublicIpPrefixes = null;
nextHopIpAddress = null;
publicFacingMac = null;
xosIpAddress = null;
xosRestPort = 0;
}
/**
......@@ -51,6 +55,8 @@ public final class VbngConfiguration {
* @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 @@ public final class VbngConfiguration {
@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 final class VbngConfiguration {
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;
}
}
......
......@@ -61,6 +61,8 @@ public class VbngConfigurationManager implements VbngConfigurationService {
private IpAddress nextHopIpAddress;
private MacAddress macOfPublicIpAddresses;
private IpAddress xosIpAddress;
private int xosRestPort;
@Activate
public void activate() {
......@@ -100,6 +102,8 @@ public class VbngConfigurationManager implements VbngConfigurationService {
}
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 @@ public class VbngConfigurationManager implements VbngConfigurationService {
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
......
......@@ -40,6 +40,20 @@ public interface VbngConfigurationService {
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
......
......@@ -136,7 +136,9 @@ public class VbngManager implements VbngService {
*/
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 "
......