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; ...@@ -29,18 +29,26 @@ import com.sun.jersey.api.client.WebResource;
29 29
30 import java.io.IOException; 30 import java.io.IOException;
31 31
32 +import org.onlab.packet.IpAddress;
32 import org.slf4j.Logger; 33 import org.slf4j.Logger;
33 34
34 public class RestClient { 35 public class RestClient {
35 private final Logger log = getLogger(getClass()); 36 private final Logger log = getLogger(getClass());
36 - private final String hostName = "10.254.1.22";
37 - private final int xosServerPort = 8000;
38 private static final String UTF_8 = JSON_UTF_8.toString(); 37 private static final String UTF_8 = JSON_UTF_8.toString();
39 private static final ObjectMapper MAPPER = new ObjectMapper(); 38 private static final ObjectMapper MAPPER = new ObjectMapper();
40 - private final String url = "http://" + hostName + ":" + xosServerPort 39 + private final String url;
41 - + "/xoslib/rs/vbng_mapping/";
42 40
43 /** 41 /**
42 + * Constructor.
43 + *
44 + * @param xosServerIpAddress the IP address of the XOS server
45 + * @param xosServerPort the port for the REST service on XOS server
46 + */
47 + RestClient(IpAddress xosServerIpAddress, int xosServerPort) {
48 + this.url = "http://" + xosServerIpAddress.toString() + ":"
49 + + xosServerPort + "/xoslib/rs/vbng_mapping/";
50 + }
51 + /**
44 * Gets a client web resource builder. 52 * Gets a client web resource builder.
45 * 53 *
46 * @param url the URL to access remote resource 54 * @param url the URL to access remote resource
......
...@@ -34,6 +34,8 @@ public final class VbngConfiguration { ...@@ -34,6 +34,8 @@ public final class VbngConfiguration {
34 private final List<IpPrefix> localPublicIpPrefixes; 34 private final List<IpPrefix> localPublicIpPrefixes;
35 private final IpAddress nextHopIpAddress; 35 private final IpAddress nextHopIpAddress;
36 private final MacAddress publicFacingMac; 36 private final MacAddress publicFacingMac;
37 + private final IpAddress xosIpAddress;
38 + private final int xosRestPort;
37 39
38 /** 40 /**
39 * Default constructor. 41 * Default constructor.
...@@ -42,6 +44,8 @@ public final class VbngConfiguration { ...@@ -42,6 +44,8 @@ public final class VbngConfiguration {
42 localPublicIpPrefixes = null; 44 localPublicIpPrefixes = null;
43 nextHopIpAddress = null; 45 nextHopIpAddress = null;
44 publicFacingMac = null; 46 publicFacingMac = null;
47 + xosIpAddress = null;
48 + xosRestPort = 0;
45 } 49 }
46 50
47 /** 51 /**
...@@ -51,6 +55,8 @@ public final class VbngConfiguration { ...@@ -51,6 +55,8 @@ public final class VbngConfiguration {
51 * @param prefixes the public IP prefix list for local SDN network 55 * @param prefixes the public IP prefix list for local SDN network
52 * @param publicFacingMac the MAC address configured for all local 56 * @param publicFacingMac the MAC address configured for all local
53 * public IP addresses 57 * public IP addresses
58 + * @param xosIpAddress the XOS server IP address
59 + * @param xosRestPort the port of the XOS server for REST
54 */ 60 */
55 @JsonCreator 61 @JsonCreator
56 public VbngConfiguration(@JsonProperty("localPublicIpPrefixes") 62 public VbngConfiguration(@JsonProperty("localPublicIpPrefixes")
...@@ -58,10 +64,16 @@ public final class VbngConfiguration { ...@@ -58,10 +64,16 @@ public final class VbngConfiguration {
58 @JsonProperty("nextHopIpAddress") 64 @JsonProperty("nextHopIpAddress")
59 IpAddress nextHopIpAddress, 65 IpAddress nextHopIpAddress,
60 @JsonProperty("publicFacingMac") 66 @JsonProperty("publicFacingMac")
61 - MacAddress publicFacingMac) { 67 + MacAddress publicFacingMac,
68 + @JsonProperty("xosIpAddress")
69 + IpAddress xosIpAddress,
70 + @JsonProperty("xosRestPort")
71 + int xosRestPort) {
62 localPublicIpPrefixes = prefixes; 72 localPublicIpPrefixes = prefixes;
63 this.nextHopIpAddress = nextHopIpAddress; 73 this.nextHopIpAddress = nextHopIpAddress;
64 this.publicFacingMac = publicFacingMac; 74 this.publicFacingMac = publicFacingMac;
75 + this.xosIpAddress = xosIpAddress;
76 + this.xosRestPort = xosRestPort;
65 } 77 }
66 78
67 /** 79 /**
...@@ -90,4 +102,22 @@ public final class VbngConfiguration { ...@@ -90,4 +102,22 @@ public final class VbngConfiguration {
90 public MacAddress getPublicFacingMac() { 102 public MacAddress getPublicFacingMac() {
91 return publicFacingMac; 103 return publicFacingMac;
92 } 104 }
105 +
106 + /**
107 + * Gets the IP address configured for XOS server.
108 + *
109 + * @return the IP address configured for the XOS server
110 + */
111 + public IpAddress getXosIpAddress() {
112 + return xosIpAddress;
113 + }
114 +
115 + /**
116 + * Gets the REST communication port configured for XOS server.
117 + *
118 + * @return the REST communication port configured for XOS server
119 + */
120 + public int getXosRestPort() {
121 + return xosRestPort;
122 + }
93 } 123 }
......
...@@ -61,6 +61,8 @@ public class VbngConfigurationManager implements VbngConfigurationService { ...@@ -61,6 +61,8 @@ public class VbngConfigurationManager implements VbngConfigurationService {
61 61
62 private IpAddress nextHopIpAddress; 62 private IpAddress nextHopIpAddress;
63 private MacAddress macOfPublicIpAddresses; 63 private MacAddress macOfPublicIpAddresses;
64 + private IpAddress xosIpAddress;
65 + private int xosRestPort;
64 66
65 @Activate 67 @Activate
66 public void activate() { 68 public void activate() {
...@@ -100,6 +102,8 @@ public class VbngConfigurationManager implements VbngConfigurationService { ...@@ -100,6 +102,8 @@ public class VbngConfigurationManager implements VbngConfigurationService {
100 } 102 }
101 nextHopIpAddress = config.getNextHopIpAddress(); 103 nextHopIpAddress = config.getNextHopIpAddress();
102 macOfPublicIpAddresses = config.getPublicFacingMac(); 104 macOfPublicIpAddresses = config.getPublicFacingMac();
105 + xosIpAddress = config.getXosIpAddress();
106 + xosRestPort = config.getXosRestPort();
103 107
104 } catch (FileNotFoundException e) { 108 } catch (FileNotFoundException e) {
105 log.warn("Configuration file not found: {}", configFileName); 109 log.warn("Configuration file not found: {}", configFileName);
...@@ -118,6 +122,16 @@ public class VbngConfigurationManager implements VbngConfigurationService { ...@@ -118,6 +122,16 @@ public class VbngConfigurationManager implements VbngConfigurationService {
118 return macOfPublicIpAddresses; 122 return macOfPublicIpAddresses;
119 } 123 }
120 124
125 + @Override
126 + public IpAddress getXosIpAddress() {
127 + return xosIpAddress;
128 + }
129 +
130 + @Override
131 + public int getXosRestPort() {
132 + return xosRestPort;
133 + }
134 +
121 // TODO handle the case: the number of public IP addresses is not enough 135 // TODO handle the case: the number of public IP addresses is not enough
122 // for 1:1 mapping from public IP to private IP. 136 // for 1:1 mapping from public IP to private IP.
123 @Override 137 @Override
......
...@@ -40,6 +40,20 @@ public interface VbngConfigurationService { ...@@ -40,6 +40,20 @@ public interface VbngConfigurationService {
40 MacAddress getPublicFacingMac(); 40 MacAddress getPublicFacingMac();
41 41
42 /** 42 /**
43 + * Gets the IP address configured for XOS server.
44 + *
45 + * @return the IP address configured for the XOS server
46 + */
47 + IpAddress getXosIpAddress();
48 +
49 + /**
50 + * Gets the REST communication port configured for XOS server.
51 + *
52 + * @return the REST communication port configured for XOS server
53 + */
54 + int getXosRestPort();
55 +
56 + /**
43 * Evaluates whether an IP address is an assigned public IP address. 57 * Evaluates whether an IP address is an assigned public IP address.
44 * 58 *
45 * @param ipAddress the IP address to evaluate 59 * @param ipAddress the IP address to evaluate
......
...@@ -136,7 +136,9 @@ public class VbngManager implements VbngService { ...@@ -136,7 +136,9 @@ public class VbngManager implements VbngService {
136 */ 136 */
137 private void statusRecovery() { 137 private void statusRecovery() {
138 log.info("vBNG starts to recover from XOS record......"); 138 log.info("vBNG starts to recover from XOS record......");
139 - RestClient restClient = new RestClient(); 139 + RestClient restClient =
140 + new RestClient(vbngConfigurationService.getXosIpAddress(),
141 + vbngConfigurationService.getXosRestPort());
140 ObjectNode map = restClient.getRest(); 142 ObjectNode map = restClient.getRest();
141 if (map == null) { 143 if (map == null) {
142 log.info("Stop to recover vBNG status due to the vBNG map " 144 log.info("Stop to recover vBNG status due to the vBNG map "
......