ONOS-2197 Adding Router Address and DNS to the config
Change-Id: I01bda8824b1342872ba7890b824f6a5f38026515
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPConfig.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPConfig.java
index 4b678f1..16fcdd7 100644
--- a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPConfig.java
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPConfig.java
@@ -28,6 +28,8 @@
public static final String MY_MAC = "mac";
public static final String SUBNET_MASK = "subnet";
public static final String BROADCAST_ADDRESS = "broadcast";
+ public static final String ROUTER_ADDRESS = "router";
+ public static final String DOMAIN_SERVER = "domain";
public static final String TTL = "ttl";
public static final String LEASE_TIME = "lease";
public static final String RENEW_TIME = "renew";
@@ -184,4 +186,42 @@
public BasicElementConfig rebindTime(String rebind) {
return (BasicElementConfig) setOrClear(REBIND_TIME, rebind);
}
+
+ /**
+ * Returns the Router Address.
+ *
+ * @return router address or null if not set
+ */
+ public String routerAddress() {
+ return get(ROUTER_ADDRESS, null);
+ }
+
+ /**
+ * Sets the Router Address.
+ *
+ * @param router new router address; null to clear
+ * @return self
+ */
+ public BasicElementConfig routerAddress(String router) {
+ return (BasicElementConfig) setOrClear(ROUTER_ADDRESS, router);
+ }
+
+ /**
+ * Returns the Domain Server Address.
+ *
+ * @return domain server address or null if not set
+ */
+ public String domainServer() {
+ return get(DOMAIN_SERVER, null);
+ }
+
+ /**
+ * Sets the Domain Server Address.
+ *
+ * @param domain new domain server address; null to clear
+ * @return self
+ */
+ public BasicElementConfig domainServer(String domain) {
+ return (BasicElementConfig) setOrClear(DOMAIN_SERVER, domain);
+ }
}
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPManager.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPManager.java
index 39cf17d..520af42 100644
--- a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPManager.java
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPManager.java
@@ -128,6 +128,10 @@
private static String broadcastAddress = "10.255.255.255";
+ private static String routerAddress = "10.0.0.2";
+
+ private static String domainServer = "10.0.0.2";
+
private static Ip4Address startIPRange = Ip4Address.valueOf("10.1.0.140");
private static Ip4Address endIPRange = Ip4Address.valueOf("10.1.0.160");
@@ -320,14 +324,16 @@
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue());
option.setLength((byte) 4);
- option.setData(myIPAddress.toOctets());
+ ipAddress = Ip4Address.valueOf(routerAddress);
+ option.setData(ipAddress.toOctets());
optionList.add(option);
// DNS Server Address.
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue());
option.setLength((byte) 4);
- option.setData(myIPAddress.toOctets());
+ ipAddress = Ip4Address.valueOf(domainServer);
+ option.setData(ipAddress.toOctets());
optionList.add(option);
// End Option.
@@ -501,6 +507,12 @@
if (cfg.broadcastAddress() != null) {
broadcastAddress = cfg.broadcastAddress();
}
+ if (cfg.routerAddress() != null) {
+ routerAddress = cfg.routerAddress();
+ }
+ if (cfg.domainServer() != null) {
+ domainServer = cfg.domainServer();
+ }
if (cfg.ttl() != null) {
packetTTL = Byte.valueOf(cfg.ttl());
}
@@ -550,9 +562,7 @@
reconfigureStore(cfg);
log.info("Reconfigured Store");
}
-
}
- log.info("Reconfigured");
}
}
}
\ No newline at end of file
diff --git a/onos-app-dhcpserver/src/test/resources/dhcp-cfg.json b/onos-app-dhcpserver/src/test/resources/dhcp-cfg.json
index c4aefff..21920d3 100644
--- a/onos-app-dhcpserver/src/test/resources/dhcp-cfg.json
+++ b/onos-app-dhcpserver/src/test/resources/dhcp-cfg.json
@@ -6,6 +6,8 @@
"mac": "1f:2f:3f:4f:5f:6f",
"subnet": "255.0.0.0",
"broadcast": "10.255.255.255",
+ "router": "10.0.0.1",
+ "domain": "10.0.0.1",
"ttl": "63",
"lease": "300",
"renew": "150",