aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps
diff options
context:
space:
mode:
authorAshlee Young <ashlee@wildernessvoice.com>2015-11-11 14:39:51 -0800
committerAshlee Young <ashlee@wildernessvoice.com>2015-11-11 14:40:00 -0800
commitbaac58c7c50e6f89eb0520e3f5b0e83a69839bd3 (patch)
tree9c5a149ee6cdf345fed7dfe8c97fcaac8959a70d /framework/src/onos/apps
parent8f92448e4f2f5d9c98036097bdabd1c40166908a (diff)
Updating onos src to commit id ec0425c18cbe49d368c600160f033acf9fe344ca
Change-Id: Iec2815bf7771080f25272842b852bd9d33f908ff Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/apps')
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java13
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java21
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java103
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java3
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java75
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java39
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java3
-rw-r--r--framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java9
-rw-r--r--framework/src/onos/apps/openstackswitching/pom.xml5
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java73
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java45
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java22
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java159
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java106
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java1
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java6
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java2
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java72
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java64
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml3
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java102
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java108
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java77
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java (renamed from framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java)4
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java (renamed from framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java)6
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java (renamed from framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java)2
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java (renamed from framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java)2
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java2
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java2
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java82
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java63
-rw-r--r--framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java2
32 files changed, 1125 insertions, 151 deletions
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
index 7c2127f9..e356c38b 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
@@ -19,8 +19,10 @@ import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.net.HostId;
+import java.util.List;
import java.util.Map;
+
/**
* DHCP Service Interface.
*/
@@ -56,12 +58,16 @@ public interface DhcpService {
/**
* Registers a static IP mapping with the DHCP Server.
+ * Supports the request from OpenStack
*
- * @param macID macID of the client
+ * @param macID macID of the client
* @param ipAddress IP Address requested for the client
- * @return true if the mapping was successfully registered, false otherwise
+ * @param fromOpenStack true if the request is from OpenStack
+ * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
+ * @return true if the mapping was successfully added, false otherwise
*/
- boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress);
+ boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ List<Ip4Address> addressList);
/**
* Removes a static IP mapping with the DHCP Server.
@@ -77,5 +83,4 @@ public interface DhcpService {
* @return list of available IPs
*/
Iterable<Ip4Address> getAvailableIPs();
-
}
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
index e263b3a2..bd2e16b3 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
@@ -19,8 +19,10 @@ import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.net.HostId;
+import java.util.List;
import java.util.Map;
+
/**
* DHCPStore Interface.
*/
@@ -43,15 +45,21 @@ public interface DhcpStore {
*/
Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP);
+
/**
* Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message.
*
* @param hostId Host Id of the client requesting an IP
* @param ipAddr IP Address being requested
* @param leaseTime Lease time offered by the server for this mapping
+ * @param fromOpenStack true if the request is from Openstack
+ * @param addressList subnetMask, DHCP IP Address, Router IP Address, Domain Server IP Address if the request
+ * from OpenStack
* @return returns true if the assignment was successful, false otherwise
*/
- boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime);
+ boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ List<Ip4Address> addressList);
+
/**
* Sets the default time for which suggested IP mappings are valid.
@@ -87,9 +95,11 @@ public interface DhcpStore {
*
* @param macID macID of the client
* @param ipAddr IP Address requested for the client
+ * @param fromOpenStack true if the request is from Openstack
+ * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
* @return true if the mapping was successfully registered, false otherwise
*/
- boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr);
+ boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, List<Ip4Address> addressList);
/**
* Removes a static IP mapping associated with the given MAC ID from the DHCP Server.
@@ -106,4 +116,11 @@ public interface DhcpStore {
*/
Iterable<Ip4Address> getAvailableIPs();
+ /**
+ *
+ *
+ * @param hostId
+ * @return
+ */
+ IpAssignment getIpAssignmentFromAllocationMap(HostId hostId);
}
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
index 9b3aa686..998579e2 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
@@ -33,6 +33,16 @@ public final class IpAssignment {
private final long leasePeriod;
+ private final Ip4Address subnetMask;
+
+ private final Ip4Address dhcpServer;
+
+ private final Ip4Address routerAddress;
+
+ private final Ip4Address domainServer;
+
+ private final boolean fromOpenStack;
+
private final AssignmentStatus assignmentStatus;
public enum AssignmentStatus {
@@ -42,6 +52,10 @@ public final class IpAssignment {
Option_Requested,
/**
+ * IP Assignment has been requested by a OpenStack.
+ */
+ Option_Requested_From_OpenStack,
+ /**
* IP has been assigned to a host.
*/
Option_Assigned,
@@ -58,16 +72,28 @@ public final class IpAssignment {
*
* @param ipAddress
* @param leasePeriod
+ * @param timestamp
* @param assignmentStatus
+ * @param subnetMask
+ * @param dhcpServer
+ * @param routerAddress
+ * @param domainServer
+ * @param fromOpenStack
*/
private IpAssignment(Ip4Address ipAddress,
long leasePeriod,
Date timestamp,
- AssignmentStatus assignmentStatus) {
+ AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer,
+ Ip4Address routerAddress, Ip4Address domainServer, boolean fromOpenStack) {
this.ipAddress = ipAddress;
this.leasePeriod = leasePeriod;
this.timestamp = timestamp;
this.assignmentStatus = assignmentStatus;
+ this.subnetMask = subnetMask;
+ this.dhcpServer = dhcpServer;
+ this.routerAddress = routerAddress;
+ this.domainServer = domainServer;
+ this.fromOpenStack = fromOpenStack;
}
/**
@@ -115,6 +141,26 @@ public final class IpAssignment {
return (int) this.leasePeriod * 1000;
}
+ public Ip4Address subnetMask() {
+ return subnetMask;
+ }
+
+ public Ip4Address dhcpServer() {
+ return dhcpServer;
+ }
+
+ public Ip4Address routerAddress() {
+ return routerAddress;
+ }
+
+ public Ip4Address domainServer() {
+ return domainServer;
+ }
+
+ public boolean fromOpenStack() {
+ return fromOpenStack;
+ }
+
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
@@ -122,6 +168,11 @@ public final class IpAssignment {
.add("timestamp", timestamp)
.add("lease", leasePeriod)
.add("assignmentStatus", assignmentStatus)
+ .add("subnetMask", subnetMask)
+ .add("dhcpServer", dhcpServer)
+ .add("routerAddress", routerAddress)
+ .add("domainServer", domainServer)
+ .add("fromOpenStack", fromOpenStack)
.toString();
}
@@ -157,6 +208,16 @@ public final class IpAssignment {
private AssignmentStatus assignmentStatus;
+ private Ip4Address subnetMask;
+
+ private Ip4Address dhcpServer;
+
+ private Ip4Address domainServer;
+
+ private Ip4Address routerAddress;
+
+ private boolean fromOpenStack = false;
+
private Builder() {
}
@@ -170,10 +231,8 @@ public final class IpAssignment {
public IpAssignment build() {
validateInputs();
- return new IpAssignment(ipAddress,
- leasePeriod,
- timeStamp,
- assignmentStatus);
+ return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask,
+ dhcpServer, domainServer, routerAddress, fromOpenStack);
}
public Builder ipAddress(Ip4Address addr) {
@@ -196,14 +255,48 @@ public final class IpAssignment {
return this;
}
+ public Builder subnetMask(Ip4Address subnetMask) {
+ this.subnetMask = subnetMask;
+ return this;
+ }
+
+ public Builder dhcpServer(Ip4Address dhcpServer) {
+ this.dhcpServer = dhcpServer;
+ return this;
+ }
+
+ public Builder domainServer(Ip4Address domainServer) {
+ this.domainServer = domainServer;
+ return this;
+ }
+
+ public Builder routerAddress(Ip4Address routerAddress) {
+ this.routerAddress = routerAddress;
+ return this;
+ }
+
+ public Builder fromOpenStack(boolean fromOpenStack) {
+ this.fromOpenStack = fromOpenStack;
+ return this;
+ }
+
+
private void validateInputs() {
checkNotNull(ipAddress, "IP Address must be specified");
checkNotNull(assignmentStatus, "Assignment Status must be specified");
checkNotNull(leasePeriod, "Lease Period must be specified");
checkNotNull(timeStamp, "Timestamp must be specified");
+ if (fromOpenStack) {
+ checkNotNull(subnetMask, "subnetMask must be specified in case of OpenStack");
+ checkNotNull(dhcpServer, "dhcpServer must be specified in case of OpenStack");
+ checkNotNull(domainServer, "domainServer must be specified in case of OpenStack");
+ checkNotNull(routerAddress, "routerAddress must be specified in case of OpenStack");
+ }
+
switch (assignmentStatus) {
case Option_Requested:
+ case Option_Requested_From_OpenStack:
case Option_Assigned:
case Option_Expired:
break;
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java
index 9f4f6580..e1ce8904 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.dhcp.cli;
+import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.packet.Ip4Address;
@@ -48,7 +49,7 @@ public class DhcpSetStaticMapping extends AbstractShellCommand {
try {
MacAddress macID = MacAddress.valueOf(macAddr);
Ip4Address ipAddress = Ip4Address.valueOf(ipAddr);
- if (dhcpService.setStaticMapping(macID, ipAddress)) {
+ if (dhcpService.setStaticMapping(macID, ipAddress, false, Lists.newArrayList())) {
print(DHCP_SUCCESS);
} else {
print(DHCP_FAILURE);
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
index 96d94a2b..4093f2d2 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
@@ -16,6 +16,7 @@
package org.onosproject.dhcp.impl;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -77,7 +78,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-
import static org.onlab.packet.MacAddress.valueOf;
import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
@@ -168,7 +168,6 @@ public class DhcpManager implements DhcpService {
cfgService.addListener(cfgListener);
factories.forEach(cfgService::registerConfigFactory);
cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class));
-
hostProviderService = hostProviderRegistry.register(hostProvider);
packetService.addProcessor(processor, PacketProcessor.director(0));
requestPackets();
@@ -242,8 +241,12 @@ public class DhcpManager implements DhcpService {
}
@Override
- public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress) {
- return dhcpStore.assignStaticIP(macID, ipAddress);
+ public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ List<Ip4Address> addressList) {
+ log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}",
+ macID.toString(), ipAddress.toString(), addressList.toString());
+
+ return dhcpStore.assignStaticIP(macID, ipAddress, fromOpenStack, addressList);
}
@Override
@@ -268,6 +271,26 @@ public class DhcpManager implements DhcpService {
*/
private Ethernet buildReply(Ethernet packet, Ip4Address ipOffered, byte outgoingMessageType) {
+ Ip4Address subnetMaskReply;
+ Ip4Address dhcpServerReply;
+ Ip4Address routerAddressReply;
+ Ip4Address domainServerReply;
+ IpAssignment ipAssignment;
+
+ ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC()));
+
+ if (ipAssignment != null && ipAssignment.fromOpenStack()) {
+ subnetMaskReply = ipAssignment.subnetMask();
+ dhcpServerReply = ipAssignment.dhcpServer();
+ domainServerReply = ipAssignment.domainServer();
+ routerAddressReply = ipAssignment.routerAddress();
+ } else {
+ subnetMaskReply = subnetMask;
+ dhcpServerReply = myIP;
+ routerAddressReply = routerAddress;
+ domainServerReply = domainServer;
+ }
+
// Ethernet Frame.
Ethernet ethReply = new Ethernet();
ethReply.setSourceMACAddress(myMAC);
@@ -278,7 +301,7 @@ public class DhcpManager implements DhcpService {
// IP Packet
IPv4 ipv4Packet = (IPv4) packet.getPayload();
IPv4 ipv4Reply = new IPv4();
- ipv4Reply.setSourceAddress(myIP.toInt());
+ ipv4Reply.setSourceAddress(dhcpServerReply.toInt());
ipv4Reply.setDestinationAddress(ipOffered.toInt());
ipv4Reply.setTtl(packetTTL);
@@ -299,7 +322,7 @@ public class DhcpManager implements DhcpService {
if (outgoingMessageType != DHCPPacketType.DHCPNAK.getValue()) {
dhcpReply.setYourIPAddress(ipOffered.toInt());
- dhcpReply.setServerIPAddress(myIP.toInt());
+ dhcpReply.setServerIPAddress(dhcpServerReply.toInt());
if (dhcpPacket.getGatewayIPAddress() == 0) {
ipv4Reply.setDestinationAddress(IP_BROADCAST.toInt());
}
@@ -322,7 +345,7 @@ public class DhcpManager implements DhcpService {
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue());
option.setLength((byte) 4);
- option.setData(myIP.toOctets());
+ option.setData(dhcpServerReply.toOctets());
optionList.add(option);
if (outgoingMessageType != DHCPPacketType.DHCPNAK.getValue()) {
@@ -352,7 +375,7 @@ public class DhcpManager implements DhcpService {
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_SubnetMask.getValue());
option.setLength((byte) 4);
- option.setData(subnetMask.toOctets());
+ option.setData(subnetMaskReply.toOctets());
optionList.add(option);
// Broadcast Address.
@@ -366,14 +389,14 @@ public class DhcpManager implements DhcpService {
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue());
option.setLength((byte) 4);
- option.setData(routerAddress.toOctets());
+ option.setData(routerAddressReply.toOctets());
optionList.add(option);
// DNS Server Address.
option = new DHCPOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue());
option.setLength((byte) 4);
- option.setData(domainServer.toOctets());
+ option.setData(domainServerReply.toOctets());
optionList.add(option);
}
@@ -384,7 +407,6 @@ public class DhcpManager implements DhcpService {
optionList.add(option);
dhcpReply.setOptions(optionList);
-
udpReply.setPayload(dhcpReply);
ipv4Reply.setPayload(udpReply);
ethReply.setPayload(ipv4Reply);
@@ -449,31 +471,40 @@ public class DhcpManager implements DhcpService {
if (incomingPacketType.getValue() == DHCPPacketType.DHCPDISCOVER.getValue()) {
outgoingPacketType = DHCPPacketType.DHCPOFFER;
- Ip4Address ipOffered = dhcpStore.suggestIP(hostId, requestedIP);
+ Ip4Address ipOffered = null;
+ ipOffered = dhcpStore.suggestIP(hostId, requestedIP);
+
if (ipOffered != null) {
Ethernet ethReply = buildReply(packet, ipOffered,
(byte) outgoingPacketType.getValue());
sendReply(context, ethReply);
}
-
} else if (incomingPacketType.getValue() == DHCPPacketType.DHCPREQUEST.getValue()) {
if (flagIfServerIP && flagIfRequestedIP) {
// SELECTING state
- if (myIP.equals(serverIP)) {
- if (dhcpStore.assignIP(hostId, requestedIP, leaseTime)) {
- outgoingPacketType = DHCPPacketType.DHCPACK;
- discoverHost(context, requestedIP);
- } else {
- outgoingPacketType = DHCPPacketType.DHCPNAK;
- }
+ if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMAC))
+ .fromOpenStack()) {
+ outgoingPacketType = DHCPPacketType.DHCPACK;
Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue());
sendReply(context, ethReply);
+ } else {
+ if (myIP.equals(serverIP)) {
+ if (dhcpStore.assignIP(hostId, requestedIP, leaseTime, false, Lists.newArrayList())) {
+ outgoingPacketType = DHCPPacketType.DHCPACK;
+ discoverHost(context, requestedIP);
+ } else {
+ outgoingPacketType = DHCPPacketType.DHCPNAK;
+ }
+ Ethernet ethReply = buildReply(packet, requestedIP,
+ (byte) outgoingPacketType.getValue());
+ sendReply(context, ethReply);
+ }
}
} else if (flagIfRequestedIP) {
// INIT-REBOOT state
- if (dhcpStore.assignIP(hostId, requestedIP, leaseTime)) {
+ if (dhcpStore.assignIP(hostId, requestedIP, leaseTime, false, Lists.newArrayList())) {
outgoingPacketType = DHCPPacketType.DHCPACK;
Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue());
sendReply(context, ethReply);
@@ -485,7 +516,7 @@ public class DhcpManager implements DhcpService {
int ciaadr = dhcpPayload.getClientIPAddress();
if (ciaadr != 0) {
Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr);
- if (dhcpStore.assignIP(hostId, clientIaddr, leaseTime)) {
+ if (dhcpStore.assignIP(hostId, clientIaddr, leaseTime, false, Lists.newArrayList())) {
outgoingPacketType = DHCPPacketType.DHCPACK;
discoverHost(context, clientIaddr);
} else if (packet.getEtherType() == Ethernet.TYPE_IPV4 &&
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
index 63f69d40..0f25495e 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
@@ -38,8 +38,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
+import java.util.List;
+import java.util.HashMap;
import java.util.Objects;
/**
@@ -105,7 +106,9 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
Ip4Address ipAddr = assignmentInfo.ipAddress();
- if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
+ if (assignmentInfo.fromOpenStack()) {
+ return assignmentInfo.ipAddress();
+ } else if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
status == IpAssignment.AssignmentStatus.Option_Requested) {
// Client has a currently Active Binding.
if (ipWithinRange(ipAddr)) {
@@ -160,9 +163,11 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) {
+ public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ List<Ip4Address> addressList) {
IpAssignment assignmentInfo;
+
if (allocationMap.containsKey(hostId)) {
assignmentInfo = allocationMap.get(hostId).value();
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
@@ -207,6 +212,20 @@ public class DistributedDhcpStore implements DhcpStore {
allocationMap.put(hostId, assignmentInfo);
return true;
}
+ } else if (fromOpenStack) {
+ assignmentInfo = IpAssignment.builder()
+ .ipAddress(ipAddr)
+ .timestamp(new Date())
+ .leasePeriod(leaseTime)
+ .fromOpenStack(true)
+ .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack)
+ .subnetMask((Ip4Address) addressList.toArray()[0])
+ .dhcpServer((Ip4Address) addressList.toArray()[1])
+ .domainServer((Ip4Address) addressList.toArray()[2])
+ .routerAddress((Ip4Address) addressList.toArray()[3])
+ .build();
+ allocationMap.put(hostId, assignmentInfo);
+ return true;
}
return false;
}
@@ -239,7 +258,8 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment assignment;
for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
assignment = entry.getValue().value();
- if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned) {
+ if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned
+ || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack) {
validMapping.put(entry.getKey(), assignment);
}
}
@@ -256,9 +276,10 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) {
+ public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack,
+ List<Ip4Address> addressList) {
HostId host = HostId.hostId(macID);
- return assignIP(host, ipAddr, -1);
+ return assignIP(host, ipAddr, -1, fromOpenStack, addressList);
}
@Override
@@ -299,6 +320,11 @@ public class DistributedDhcpStore implements DhcpStore {
}
}
+ @Override
+ public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) {
+ return allocationMap.get(hostId).value();
+ }
+
/**
* Fetches the next available IP from the free pool pf IPs.
*
@@ -326,3 +352,4 @@ public class DistributedDhcpStore implements DhcpStore {
return false;
}
}
+
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
index 646ab7ea..7a078df9 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
@@ -18,6 +18,7 @@ package org.onosproject.dhcp.rest;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.dhcp.DhcpService;
@@ -121,7 +122,7 @@ public class DHCPWebResource extends AbstractWebResource {
if (macID != null && ip != null) {
if (!service.setStaticMapping(MacAddress.valueOf(macID.asText()),
- Ip4Address.valueOf(ip.asText()))) {
+ Ip4Address.valueOf(ip.asText()), false, Lists.newArrayList())) {
throw new IllegalArgumentException("Static Mapping Failed. The IP maybe unavailable.");
}
}
diff --git a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
index fd4701c6..bb6b74cc 100644
--- a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
+++ b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
@@ -228,7 +228,8 @@ public class DhcpManagerTest {
return Ip4Address.valueOf(EXPECTED_IP);
}
- public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) {
+ public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ List<Ip4Address> addressList) {
return true;
}
@@ -255,7 +256,8 @@ public class DhcpManagerTest {
return map;
}
- public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) {
+ public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack,
+ List<Ip4Address> addressList) {
return true;
}
@@ -268,6 +270,9 @@ public class DhcpManagerTest {
ipList.add(Ip4Address.valueOf(EXPECTED_IP));
return ImmutableSet.copyOf(ipList);
}
+ public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) {
+ return null;
+ }
}
/**
diff --git a/framework/src/onos/apps/openstackswitching/pom.xml b/framework/src/onos/apps/openstackswitching/pom.xml
index 245b9e80..52129b6f 100644
--- a/framework/src/onos/apps/openstackswitching/pom.xml
+++ b/framework/src/onos/apps/openstackswitching/pom.xml
@@ -80,6 +80,11 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-app-dhcp-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java
index afaf7a22..0c139d8d 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java
@@ -15,11 +15,20 @@
*/
package org.onosproject.openstackswitching;
+import org.onlab.packet.ARP;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.InboundPacket;
+import org.onosproject.net.packet.OutboundPacket;
+import org.onosproject.net.packet.PacketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
+import java.nio.ByteBuffer;
+import java.util.Map;
/**
* It handles ARP packet from VMs.
@@ -28,16 +37,18 @@ public class OpenstackArpHandler {
private static Logger log = LoggerFactory
.getLogger(OpenstackArpHandler.class);
-
- HashMap<String, OpenstackPort> openstackPortHashMap;
+ private PacketService packetService;
+ private Map<String, OpenstackPort> openstackPortMap;
/**
- * Constructs an OpenstackArpHandler.
+ * Returns OpenstackArpHandler reference.
*
- * @param openstackPortMap port map
+ * @param openstackPortMap
+ * @param packetService
*/
- public OpenstackArpHandler(HashMap<String, OpenstackPort> openstackPortMap) {
- this.openstackPortHashMap = openstackPortMap;
+ public OpenstackArpHandler(Map<String, OpenstackPort> openstackPortMap, PacketService packetService) {
+ this.openstackPortMap = openstackPortMap;
+ this.packetService = packetService;
}
/**
@@ -46,6 +57,50 @@ public class OpenstackArpHandler {
* @param pkt ARP request packet
*/
public void processPacketIn(InboundPacket pkt) {
- log.warn("Received an ARP packet");
+ Ethernet ethernet = pkt.parsed();
+ ARP arp = (ARP) ethernet.getPayload();
+
+ if (arp.getOpCode() == ARP.OP_REQUEST) {
+ byte[] srcMacAddress = arp.getSenderHardwareAddress();
+ byte[] srcIPAddress = arp.getSenderProtocolAddress();
+ byte[] dstIPAddress = arp.getTargetProtocolAddress();
+
+ //Searches the Dst MAC Address based on openstackPortMap
+ MacAddress macAddress = null;
+
+ OpenstackPort openstackPort = openstackPortMap.values().stream().filter(e -> e.fixedIps().
+ containsValue(Ip4Address.valueOf(dstIPAddress))).findAny().orElse(null);
+
+ if (openstackPort != null) {
+ macAddress = openstackPort.macAddress();
+ log.debug("Found MACAddress: {}", macAddress.toString());
+ } else {
+ return;
+ }
+
+ //Creates a response packet
+ ARP arpReply = new ARP();
+ arpReply.setOpCode(ARP.OP_REPLY)
+ .setHardwareAddressLength(arp.getHardwareAddressLength())
+ .setHardwareType(arp.getHardwareType())
+ .setProtocolAddressLength(arp.getProtocolAddressLength())
+ .setProtocolType(arp.getProtocolType())
+ .setSenderHardwareAddress(macAddress.toBytes())
+ .setSenderProtocolAddress(dstIPAddress)
+ .setTargetHardwareAddress(srcMacAddress)
+ .setTargetProtocolAddress(srcIPAddress);
+
+ //Sends a response packet
+ ethernet.setDestinationMACAddress(srcMacAddress)
+ .setSourceMACAddress(macAddress)
+ .setEtherType(Ethernet.TYPE_ARP)
+ .setPayload(arpReply);
+
+ TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
+ builder.setOutput(pkt.receivedFrom().port());
+ OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(),
+ builder.build(), ByteBuffer.wrap(ethernet.serialize()));
+ packetService.emit(packet);
+ }
}
}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java
deleted file mode 100644
index 9c3641c1..00000000
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* Copyright 2015 Open Networking Laboratory
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.onosproject.openstackswitching;
-
-import org.onosproject.net.packet.InboundPacket;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * It handles DHCP request packets.
- */
-public class OpenstackDhcpHandler {
-
- private static Logger log = LoggerFactory
- .getLogger(OpenstackDhcpHandler.class);
-
- /**
- * Returns OpenstackDhcpHandler reference.
- */
- public OpenstackDhcpHandler() {
-
- }
-
- /**
- * Processes DHCP request packets.
- *
- * @param pkt DHCP request packet
- */
- public void processPacketIn(InboundPacket pkt) {
- log.warn("Received a DHCP packet");
- }
-}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
index dc7c0263..7bfdf290 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
@@ -26,8 +26,18 @@ public final class OpenstackNetwork {
private String name;
private String tenantId;
private String segmentId;
- private String networkType;
private String id;
+ private NetworkType networkType;
+
+ public enum NetworkType {
+ /**
+ * Currently only VXLAN moded is supported.
+ */
+ VXLAN,
+ VLAN,
+ STT,
+ LOCAL
+ }
/**
* Returns the builder object of the OpenstackNetwork class.
@@ -39,12 +49,12 @@ public final class OpenstackNetwork {
}
private OpenstackNetwork(String name, String tenantId, String id, String sid,
- String type) {
+ NetworkType type) {
this.name = checkNotNull(name);
this.tenantId = checkNotNull(tenantId);
this.segmentId = checkNotNull(sid);
this.id = checkNotNull(id);
- this.networkType = checkNotNull(type);
+ this.networkType = type;
}
public String name() {
@@ -63,7 +73,7 @@ public final class OpenstackNetwork {
return this.segmentId;
}
- public String networkType() {
+ public NetworkType networkType() {
return this.networkType;
}
@@ -72,7 +82,7 @@ public final class OpenstackNetwork {
private String tenantId;
private String id;
private String sid;
- private String networkType;
+ private NetworkType networkType;
public Builder name(String name) {
this.name = name;
@@ -98,7 +108,7 @@ public final class OpenstackNetwork {
return this;
}
- public Builder networkType(String type) {
+ public Builder networkType(NetworkType type) {
this.networkType = type;
return this;
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java
new file mode 100644
index 00000000..39d783e3
--- /dev/null
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstackswitching;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents the subnet information given by Neutron.
+ *
+ */
+public final class OpenstackSubnet {
+ private String name;
+ private boolean enableHhcp;
+ private String networkId;
+ private String tenantId;
+ private String dnsNameservers;
+ private String gatewayIp;
+ private String cidr;
+ private String id;
+
+ private OpenstackSubnet(String name, boolean enableHhcp, String networkId,
+ String tenantId, String dnsNameservers, String gatewayIp,
+ String cidr, String id) {
+ this.name = name;
+ this.enableHhcp = enableHhcp;
+ this.networkId = checkNotNull(networkId);
+ this.tenantId = checkNotNull(tenantId);
+ this.dnsNameservers = dnsNameservers;
+ this.gatewayIp = gatewayIp;
+ this.cidr = checkNotNull(cidr);
+ this.id = checkNotNull(id);
+ }
+
+ /**
+ * Returns OpenstackSubnet builder object.
+ *
+ * @return OpenstackSubnet builder
+ */
+ public static OpenstackSubnet.Builder builder() {
+ return new Builder();
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public boolean enableHhcp() {
+ return enableHhcp;
+ }
+
+ public String networkId() {
+ return networkId;
+ }
+
+ public String tenantId() {
+ return tenantId;
+ }
+
+ public String dnsNameservers() {
+ return dnsNameservers;
+ }
+
+ public String gatewayIp() {
+ return gatewayIp;
+ }
+
+ public String cidr() {
+ return cidr;
+ }
+
+ public String id() {
+ return id;
+ }
+
+ // TODO : Implement the following functions when necessary
+
+ /**
+ * OpenstackSubnet Builder class.
+ *
+ */
+ public static final class Builder {
+ private String name;
+ private boolean enableDhcp;
+ private String networkId;
+ private String tenantId;
+ private String dnsNameservers;
+ private String gatewayIp;
+ private String cidr;
+ private String id;
+
+ Builder() {}
+
+ public Builder setName(String name) {
+ this.name = name;
+
+ return this;
+ }
+
+ public Builder setEnableDhcp(boolean enableDhcp) {
+ this.enableDhcp = enableDhcp;
+
+ return this;
+ }
+
+ public Builder setNetworkId(String networkId) {
+ this.networkId = networkId;
+
+ return this;
+ }
+
+ public Builder setTenantId(String tenantId) {
+ this.tenantId = tenantId;
+
+ return this;
+ }
+
+ public Builder setDnsNameservers(String dnsNameservers) {
+ this.dnsNameservers = dnsNameservers;
+
+ return this;
+ }
+
+ public Builder setGatewayIp(String gatewayIp) {
+ this.gatewayIp = gatewayIp;
+
+ return this;
+ }
+
+ public Builder setCidr(String cidr) {
+ this.cidr = cidr;
+
+ return this;
+ }
+
+ public Builder setId(String id) {
+ this.id = id;
+
+ return this;
+ }
+
+ public OpenstackSubnet build() {
+ return new OpenstackSubnet(name, enableDhcp, networkId, tenantId,
+ dnsNameservers, gatewayIp, cidr, id);
+ }
+ }
+}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java
index baae7f80..4be8a50d 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java
@@ -24,13 +24,12 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ethernet;
-import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.MacAddress;
-import org.onlab.packet.UDP;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.dhcp.DhcpService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
@@ -45,8 +44,8 @@ import org.onosproject.net.packet.PacketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -73,12 +72,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowObjectiveService flowObjectiveService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DhcpService dhcpService;
public static final int DHCP_PORT = 67;
private ApplicationId appId;
private OpenstackArpHandler arpHandler;
- private OpenstackDhcpHandler dhcpHandler = new OpenstackDhcpHandler();
+
private OpenstackSwitchingRulePopulator rulePopulator;
private ExecutorService deviceEventExcutorService = Executors.newFixedThreadPool(10);
@@ -86,12 +87,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
private InternalDeviceListener internalDeviceListener = new InternalDeviceListener();
// Map <port_id, OpenstackPort>
- private HashMap<String, OpenstackPort> openstackPortMap;
+ private Map<String, OpenstackPort> openstackPortMap;
// Map <network_id, OpenstackNetwork>
- private HashMap<String, OpenstackNetwork> openstackNetworkMap;
+ private Map<String, OpenstackNetwork> openstackNetworkMap;
+ // Map <subnet_id, OpenstackSubner>
+ private Map<String, OpenstackSubnet> openstackSubnetMap;
// Map <vni, List <Entry <portName, host ip>>
- private HashMap<String, List<PortInfo>> vniPortMap;
- private HashMap<Ip4Address, Port> tunnelPortMap;
+ private Map<String, List<PortInfo>> vniPortMap;
+ private Map<Ip4Address, Port> tunnelPortMap;
@Activate
@@ -104,11 +107,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
openstackPortMap = Maps.newHashMap();
openstackNetworkMap = Maps.newHashMap();
+ openstackSubnetMap = Maps.newHashMap();
+
vniPortMap = Maps.newHashMap();
tunnelPortMap = Maps.newHashMap();
-
- arpHandler = new OpenstackArpHandler(openstackPortMap);
-
+ arpHandler = new OpenstackArpHandler(openstackPortMap, packetService);
log.info("Started");
}
@@ -124,9 +127,43 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
@Override
public void createPorts(OpenstackPort openstackPort) {
+ //For DHCP purpose
+ //registerDhcpInfo(openstackPort);
openstackPortMap.put(openstackPort.id(), openstackPort);
}
+ /*
+ private void registerDhcpInfo(OpenstackPort openstackPort) {
+ Ip4Address ip4Address;
+ Ip4Address subnetMask;
+ Ip4Address dhcpServer;
+ Ip4Address gatewayIPAddress;
+ Ip4Address domainServer;
+ OpenstackSubnet openstackSubnet;
+
+ ip4Address = (Ip4Address) openstackPort.fixedIps().values().toArray()[0];
+
+ openstackSubnet = openstackSubnetMap.values().stream()
+ .filter(n -> n.networkId().equals(openstackPort.networkId()))
+ .findFirst().get();
+
+ int prefix;
+ String[] parts = openstackSubnet.cidr().split("/");
+ prefix = Integer.parseInt(parts[1]);
+ int mask = 0xffffffff << (32 - prefix);
+ byte[] bytes = new byte[]{(byte) (mask >>> 24),
+ (byte) (mask >> 16 & 0xff), (byte) (mask >> 8 & 0xff), (byte) (mask & 0xff)};
+
+ subnetMask = Ip4Address.valueOf(bytes);
+ gatewayIPAddress = Ip4Address.valueOf(openstackSubnet.gatewayIp());
+ dhcpServer = gatewayIPAddress;
+ domainServer = Ip4Address.valueOf("8.8.8.8");
+
+ dhcpService.setStaticMappingOpenstack(openstackPort.macAddress(),
+ ip4Address, subnetMask, dhcpServer, gatewayIPAddress, domainServer);
+ }
+ */
+
@Override
public void deletePorts() {
@@ -142,8 +179,15 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
openstackNetworkMap.put(openstackNetwork.id(), openstackNetwork);
}
+
+ @Override
+ public void createSubnet(OpenstackSubnet openstackSubnet) {
+ openstackSubnetMap.put(openstackSubnet.id(), openstackSubnet);
+ log.debug("Added Subnet Info {}", openstackNetworkMap.get(openstackSubnet.id()));
+ }
+
private void processDeviceAdded(Device device) {
- log.warn("device {} is added", device.id());
+ log.debug("device {} is added", device.id());
rulePopulator.populateDefaultRules(device.id());
}
@@ -152,7 +196,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
// TODO: Make it stateless
// TODO: All the logics need to be processed inside of the rulePopulator class
synchronized (vniPortMap) {
- log.warn("port {} is updated", port.toString());
+ log.debug("port {} is updated", port.toString());
updatePortMaps(device, port);
if (!port.annotations().value("portName").equals("vxlan")) {
@@ -163,7 +207,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
}
private void processPortRemoved(Device device, Port port) {
- log.warn("port {} is removed", port.toString());
+ log.debug("port {} is removed", port.toString());
// TODO: need to update the vniPortMap
}
@@ -182,7 +226,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
// TODO: Avoid duplicate flow rule set up for VMs in other Cnode
// (possibly avoided by flowrule subsystem?)
if (tunnelPortMap.get(hostIpAddress) == null) {
- log.warn("There is no tunnel port information");
+ log.debug("There is no tunnel port information");
return;
}
String vni = getVniForPort(portName);
@@ -251,20 +295,19 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
.filter(p -> p.id().startsWith(uuid))
.findFirst().get();
if (port == null) {
- log.warn("No port information for port {}", portName);
+ log.debug("No port information for port {}", portName);
return null;
}
- //OpenstackSubnet subnet = openstackSubnetMap.values().stream()
- // .filter(s -> s.networkId().equals(port.networkId()))
- // .findFirst().get();
- //if (subnet == null) {
- // log.warn("No subnet information for network {}", subnet.id());
- // return null;
- //}
+ OpenstackSubnet subnet = openstackSubnetMap.values().stream()
+ .filter(s -> s.networkId().equals(port.networkId()))
+ .findFirst().get();
+ if (subnet == null) {
+ log.debug("No subnet information for network {}", subnet.id());
+ return null;
+ }
- //return Ip4Prefix.valueOf(subnet.cidr());
- return null;
+ return Ip4Prefix.valueOf(subnet.cidr());
}
/**
@@ -280,14 +323,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
.filter(p -> p.id().startsWith(uuid))
.findFirst().get();
if (port == null) {
- log.warn("No port information for port {}", portName);
+ log.debug("No port information for port {}", portName);
return null;
}
OpenstackNetwork network = openstackNetworkMap.values().stream()
.filter(n -> n.id().equals(port.networkId()))
.findFirst().get();
if (network == null) {
- log.warn("No VNI information for network {}", network.id());
+ log.debug("No VNI information for network {}", network.id());
return null;
}
@@ -357,15 +400,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
if (ethernet.getEtherType() == Ethernet.TYPE_ARP) {
arpHandler.processPacketIn(pkt);
- } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
- IPv4 ipPacket = (IPv4) ethernet.getPayload();
-
- if (ipPacket.getProtocol() == IPv4.PROTOCOL_UDP) {
- UDP udpPacket = (UDP) ipPacket.getPayload();
- if (udpPacket.getDestinationPort() == DHCP_PORT) {
- dhcpHandler.processPacketIn(pkt);
- }
- }
}
}
}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
index 9ead05f0..661a873e 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
@@ -87,7 +87,6 @@ public class OpenstackSwitchingRulePopulator {
*/
public void populateDefaultRules(DeviceId id) {
- //setFlowRuleForDHCP(id);
setFlowRuleForArp(id);
log.warn("Default rule has been set");
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java
index d97b39c8..3d40d51d 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java
@@ -46,4 +46,10 @@ public interface OpenstackSwitchingService {
*/
void createNetwork(OpenstackNetwork openstackNetwork);
+ /**
+ * Store the subnet information created by openstack.
+ *
+ * @param openstackSubnet subnet information
+ */
+ void createSubnet(OpenstackSubnet openstackSubnet);
}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
index 43bd1583..fc1509d4 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
@@ -54,6 +54,8 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
.id(id);
if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) {
+ onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkInfo.path(NETWORK_TYPE).
+ asText().toUpperCase()));
onb.name(networkInfo.path(NETWORK_TYPE).asText());
onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java
new file mode 100644
index 00000000..a643057a
--- /dev/null
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstackswitching.web;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.openstackswitching.OpenstackSubnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * It encodes and decodes the OpenstackSubnet.
+ */
+
+public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
+ private static Logger log = LoggerFactory
+ .getLogger(OpenstackSubnetCodec.class);
+
+ // JSON Field names
+ private static final String SUBNET = "subnet";
+ private static final String NAME = "name";
+ private static final String ENABLE_DHCP = "enable_dhcp";
+ private static final String NETWORK_ID = "network_id";
+ private static final String TENANT_ID = "tenant_id";
+ private static final String DNS_NAMESERVERS = "dns_nameservers";
+ private static final String GATEWAY_IP = "gateway_ip";
+ private static final String CIDR = "cidr";
+ private static final String ID = "id";
+
+ @Override
+ public OpenstackSubnet decode(ObjectNode json, CodecContext context) {
+ JsonNode subnetInfo = json.get(SUBNET);
+
+ String name = subnetInfo.path(NAME).asText();
+ boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean();
+ String networkId = subnetInfo.path(NETWORK_ID).asText();
+ String tenantId = subnetInfo.path(TENANT_ID).asText();
+ String dnsNameservsers = subnetInfo.path(DNS_NAMESERVERS).asText();
+ String gatewayIp = subnetInfo.path(GATEWAY_IP).asText();
+ String cidr = subnetInfo.path(CIDR).asText();
+ String id = subnetInfo.path(ID).asText();
+
+ OpenstackSubnet openstackSubnet = OpenstackSubnet.builder()
+ .setName(name)
+ .setEnableDhcp(enableDhcp)
+ .setNetworkId(networkId)
+ .setTenantId(tenantId)
+ .setDnsNameservers(dnsNameservsers)
+ .setGatewayIp(gatewayIp)
+ .setCidr(cidr)
+ .setId(id)
+ .build();
+ return openstackSubnet;
+ }
+}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java
new file mode 100644
index 00000000..af1ae9dd
--- /dev/null
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstackswitching.web;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.openstackswitching.OpenstackSubnet;
+import org.onosproject.openstackswitching.OpenstackSwitchingService;
+import org.onosproject.rest.AbstractWebResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+@Path("subnets")
+public class OpenstackSubnetWebResource extends AbstractWebResource {
+ protected static final Logger log = LoggerFactory
+ .getLogger(OpenstackSubnetWebResource.class);
+
+ private static final OpenstackSubnetCodec SUBNET_CODEC = new OpenstackSubnetCodec();
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createSubnet(InputStream input) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode subnetNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackSubnet openstackSubnet = SUBNET_CODEC.decode(subnetNode, this);
+
+ OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
+ switchingService.createSubnet(openstackSubnet);
+ log.info("REST API subnets is called with {}", subnetNode.toString());
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("Creates VirtualSubnet failed because of exception {}",
+ e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml
index 53b0e2e9..4f50ef72 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml
+++ b/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml
@@ -31,7 +31,8 @@
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
org.onosproject.openstackswitching.web.OpenstackPortWebResource,
- org.onosproject.openstackswitching.web.OpenstackNetworkWebResource
+ org.onosproject.openstackswitching.web.OpenstackNetworkWebResource,
+ org.onosproject.openstackswitching.web.OpenstackSubnetWebResource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java
new file mode 100644
index 00000000..e853ec2f
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vtnrsc;
+
+import java.util.List;
+
+/**
+ * Representation of a Router.
+ */
+public interface Router {
+
+ /**
+ * Coarse classification of the type of the Router.
+ */
+ public enum Status {
+ /**
+ * Signifies that a router is currently active.
+ */
+ ACTIVE,
+ /**
+ * Signifies that a router is currently inactive.
+ */
+ INACTIVE
+ }
+
+ /**
+ * Returns the router identifier.
+ *
+ * @return identifier
+ */
+ RouterId id();
+
+ /**
+ * Returns the router Name.
+ *
+ * @return routerName
+ */
+ String name();
+
+ /**
+ * Returns the router admin state.
+ *
+ * @return true or false
+ */
+ boolean adminStateUp();
+
+ /**
+ * Returns the status of router.
+ *
+ * @return RouterStatus
+ */
+ Status status();
+
+ /**
+ * Returns the distributed status of this router.
+ * If true, indicates a distributed router.
+ *
+ * @return true or false
+ */
+ boolean distributed();
+
+ /**
+ * Returns the RouterGateway of router.
+ *
+ * @return routerGateway
+ */
+ RouterGateway externalGatewayInfo();
+
+ /**
+ * Returns the gatewayPortid of router.
+ *
+ * @return virtualPortId
+ */
+ VirtualPortId gatewayPortid();
+
+ /**
+ * Returns the owner(tenant) of this router.
+ *
+ * @return tenantId
+ */
+ TenantId tenantId();
+
+ /**
+ * Returns the router list of router.
+ *
+ * @return routes
+ */
+ List<String> routes();
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java
new file mode 100644
index 00000000..9a755561
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vtnrsc;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * Representation of a Router gateway.
+ */
+public final class RouterGateway {
+
+ private final TenantNetworkId networkId;
+ private final boolean enableSnat;
+ private final Collection<FixedIp> externalFixedIps;
+
+ // Public construction is prohibited
+ private RouterGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ this.networkId = checkNotNull(networkId, "networkId cannot be null");
+ this.enableSnat = checkNotNull(enableSnat, "enableSnat cannot be null");
+ this.externalFixedIps = checkNotNull(externalFixedIps, "externalFixedIps cannot be null");
+ }
+
+ /**
+ * Creates router gateway object.
+ *
+ * @param networkId network identifier
+ * @param enableSnat SNAT enable or not
+ * @param externalFixedIps external fixed IP
+ * @return RouterGateway
+ */
+ public static RouterGateway routerGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ return new RouterGateway(networkId, enableSnat, externalFixedIps);
+ }
+
+ /**
+ * Returns network identifier.
+ *
+ * @return networkId
+ */
+ public TenantNetworkId networkId() {
+ return networkId;
+ }
+
+ /**
+ * Return SNAT enable or not.
+ *
+ * @return enableSnat
+ */
+ public boolean enableSnat() {
+ return enableSnat;
+ }
+
+ /**
+ * Return external fixed Ip.
+ *
+ * @return externalFixedIps
+ */
+ public Collection<FixedIp> externalFixedIps() {
+ return externalFixedIps;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkId, enableSnat, externalFixedIps);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof RouterGateway) {
+ final RouterGateway that = (RouterGateway) obj;
+ return Objects.equals(this.networkId, that.networkId)
+ && Objects.equals(this.enableSnat, that.enableSnat)
+ && Objects.equals(this.externalFixedIps, that.externalFixedIps);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("networkId", networkId)
+ .add("enableSnat", enableSnat)
+ .add("externalFixedIps", externalFixedIps)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java
new file mode 100644
index 00000000..d396c0d1
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vtnrsc;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+/**
+ * Immutable representation of a router identifier.
+ */
+public final class RouterId {
+
+ private final String routerId;
+
+ // Public construction is prohibited
+ private RouterId(String routerId) {
+ checkNotNull(routerId, "routerId cannot be null");
+ this.routerId = routerId;
+ }
+
+ /**
+ * Creates a router identifier.
+ *
+ * @param routerId the router identifier
+ * @return the router identifier
+ */
+ public static RouterId valueOf(String routerId) {
+ return new RouterId(routerId);
+ }
+
+ /**
+ * Returns the router identifier.
+ *
+ * @return the router identifier
+ */
+ public String routerId() {
+ return routerId;
+ }
+
+ @Override
+ public int hashCode() {
+ return routerId.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof RouterId) {
+ final RouterId that = (RouterId) obj;
+ return Objects.equals(this.routerId, that.routerId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("routerId", routerId).toString();
+ }
+}
+
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java
index e379be81..c160d221 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.vtnrsc.flowClassifier;
+package org.onosproject.vtnrsc.flowclassifier;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.FlowClassifierId;
@@ -69,4 +69,4 @@ public interface FlowClassifierService {
* @return true if Flow Classifier removal is success otherwise return false.
*/
boolean removeFlowClassifier(FlowClassifierId id);
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java
index ca01c434..ee5873d6 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.vtnrsc.flowClassifier.impl;
+package org.onosproject.vtnrsc.flowclassifier.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -29,7 +29,7 @@ import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.WallClockTimestamp;
import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.vtnrsc.FlowClassifier;
-import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
@@ -121,4 +121,4 @@ public class FlowClassifierManager implements FlowClassifierService {
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java
index 4ea050b3..62b5603d 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java
@@ -17,4 +17,4 @@
/**
* Provides implementation of the flow Classifier service.
*/
-package org.onosproject.vtnrsc.flowClassifier.impl;
+package org.onosproject.vtnrsc.flowclassifier.impl;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java
index 07584170..c8c75bf3 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java
@@ -17,4 +17,4 @@
/**
* Service for interacting with flow Classifier of SFC.
*/
-package org.onosproject.vtnrsc.flowClassifier;
+package org.onosproject.vtnrsc.flowclassifier;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java
index 88fecf8d..a87bdb99 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.vtnrsc.portpair;
+package org.onosproject.vtnrsc.portchain;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java
index 7da4c489..25db9d2e 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.vtnrsc.portpair;
+package org.onosproject.vtnrsc.portpairgroup;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java
new file mode 100644
index 00000000..ce6b6c00
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vtnrsc.router;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+import org.onosproject.vtnrsc.RouterGateway;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.FixedIp;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for RouterGateway class.
+ */
+public class RouterGatewayTest {
+ final TenantNetworkId networkId1 = TenantNetworkId.networkId("1");
+ final TenantNetworkId networkId2 = TenantNetworkId.networkId("2");
+ final Set<FixedIp> fixedIpSet1 = new HashSet<>();
+ final Set<FixedIp> fixedIpSet2 = new HashSet<>();
+
+ /**
+ * Checks that the RouterGateway class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(RouterGateway.class);
+ }
+
+ /**
+ * Checks the operation of equals().
+ */
+ @Test
+ public void testEquals() {
+ RouterGateway routerGateway1 = RouterGateway.routerGateway(networkId1,
+ true,
+ fixedIpSet1);
+ RouterGateway routerGateway2 = RouterGateway.routerGateway(networkId1,
+ true,
+ fixedIpSet1);
+ RouterGateway routerGateway3 = RouterGateway.routerGateway(networkId2,
+ true,
+ fixedIpSet2);
+ new EqualsTester().addEqualityGroup(routerGateway1, routerGateway2)
+ .addEqualityGroup(routerGateway3).testEquals();
+ }
+
+ /**
+ * Checks the construction of a RouterGateway object.
+ */
+ @Test
+ public void testConstruction() {
+ RouterGateway routerGateway = RouterGateway.routerGateway(networkId1,
+ true,
+ fixedIpSet1);
+ assertThat(fixedIpSet1, is(notNullValue()));
+ assertThat(fixedIpSet1, is(routerGateway.externalFixedIps()));
+ assertThat(networkId1, is(notNullValue()));
+ assertThat(networkId1, is(routerGateway.networkId()));
+ assertThat(routerGateway.enableSnat(), is(true));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java
new file mode 100644
index 00000000..3751c11a
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vtnrsc.router;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+import org.junit.Test;
+import org.onosproject.vtnrsc.RouterId;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for RouterId class.
+ */
+public class RouterIdTest {
+ final RouterId routerId1 = RouterId.valueOf("1");
+ final RouterId sameAsRouterId1 = RouterId.valueOf("1");
+ final RouterId routerId2 = RouterId.valueOf("2");
+
+ /**
+ * Checks that the RouterId class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(RouterId.class);
+ }
+
+ /**
+ * Checks the operation of equals() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester().addEqualityGroup(routerId1, sameAsRouterId1).addEqualityGroup(routerId2)
+ .testEquals();
+ }
+
+ /**
+ * Checks the construction of a RouterId object.
+ */
+ @Test
+ public void testConstruction() {
+ final String routerIdValue = "s";
+ final RouterId routerId = RouterId.valueOf(routerIdValue);
+ assertThat(routerId, is(notNullValue()));
+ assertThat(routerId.routerId(), is(routerIdValue));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
index b5b8252b..7a57c0ab 100644
--- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
+++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
@@ -39,7 +39,7 @@ import javax.ws.rs.core.Response;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.rest.AbstractWebResource;
-import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
import org.onosproject.vtnweb.web.FlowClassifierCodec;
import com.fasterxml.jackson.databind.ObjectMapper;