aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/vtn/vtnrsc/src/main/java/org')
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFloatingIp.java140
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultRouter.java146
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIp.java94
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIpId.java85
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterInterface.java119
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java95
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java92
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java90
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java103
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java97
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java76
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java71
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java99
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java56
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java50
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEvent.java77
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEventFeedback.java123
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscListener.java26
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpEvent.java60
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpListener.java25
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpService.java108
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java348
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java44
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java55
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterEvent.java59
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterListener.java25
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterService.java90
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/RouterManager.java269
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceEvent.java62
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceListener.java27
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceService.java80
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/RouterInterfaceManager.java235
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java94
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java472
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java42
48 files changed, 3979 insertions, 59 deletions
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFloatingIp.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFloatingIp.java
new file mode 100644
index 00000000..7a297d90
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFloatingIp.java
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.onlab.packet.IpAddress;
+
+/**
+ * Default implementation of FloatingIp interface.
+ */
+public final class DefaultFloatingIp implements FloatingIp {
+
+ private final FloatingIpId id;
+ private final TenantId tenantId;
+ private final TenantNetworkId networkId;
+ private final VirtualPortId portId;
+ private final RouterId routerId;
+ private final IpAddress floatingIp;
+ private final IpAddress fixedIp;
+ private final Status status;
+
+ /**
+ *
+ * Creates a floating Ip object.
+ *
+ * @param id floatingIp identifier
+ * @param tenantId tenant identifier
+ * @param networkId the identifier of network associated with the floating Ip
+ * @param portId port identifier
+ * @param routerId router identifier
+ * @param floatingIp floatingIp address
+ * @param fixedIp the fixed Ip associated with the floating Ip
+ * @param status the floating Ip status
+ */
+ public DefaultFloatingIp(FloatingIpId id, TenantId tenantId,
+ TenantNetworkId networkId, VirtualPortId portId,
+ RouterId routerId, IpAddress floatingIp,
+ IpAddress fixedIp, Status status) {
+ this.id = checkNotNull(id, "id cannot be null");
+ this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
+ this.networkId = checkNotNull(networkId, "networkId cannot be null");
+ this.portId = portId;
+ this.routerId = routerId;
+ this.floatingIp = checkNotNull(floatingIp, "floatingIp cannot be null");
+ this.fixedIp = fixedIp;
+ this.status = checkNotNull(status, "status cannot be null");
+ }
+
+ @Override
+ public FloatingIpId id() {
+ return id;
+ }
+
+ @Override
+ public TenantId tenantId() {
+ return tenantId;
+ }
+
+ @Override
+ public TenantNetworkId networkId() {
+ return networkId;
+ }
+
+ @Override
+ public VirtualPortId portId() {
+ return portId;
+ }
+
+ @Override
+ public RouterId routerId() {
+ return routerId;
+ }
+
+ @Override
+ public IpAddress floatingIp() {
+ return floatingIp;
+ }
+
+ @Override
+ public IpAddress fixedIp() {
+ return fixedIp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, tenantId, networkId, portId, routerId,
+ floatingIp, fixedIp, status);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultFloatingIp) {
+ final DefaultFloatingIp that = (DefaultFloatingIp) obj;
+ return Objects.equals(this.id, that.id)
+ && Objects.equals(this.tenantId, that.tenantId)
+ && Objects.equals(this.networkId, that.networkId)
+ && Objects.equals(this.portId, that.portId)
+ && Objects.equals(this.routerId, that.routerId)
+ && Objects.equals(this.floatingIp, that.floatingIp)
+ && Objects.equals(this.fixedIp, that.fixedIp)
+ && Objects.equals(this.status, that.status);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("id", id).add("tenantId", tenantId)
+ .add("networkId", networkId).add("portId", portId)
+ .add("routerId", routerId).add("floatingIp", floatingIp)
+ .add("fixedIp", fixedIp).add("floatingIpStatus", status)
+ .toString();
+ }
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultRouter.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultRouter.java
new file mode 100644
index 00000000..a2404f56
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultRouter.java
@@ -0,0 +1,146 @@
+/*
+ * 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.List;
+import java.util.Objects;
+
+/**
+ * Default implementation of router interface.
+ */
+public final class DefaultRouter implements Router {
+ private final RouterId id;
+ private final String name;
+ private final boolean adminStateUp;
+ private final Status status;
+ private final boolean distributed;
+ private final RouterGateway externalGatewayInfo;
+ private final VirtualPortId gatewayPortId;
+ private final TenantId tenantId;
+ private final List<String> routes;
+
+ /**
+ * Creates router object.
+ *
+ * @param id router identifier
+ * @param routerName the name of router
+ * @param adminStateUp the status of admin state
+ * @param status the status of router
+ * @param distributed the status of router distributed
+ * @param externalGatewayInfo the gateway info of router
+ * @param gatewayPortId the port identifier of router gateway
+ * @param tenantId the tenant identifier
+ * @param routes the routes configure
+ */
+ public DefaultRouter(RouterId id, String routerName, boolean adminStateUp,
+ Status status, boolean distributed,
+ RouterGateway externalGatewayInfo,
+ VirtualPortId gatewayPortId, TenantId tenantId,
+ List<String> routes) {
+ this.id = checkNotNull(id, "id cannot be null");
+ this.name = routerName;
+ this.adminStateUp = checkNotNull(adminStateUp, "adminStateUp cannot be null");
+ this.status = checkNotNull(status, "status cannot be null");
+ this.distributed = checkNotNull(distributed, "distributed cannot be null");
+ this.externalGatewayInfo = externalGatewayInfo;
+ this.gatewayPortId = gatewayPortId;
+ this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
+ this.routes = routes;
+ }
+
+ @Override
+ public RouterId id() {
+ return id;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public boolean adminStateUp() {
+ return adminStateUp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public boolean distributed() {
+ return distributed;
+ }
+
+ @Override
+ public RouterGateway externalGatewayInfo() {
+ return externalGatewayInfo;
+ }
+
+ @Override
+ public VirtualPortId gatewayPortid() {
+ return gatewayPortId;
+ }
+
+ @Override
+ public TenantId tenantId() {
+ return tenantId;
+ }
+
+ @Override
+ public List<String> routes() {
+ return routes;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, name, adminStateUp, status, distributed,
+ externalGatewayInfo, gatewayPortId, routes);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultRouter) {
+ final DefaultRouter that = (DefaultRouter) obj;
+ return Objects.equals(this.id, that.id)
+ && Objects.equals(this.name, that.name)
+ && Objects.equals(this.adminStateUp, that.adminStateUp)
+ && Objects.equals(this.status, that.status)
+ && Objects.equals(this.distributed, that.distributed)
+ && Objects.equals(this.externalGatewayInfo,
+ that.externalGatewayInfo)
+ && Objects.equals(this.gatewayPortId, that.gatewayPortId)
+ && Objects.equals(this.routes, that.routes);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("id", id).add("routerName", name)
+ .add("adminStateUp", adminStateUp).add("status", status)
+ .add("distributed", distributed)
+ .add("externalGatewayInfo", externalGatewayInfo)
+ .add("gatewayPortid", gatewayPortId).add("routes", routes).toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIp.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIp.java
new file mode 100644
index 00000000..0933d9ef
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIp.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.onlab.packet.IpAddress;
+
+/**
+ * Representation of a floatingIp.
+ */
+public interface FloatingIp {
+
+ /**
+ * Coarse classification of the type of the FloatingIp.
+ */
+ public enum Status {
+ /**
+ * Signifies that a floating Ip is currently active.
+ */
+ ACTIVE,
+ /**
+ * Signifies that a floating Ip is currently inactive.
+ */
+ INACTIVE
+ }
+
+ /**
+ * Returns the floatingIp identifier.
+ *
+ * @return identifier
+ */
+ FloatingIpId id();
+
+ /**
+ * Returns the tenant identifier.
+ *
+ * @return the tenant identifier
+ */
+ TenantId tenantId();
+
+ /**
+ * Returns the network identifier.
+ *
+ * @return the network identifier
+ */
+ TenantNetworkId networkId();
+
+ /**
+ * Returns the port identifier.
+ *
+ * @return the port identifier
+ */
+ VirtualPortId portId();
+
+ /**
+ * Returns the router identifier.
+ *
+ * @return the router identifier
+ */
+ RouterId routerId();
+
+ /**
+ * Returns the floating ip address.
+ *
+ * @return floatingIp
+ */
+ IpAddress floatingIp();
+
+ /**
+ * Returns the fixed ip address.
+ *
+ * @return fixedIp
+ */
+ IpAddress fixedIp();
+
+ /**
+ * Returns the status of floating ip.
+ *
+ * @return floatingIpStatus
+ */
+ Status status();
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIpId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIpId.java
new file mode 100644
index 00000000..1b48c7d6
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FloatingIpId.java
@@ -0,0 +1,85 @@
+/*
+ * 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;
+import java.util.UUID;
+
+/**
+ * Immutable representation of a floating IP identifier.
+ */
+public final class FloatingIpId {
+ private final UUID floatingIpId;
+
+ // Public construction is prohibited
+ private FloatingIpId(UUID floatingIpId) {
+ this.floatingIpId = checkNotNull(floatingIpId, "floatingIpId cannot be null");
+ }
+
+ /**
+ * Creates a floating IP identifier.
+ *
+ * @param floatingIpId the UUID id of floating IP identifier
+ * @return object of floating IP identifier
+ */
+ public static FloatingIpId of(UUID floatingIpId) {
+ return new FloatingIpId(floatingIpId);
+ }
+
+ /**
+ * Creates a floating IP identifier.
+ *
+ * @param floatingIpId the floating IP identifier in string
+ * @return object of floating IP identifier
+ */
+ public static FloatingIpId of(String floatingIpId) {
+ return new FloatingIpId(UUID.fromString(floatingIpId));
+ }
+
+ /**
+ * Returns the floating IP identifier.
+ *
+ * @return the floating IP identifier
+ */
+ public UUID floatingIpId() {
+ return floatingIpId;
+ }
+
+ @Override
+ public int hashCode() {
+ return floatingIpId.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof FloatingIpId) {
+ final FloatingIpId that = (FloatingIpId) obj;
+ return Objects.equals(this.floatingIpId, that.floatingIpId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("floatingIpId", floatingIpId).toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterInterface.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterInterface.java
new file mode 100644
index 00000000..5c37c30b
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterInterface.java
@@ -0,0 +1,119 @@
+/*
+ * 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;
+
+/**
+ * Representation of a Router interface.
+ */
+public final class RouterInterface {
+ private final SubnetId subnetId;
+ private final VirtualPortId portId;
+ private final RouterId routerId;
+ private final TenantId tenantId;
+
+ // Public construction is prohibited
+ private RouterInterface(SubnetId subnetId, VirtualPortId portId,
+ RouterId routerId, TenantId tenantId) {
+ this.subnetId = checkNotNull(subnetId, "subnetId cannot be null");
+ this.portId = checkNotNull(portId, "portId cannot be null");
+ this.routerId = checkNotNull(routerId, "routerId cannot be null");
+ this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
+ }
+
+ /**
+ * Creates router interface object.
+ *
+ * @param subnetId subnet identifier
+ * @param portId port identifier
+ * @param routerId router identifier
+ * @param tenantId tenant identifier
+ * @return RouterInterface
+ */
+ public static RouterInterface routerInterface(SubnetId subnetId,
+ VirtualPortId portId,
+ RouterId routerId,
+ TenantId tenantId) {
+ return new RouterInterface(subnetId, portId, routerId, tenantId);
+ }
+
+ /**
+ * Returns subnet identifier.
+ *
+ * @return subnetId the subnet identifier
+ */
+ public SubnetId subnetId() {
+ return subnetId;
+ }
+
+ /**
+ * Returns port identifier.
+ *
+ * @return portId the port identifier
+ */
+ public VirtualPortId portId() {
+ return portId;
+ }
+
+ /**
+ * Returns router identifier.
+ *
+ * @return routerId the router identifier
+ */
+ public RouterId routerId() {
+ return routerId;
+ }
+
+ /**
+ * Returns tenant identifier.
+ *
+ * @return tenantId the tenant identifier
+ */
+ public TenantId tenantId() {
+ return tenantId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(subnetId, portId, routerId, tenantId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof RouterInterface) {
+ final RouterInterface that = (RouterInterface) obj;
+ return Objects.equals(this.subnetId, that.subnetId)
+ && Objects.equals(this.portId, that.portId)
+ && Objects.equals(this.routerId, that.routerId)
+ && Objects.equals(this.tenantId, that.tenantId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("subnetId", subnetId)
+ .add("portId", portId).add("routerId", routerId)
+ .add("tenantId", tenantId).toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java
new file mode 100644
index 00000000..00758dd2
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java
@@ -0,0 +1,95 @@
+/*
+ * 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.cli.floatingip;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.DefaultFloatingIp;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FloatingIp.Status;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for create a floating IP.
+ */
+@Command(scope = "onos", name = "floatingip-create",
+ description = "Supports for creating a floating IP")
+public class FloatingIpCreateCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "id", description = "The floating IP identifier",
+ required = true, multiValued = false)
+ String id = null;
+
+ @Argument(index = 1, name = "networkId", description = "The network identifier of floating IP",
+ required = true, multiValued = false)
+ String networkId = null;
+
+ @Argument(index = 2, name = "tenantId", description = "The tenant identifier of floating IP",
+ required = true, multiValued = false)
+ String tenantId = null;
+
+ @Argument(index = 3, name = "routerId", description = "The router identifier of floating IP",
+ required = true, multiValued = false)
+ String routerId = null;
+
+ @Argument(index = 4, name = "fixedIp", description = "The fixed IP of floating IP",
+ required = true, multiValued = false)
+ String fixedIp = null;
+
+ @Argument(index = 5, name = "floatingIp", description = "The floating IP of floating IP",
+ required = true, multiValued = false)
+ String floatingIp = null;
+
+ @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP",
+ required = false, multiValued = false)
+ String portId = null;
+
+ @Option(name = "-s", aliases = "--status", description = "The status of floating IP",
+ required = false, multiValued = false)
+ String status = null;
+
+ @Override
+ protected void execute() {
+ FloatingIpService service = get(FloatingIpService.class);
+ try {
+ FloatingIp floatingIpObj = new DefaultFloatingIp(
+ FloatingIpId.of(id),
+ TenantId.tenantId(tenantId),
+ TenantNetworkId.networkId(networkId),
+ VirtualPortId.portId(portId),
+ RouterId.valueOf(routerId),
+ floatingIp == null ? null : IpAddress.valueOf(floatingIp),
+ fixedIp == null ? null : IpAddress.valueOf(fixedIp),
+ status == null ? Status.ACTIVE
+ : Status.valueOf(status));
+ Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj);
+ service.createFloatingIps(floatingIpSet);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java
new file mode 100644
index 00000000..c441d535
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java
@@ -0,0 +1,92 @@
+/*
+ * 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.cli.floatingip;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+
+/**
+ * Supports for query a floating IP.
+ */
+@Command(scope = "onos", name = "floatingips", description = "Supports for querying a floating IP")
+public class FloatingIpQueryCommand extends AbstractShellCommand {
+ @Option(name = "-I", aliases = "--id", description = "The floating IP identifier",
+ required = false, multiValued = false)
+ String id = null;
+
+ @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP",
+ required = false, multiValued = false)
+ String fixedIp = null;
+
+ @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP",
+ required = false, multiValued = false)
+ String floatingIp = null;
+
+ private static final String FMT = "floatingIpId=%s, networkId=%s, tenantId=%s, portId=%s,"
+ + "routerId=%s, fixedIp=%s, floatingIp=%s, status=%s";
+
+ @Override
+ protected void execute() {
+ FloatingIpService service = get(FloatingIpService.class);
+ if (id != null) {
+ FloatingIp floatingIp = service.getFloatingIp(FloatingIpId
+ .of(id));
+ printFloatingIp(floatingIp);
+ } else if (fixedIp != null || floatingIp != null) {
+ Iterable<FloatingIp> floatingIps = service.getFloatingIps();
+ if (floatingIps == null) {
+ return;
+ }
+ if (fixedIp != null) {
+ for (FloatingIp floatingIp : floatingIps) {
+ if (floatingIp.fixedIp().toString().equals(fixedIp)) {
+ printFloatingIp(floatingIp);
+ return;
+ }
+ }
+ print(null, "The fixedIp is not existed");
+ }
+ if (floatingIp != null) {
+ for (FloatingIp floatingIpObj : floatingIps) {
+ if (floatingIpObj.fixedIp().toString().equals(floatingIp)) {
+ printFloatingIp(floatingIpObj);
+ return;
+ }
+ }
+ print(null, "The floatingIp is not existed");
+ }
+ } else {
+ Iterable<FloatingIp> floatingIps = service.getFloatingIps();
+ if (floatingIps == null) {
+ return;
+ }
+ for (FloatingIp floatingIp : floatingIps) {
+ printFloatingIp(floatingIp);
+ }
+ }
+ }
+
+ private void printFloatingIp(FloatingIp floatingIp) {
+ print(FMT, floatingIp.id(), floatingIp.networkId(),
+ floatingIp.tenantId(), floatingIp.portId(),
+ floatingIp.routerId(), floatingIp.fixedIp(),
+ floatingIp.floatingIp(), floatingIp.status());
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java
new file mode 100644
index 00000000..a413503a
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java
@@ -0,0 +1,90 @@
+/*
+ * 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.cli.floatingip;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for remove a floating IP.
+ */
+@Command(scope = "onos", name = "floatingip-remove", description = "Supports for removing a floating IP")
+public class FloatingIpRemoveCommand extends AbstractShellCommand {
+ @Option(name = "-I", aliases = "--id", description = "The floating IP identifier",
+ required = false, multiValued = false)
+ String id = null;
+
+ @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP",
+ required = false, multiValued = false)
+ String fixedIp = null;
+
+ @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP",
+ required = false, multiValued = false)
+ String floatingIp = null;
+
+ @Override
+ protected void execute() {
+ FloatingIpService service = get(FloatingIpService.class);
+ if (id == null && fixedIp == null && floatingIp == null) {
+ print(null, "one of id, fixedIp, floatingIp should not be null");
+ }
+ try {
+ Set<FloatingIpId> floatingIpSet = Sets.newHashSet();
+ if (id != null) {
+ floatingIpSet.add(FloatingIpId.of(id));
+ service.removeFloatingIps(floatingIpSet);
+ } else {
+ Iterable<FloatingIp> floatingIps = service.getFloatingIps();
+ if (floatingIps == null) {
+ return;
+ }
+ if (fixedIp != null) {
+ for (FloatingIp floatingIp : floatingIps) {
+ if (floatingIp.fixedIp().toString().equals(fixedIp)) {
+ floatingIpSet.add(floatingIp.id());
+ service.removeFloatingIps(floatingIpSet);
+ return;
+ }
+ }
+ print(null, "The fixedIp is not existed");
+ return;
+ }
+ if (floatingIp != null) {
+ for (FloatingIp floatingIpObj : floatingIps) {
+ if (floatingIpObj.fixedIp().toString()
+ .equals(floatingIp)) {
+ floatingIpSet.add(floatingIpObj.id());
+ service.removeFloatingIps(floatingIpSet);
+ return;
+ }
+ }
+ print(null, "The floatingIp is not existed");
+ return;
+ }
+ }
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java
new file mode 100644
index 00000000..413b3bdb
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java
@@ -0,0 +1,103 @@
+/*
+ * 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.cli.floatingip;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.DefaultFloatingIp;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FloatingIp.Status;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for update a floating IP.
+ */
+@Command(scope = "onos", name = "floatingip-update",
+ description = "Supports for updating a floating IP")
+public class FloatingIpUpdateCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "id", description = "The floating IP identifier",
+ required = true, multiValued = false)
+ String id = null;
+
+ @Option(name = "-n", aliases = "--networkId", description = "The network identifier of floating IP",
+ required = false, multiValued = false)
+ String networkId = null;
+
+ @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of floating IP",
+ required = false, multiValued = false)
+ String tenantId = null;
+
+ @Option(name = "-r", aliases = "--routerId", description = "The router identifier of floating IP",
+ required = false, multiValued = false)
+ String routerId = null;
+
+ @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP",
+ required = false, multiValued = false)
+ String portId = null;
+
+ @Option(name = "-s", aliases = "--status", description = "The status of floating IP",
+ required = false, multiValued = false)
+ String status = null;
+
+ @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP",
+ required = false, multiValued = false)
+ String fixedIp = null;
+
+ @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP",
+ required = false, multiValued = false)
+ String floatingIp = null;
+
+ @Override
+ protected void execute() {
+ FloatingIpService service = get(FloatingIpService.class);
+ FloatingIpId floatingIpId = FloatingIpId.of(id);
+ FloatingIp floatingIpStore = get(FloatingIpService.class).getFloatingIp(floatingIpId);
+ try {
+ FloatingIp floatingIpObj = new DefaultFloatingIp(
+ floatingIpId,
+ tenantId == null ? floatingIpStore.tenantId()
+ : TenantId.tenantId(tenantId),
+ networkId == null ? floatingIpStore.networkId()
+ : TenantNetworkId.networkId(networkId),
+ portId == null ? floatingIpStore.portId()
+ : VirtualPortId.portId(portId),
+ routerId == null ? floatingIpStore.routerId()
+ : RouterId.valueOf(routerId),
+ floatingIp == null ? floatingIpStore.floatingIp()
+ : IpAddress.valueOf(floatingIp),
+ fixedIp == null ? floatingIpStore.fixedIp()
+ : IpAddress.valueOf(fixedIp),
+ status == null ? floatingIpStore.status()
+ : Status.valueOf(status));
+ Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj);
+ service.updateFloatingIps(floatingIpSet);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java
new file mode 100644
index 00000000..ac560771
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Command line interface for floatingIP.
+ */
+package org.onosproject.vtnrsc.cli.floatingip;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java
new file mode 100644
index 00000000..3a736deb
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java
@@ -0,0 +1,97 @@
+/*
+ * 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.cli.router;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.DefaultRouter;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.Router.Status;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.router.RouterService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for create a router.
+ */
+@Command(scope = "onos", name = "router-create",
+ description = "Supports for creating a router")
+public class RouterCreateCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "id", description = "The router identifier",
+ required = true, multiValued = false)
+ String id = null;
+
+ @Argument(index = 1, name = "routerName", description = "The name of router",
+ required = true, multiValued = false)
+ String routerName = null;
+
+ @Argument(index = 2, name = "tenantId", description = "The tenant identifier of router",
+ required = true, multiValued = false)
+ String tenantId = null;
+
+ @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router",
+ required = false, multiValued = false)
+ String gatewayPortId = null;
+
+ @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The external gateway info of router",
+ required = false, multiValued = false)
+ String externalGatewayInfo = null;
+
+ @Option(name = "-s", aliases = "--status", description = "The status of router",
+ required = false, multiValued = false)
+ String status = null;
+
+ @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router",
+ required = false, multiValued = false)
+ boolean adminStateUp = true;
+
+ @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router",
+ required = false, multiValued = false)
+ boolean distributed = false;
+
+ @Override
+ protected void execute() {
+ RouterService service = get(RouterService.class);
+ try {
+ List<String> routes = new ArrayList<String>();
+ Router router = new DefaultRouter(
+ RouterId.valueOf(id),
+ routerName,
+ adminStateUp,
+ status == null ? Status.ACTIVE
+ : Status.valueOf(status),
+ distributed,
+ null,
+ VirtualPortId.portId(gatewayPortId),
+ TenantId.tenantId(tenantId),
+ routes);
+ Set<Router> routerSet = Sets.newHashSet(router);
+ service.createRouters(routerSet);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java
new file mode 100644
index 00000000..a8a4b585
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java
@@ -0,0 +1,76 @@
+/*
+ * 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.cli.router;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.router.RouterService;
+
+/**
+ * Supports for query a list of router.
+ */
+@Command(scope = "onos", name = "routers", description = "Supports for creating a router")
+public class RouterQueryCommand extends AbstractShellCommand {
+ @Option(name = "-i", aliases = "--id", description = "The router identifier",
+ required = false, multiValued = false)
+ String id = null;
+
+ @Option(name = "-n", aliases = "--routerName", description = "The name of router",
+ required = false, multiValued = false)
+ String routerName = null;
+
+ private static final String FMT = "routerId=%s, routerName=%s, tenantId=%s, gatewayPortId=%s,"
+ + "externalGatewayInfo=%s, status=%s, adminStateUp=%s, distributed=%s, routers=%s";
+
+ @Override
+ protected void execute() {
+ RouterService service = get(RouterService.class);
+ if (id != null) {
+ Router router = service.getRouter(RouterId.valueOf(id));
+ printFloatingIp(router);
+ } else if (routerName != null) {
+ Iterable<Router> routers = service.getRouters();
+ if (routers == null) {
+ return;
+ }
+ for (Router router : routers) {
+ if (router.name().equals(routerName)) {
+ printFloatingIp(router);
+ return;
+ }
+ }
+ print(null, "The routerName is not existed");
+ } else {
+ Iterable<Router> routers = service.getRouters();
+ if (routers == null) {
+ return;
+ }
+ for (Router router : routers) {
+ printFloatingIp(router);
+ }
+ }
+ }
+
+ private void printFloatingIp(Router router) {
+ print(FMT, router.id(), router.name(), router.tenantId(),
+ router.gatewayPortid(), router.externalGatewayInfo(),
+ router.status(), router.adminStateUp(), router.distributed(),
+ router.routes());
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java
new file mode 100644
index 00000000..b48434a1
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java
@@ -0,0 +1,71 @@
+/*
+ * 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.cli.router;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.router.RouterService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for remove a router.
+ */
+@Command(scope = "onos", name = "router-remove", description = "Supports for removing a router")
+public class RouterRemoveCommand extends AbstractShellCommand {
+ @Option(name = "-i", aliases = "--id", description = "The router identifier",
+ required = false, multiValued = false)
+ String id = null;
+
+ @Option(name = "-n", aliases = "--routerName", description = "The name of router",
+ required = false, multiValued = false)
+ String routerName = null;
+
+ @Override
+ protected void execute() {
+ RouterService service = get(RouterService.class);
+ if (id == null && routerName == null) {
+ print(null, "one of id, routerName should not be null");
+ }
+ try {
+ Set<RouterId> routerSet = Sets.newHashSet();
+ if (id != null) {
+ routerSet.add(RouterId.valueOf(id));
+ service.removeRouters(routerSet);
+ } else {
+ Iterable<Router> routers = service.getRouters();
+ if (routers == null) {
+ return;
+ }
+ for (Router router : routers) {
+ if (router.name().equals(routerName)) {
+ routerSet.add(router.id());
+ service.removeRouters(routerSet);
+ return;
+ }
+ }
+ }
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java
new file mode 100644
index 00000000..699874b3
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java
@@ -0,0 +1,99 @@
+/*
+ * 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.cli.router;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.DefaultRouter;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.Router.Status;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.router.RouterService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for update a router.
+ */
+@Command(scope = "onos", name = "router-update", description = "Supports for updating a router")
+public class RouterUpdateCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "id", description = "The router identifier",
+ required = true, multiValued = false)
+ String id = null;
+
+ @Option(name = "-r", aliases = "--routerName", description = "The name of router",
+ required = false, multiValued = false)
+ String routerName = null;
+
+ @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of router",
+ required = false, multiValued = false)
+ String tenantId = null;
+
+ @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router",
+ required = false, multiValued = false)
+ String gatewayPortId = null;
+
+ @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The externalGatewayInfo of router",
+ required = false, multiValued = false)
+ String externalGatewayInfo = null;
+
+ @Option(name = "-s", aliases = "--status", description = "The status of router",
+ required = false, multiValued = false)
+ String status = null;
+
+ @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router",
+ required = false, multiValued = false)
+ boolean adminStateUp = true;
+
+ @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router",
+ required = false, multiValued = false)
+ boolean distributed = false;
+
+ @Override
+ protected void execute() {
+ RouterService service = get(RouterService.class);
+ RouterId routerId = RouterId.valueOf(id);
+ Router router = get(RouterService.class).getRouter(routerId);
+ try {
+ List<String> routes = new ArrayList<String>();
+ Router routerObj = new DefaultRouter(
+ RouterId.valueOf(id),
+ routerName == null ? router.name() : routerName,
+ adminStateUp,
+ status == null ? Status.ACTIVE
+ : Status.valueOf(status),
+ distributed,
+ null,
+ gatewayPortId == null ? router.gatewayPortid()
+ : VirtualPortId.portId(gatewayPortId),
+ tenantId == null ? router.tenantId()
+ : TenantId.tenantId(tenantId),
+ routes);
+ Set<Router> routerSet = Sets.newHashSet(routerObj);
+ service.createRouters(routerSet);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java
new file mode 100644
index 00000000..4f1768ac
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Command line interface for router.
+ */
+package org.onosproject.vtnrsc.cli.router;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java
new file mode 100644
index 00000000..a3a174c9
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.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.vtnrsc.cli.routerinterface;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
+
+/**
+ * Supports for create a router interface.
+ */
+@Command(scope = "onos", name = "routerinterface-create", description = "Supports for creating a router interface")
+public class RouterInterfaceCreateCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "routerId", description = "The router identifier of router interface",
+ required = true, multiValued = false)
+ String routerId = null;
+
+ @Argument(index = 1, name = "tenantId", description = "The tenant identifier of router interface",
+ required = true, multiValued = false)
+ String tenantId = null;
+
+ @Argument(index = 2, name = "portId", description = "The port identifier of router interface",
+ required = true, multiValued = false)
+ String portId = null;
+
+ @Argument(index = 3, name = "subnetId", description = "The subnet identifier of router interface",
+ required = true, multiValued = false)
+ String subnetId = null;
+
+ @Override
+ protected void execute() {
+ RouterInterfaceService service = get(RouterInterfaceService.class);
+ try {
+ RouterInterface routerInterface = RouterInterface.routerInterface(
+ SubnetId.subnetId(subnetId),
+ VirtualPortId.portId(portId),
+ RouterId.valueOf(routerId),
+ TenantId.tenantId(tenantId));
+ service.addRouterInterface(routerInterface);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+ }
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java
new file mode 100644
index 00000000..5de35aee
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java
@@ -0,0 +1,56 @@
+/*
+ * 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.cli.routerinterface;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
+
+/**
+ * Supports for query a router interface.
+ */
+@Command(scope = "onos", name = "routerinterfaces", description = "Supports for querying a router interface")
+public class RouterInterfaceQueryCommand extends AbstractShellCommand {
+ @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface",
+ required = false, multiValued = false)
+ String subnetId = null;
+
+ private static final String FMT = "subnetId=%s, tenantId=%s, portId=%s, routerId=%s";
+
+ @Override
+ protected void execute() {
+ RouterInterfaceService service = get(RouterInterfaceService.class);
+ if (subnetId != null) {
+ RouterInterface routerInterface = service
+ .getRouterInterface(SubnetId.subnetId(subnetId));
+ printRouterInterface(routerInterface);
+ } else {
+ Iterable<RouterInterface> routerInterfaces = service
+ .getRouterInterfaces();
+ for (RouterInterface routerInterface : routerInterfaces) {
+ printRouterInterface(routerInterface);
+ }
+ }
+ }
+
+ private void printRouterInterface(RouterInterface routerInterface) {
+ print(FMT, routerInterface.subnetId(), routerInterface.tenantId(),
+ routerInterface.portId(), routerInterface.routerId());
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java
new file mode 100644
index 00000000..4e838e26
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java
@@ -0,0 +1,50 @@
+/*
+ * 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.cli.routerinterface;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
+
+/**
+ * Supports for remove a router interface.
+ */
+@Command(scope = "onos", name = "routerinterface-remove", description = "Supports for removing a router interface")
+public class RouterInterfaceRemoveCommand extends AbstractShellCommand {
+ @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface",
+ required = true, multiValued = false)
+ String subnetId = null;
+
+ @Override
+ protected void execute() {
+ RouterInterfaceService service = get(RouterInterfaceService.class);
+ try {
+ RouterInterface routerInterface = service
+ .getRouterInterface(SubnetId.subnetId(subnetId));
+ if (routerInterface == null) {
+ print(null, "subnet ID of interface doesn't exist");
+ return;
+ }
+ service.removeRouterInterface(routerInterface);
+ } catch (Exception e) {
+ print(null, e.getMessage());
+ }
+
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java
new file mode 100644
index 00000000..7b82004e
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Command line interface for router interface.
+ */
+package org.onosproject.vtnrsc.cli.routerinterface;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEvent.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEvent.java
new file mode 100644
index 00000000..3bac158b
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEvent.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.event;
+
+import org.onosproject.event.AbstractEvent;
+
+
+/**
+ * Describes network vtnrsc event.
+ */
+public class VtnRscEvent
+ extends AbstractEvent<VtnRscEvent.Type, VtnRscEventFeedback> {
+
+ /**
+ * Type of vtnrsc events.
+ */
+ public enum Type {
+ /**
+ * Signifies that floating IP has create.
+ */
+ FLOATINGIP_PUT,
+ /**
+ * Signifies that floating IP has delete.
+ */
+ FLOATINGIP_DELETE,
+ /**
+ * Signifies that router has create.
+ */
+ ROUTER_PUT,
+ /**
+ * Signifies that router has delete.
+ */
+ ROUTER_DELETE,
+ /**
+ * Signifies that router interface has add.
+ */
+ ROUTER_INTERFACE_PUT,
+ /**
+ * Signifies that router interface has remove.
+ */
+ ROUTER_INTERFACE_DELETE
+ }
+
+ /**
+ * Creates an event of a given type and for the specified vtn event feedback.
+ *
+ * @param type Vtnrsc event type
+ * @param vtnFeedback event VtnrscEventFeedback subject
+ */
+ public VtnRscEvent(Type type, VtnRscEventFeedback vtnFeedback) {
+ super(type, vtnFeedback);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified vtn event feedback.
+ *
+ * @param type Vtnrsc event type
+ * @param vtnFeedback event VtnrscEventFeedback subject
+ * @param time occurrence time
+ */
+ public VtnRscEvent(Type type, VtnRscEventFeedback vtnFeedback, long time) {
+ super(type, vtnFeedback, time);
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEventFeedback.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEventFeedback.java
new file mode 100644
index 00000000..63dcaeee
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscEventFeedback.java
@@ -0,0 +1,123 @@
+/*
+ * 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.event;
+
+import java.util.Objects;
+
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterInterface;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a VtnRsc event feedback.
+ */
+public class VtnRscEventFeedback {
+ private final FloatingIp floaingtIp;
+ private final Router router;
+ private final RouterInterface routerInterface;
+
+ /**
+ * Creates VtnRscEventFeedback object.
+ *
+ * @param floatingIp the floating Ip
+ */
+ public VtnRscEventFeedback(FloatingIp floatingIp) {
+ this.floaingtIp = checkNotNull(floatingIp, "floaintIp cannot be null");
+ this.router = null;
+ this.routerInterface = null;
+ }
+
+ /**
+ * Creates VtnRscEventFeedback object.
+ *
+ * @param router the router
+ */
+ public VtnRscEventFeedback(Router router) {
+ this.floaingtIp = null;
+ this.router = checkNotNull(router, "router cannot be null");
+ this.routerInterface = null;
+ }
+
+ /**
+ * Creates VtnRscEventFeedback object.
+ *
+ * @param routerInterface the router interface
+ */
+ public VtnRscEventFeedback(RouterInterface routerInterface) {
+ this.floaingtIp = null;
+ this.router = null;
+ this.routerInterface = checkNotNull(routerInterface,
+ "routerInterface cannot be null");
+ }
+
+ /**
+ * Returns floating IP.
+ *
+ * @return floaingtIp the floating IP
+ */
+ public FloatingIp floatingIp() {
+ return floaingtIp;
+ }
+
+ /**
+ * Returns router.
+ *
+ * @return router the router
+ */
+ public Router router() {
+ return router;
+ }
+
+ /**
+ * Returns router interface.
+ *
+ * @return routerInterface the router interface
+ */
+ public RouterInterface routerInterface() {
+ return routerInterface;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(floaingtIp, router, routerInterface);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof VtnRscEventFeedback) {
+ final VtnRscEventFeedback that = (VtnRscEventFeedback) obj;
+ return Objects.equals(this.floaingtIp, that.floaingtIp)
+ && Objects.equals(this.router, that.router)
+ && Objects.equals(this.routerInterface, that.routerInterface);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("router", router)
+ .add("floaingtIp", floaingtIp)
+ .add("routerInterface", routerInterface)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscListener.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscListener.java
new file mode 100644
index 00000000..fdd67552
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/VtnRscListener.java
@@ -0,0 +1,26 @@
+/*
+ * 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.event;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of VtnRsc related events.
+ */
+public interface VtnRscListener extends EventListener<VtnRscEvent> {
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/package-info.java
new file mode 100644
index 00000000..c1575ad3
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/event/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Event of VtnRsc for VtnRsc service.
+ */
+package org.onosproject.vtnrsc.event;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpEvent.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpEvent.java
new file mode 100644
index 00000000..f76007f7
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpEvent.java
@@ -0,0 +1,60 @@
+/*
+ * 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.floatingip;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.vtnrsc.FloatingIp;
+
+/**
+ * Describes network Floating IP event.
+ */
+public class FloatingIpEvent
+ extends AbstractEvent<FloatingIpEvent.Type, FloatingIp> {
+ /**
+ * Type of Floating IP events.
+ */
+ public enum Type {
+ /**
+ * Signifies that Floating IP has been created.
+ */
+ FLOATINGIP_PUT,
+ /**
+ * Signifies that Floating IP has been deleted.
+ */
+ FLOATINGIP_DELETE
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Floating IP.
+ *
+ * @param type Floating IP event type
+ * @param floagingIp Floating IP subject
+ */
+ public FloatingIpEvent(Type type, FloatingIp floagingIp) {
+ super(type, floagingIp);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Floating IP.
+ *
+ * @param type Floating IP event type
+ * @param floagingIp Floating IP subject
+ * @param time occurrence time
+ */
+ public FloatingIpEvent(Type type, FloatingIp floagingIp, long time) {
+ super(type, floagingIp, time);
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpListener.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpListener.java
new file mode 100644
index 00000000..a42af136
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpListener.java
@@ -0,0 +1,25 @@
+/*
+ * 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.floatingip;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of Floating IP related events.
+ */
+public interface FloatingIpListener extends EventListener<FloatingIpEvent> {
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpService.java
new file mode 100644
index 00000000..3f6f2515
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/FloatingIpService.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.floatingip;
+
+import java.util.Collection;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.TenantId;
+
+/**
+ * Service for interacting with the inventory of floating IP.
+ */
+public interface FloatingIpService {
+ /**
+ * Returns exists or not of specific floatingIp identifier.
+ *
+ * @param floatingIpId floatingIp identifier
+ * @return true or false
+ */
+ boolean exists(FloatingIpId floatingIpId);
+
+ /**
+ * Returns is used or not of specific floating IP address.
+ *
+ * @param floatingIpAddr floatingIp address
+ * @param floatingIpId floatingIp identifier
+ * @return true or false
+ */
+ boolean floatingIpIsUsed(IpAddress floatingIpAddr, FloatingIpId floatingIpId);
+
+ /**
+ * Returns is used or not of specific fixed IP address.
+ *
+ * @param fixedIpAddr fixedIp address
+ * @param tenantId the tenant identifier of floating IP
+ * @param floatingIpId floatingIp identifier
+ * @return true or false
+ */
+ boolean fixedIpIsUsed(IpAddress fixedIpAddr, TenantId tenantId, FloatingIpId floatingIpId);
+
+ /**
+ * Returns a collection of the currently known floating IP.
+ *
+ * @return collection of floating IP
+ */
+ Collection<FloatingIp> getFloatingIps();
+
+ /**
+ * Returns the floatingIp with the specified identifier.
+ *
+ * @param floatingIpId floatingIp identifier
+ * @return floatingIp or null if one with the given identifier is not known
+ */
+ FloatingIp getFloatingIp(FloatingIpId floatingIpId);
+
+ /**
+ * Creates new floatingIps.
+ *
+ * @param floatingIps the collection of floatingIp
+ * @return true if the identifier floatingIp has been created right
+ */
+ boolean createFloatingIps(Collection<FloatingIp> floatingIps);
+
+ /**
+ * Updates existing floatingIps.
+ *
+ * @param floatingIps the collection of floatingIp
+ * @return true if all floatingIp were updated successfully
+ */
+ boolean updateFloatingIps(Collection<FloatingIp> floatingIps);
+
+ /**
+ * Removes the specified floatingIp from the store.
+ *
+ * @param floatingIpIds the collection of floatingIp identifier
+ * @return true if remove identifier floatingIp successfully
+ */
+ boolean removeFloatingIps(Collection<FloatingIpId> floatingIpIds);
+
+ /**
+ * Adds the specified listener to floating Ip manager.
+ *
+ * @param listener floating Ip listener
+ */
+ void addListener(FloatingIpListener listener);
+
+ /**
+ * Removes the specified listener to floating Ip manager.
+ *
+ * @param listener floating Ip listener
+ */
+ void removeListener(FloatingIpListener listener);
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
new file mode 100644
index 00000000..9f944da1
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
@@ -0,0 +1,348 @@
+/*
+ * 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.floatingip.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+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.IpAddress;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.EventuallyConsistentMapEvent;
+import org.onosproject.store.service.EventuallyConsistentMapListener;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.onosproject.vtnrsc.DefaultFloatingIp;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FloatingIpId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.floatingip.FloatingIpEvent;
+import org.onosproject.vtnrsc.floatingip.FloatingIpListener;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+import org.onosproject.vtnrsc.router.RouterService;
+import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Provides implementation of the FloatingIp service.
+ */
+@Component(immediate = true)
+@Service
+public class FloatingIpManager implements FloatingIpService {
+ private static final String FLOATINGIP_ID_NOT_NULL = "Floatingip ID cannot be null";
+ private static final String FLOATINGIP_NOT_NULL = "Floatingip cannot be null";
+ private static final String FLOATINGIP = "vtn-floatingip-store";
+ private static final String VTNRSC_APP = "org.onosproject.vtnrsc";
+ private static final String LISTENER_NOT_NULL = "Listener cannot be null";
+ private static final String EVENT_NOT_NULL = "event cannot be null";
+
+ private final Logger log = getLogger(getClass());
+ private final Set<FloatingIpListener> listeners = Sets
+ .newCopyOnWriteArraySet();
+ private EventuallyConsistentMapListener<FloatingIpId, FloatingIp> floatingIpListener =
+ new InnerFloatingIpStoreListener();
+ protected EventuallyConsistentMap<FloatingIpId, FloatingIp> floatingIpStore;
+ protected ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TenantNetworkService tenantNetworkService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VirtualPortService virtualPortService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RouterService routerService;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(VTNRSC_APP);
+ KryoNamespace.Builder serializer = KryoNamespace
+ .newBuilder()
+ .register(KryoNamespaces.API)
+ .register(FloatingIp.class, FloatingIpId.class,
+ TenantNetworkId.class, TenantId.class,
+ FloatingIp.Status.class, RouterId.class,
+ VirtualPortId.class, DefaultFloatingIp.class);
+ floatingIpStore = storageService
+ .<FloatingIpId, FloatingIp>eventuallyConsistentMapBuilder()
+ .withName(FLOATINGIP).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> new WallClockTimestamp())
+ .build();
+ floatingIpStore.addListener(floatingIpListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ floatingIpStore.removeListener(floatingIpListener);
+ floatingIpStore.destroy();
+ listeners.clear();
+ log.info("Stopped");
+ }
+
+ @Override
+ public Collection<FloatingIp> getFloatingIps() {
+ return Collections.unmodifiableCollection(floatingIpStore.values());
+ }
+
+ @Override
+ public FloatingIp getFloatingIp(FloatingIpId floatingIpId) {
+ checkNotNull(floatingIpId, FLOATINGIP_ID_NOT_NULL);
+ return floatingIpStore.get(floatingIpId);
+ }
+
+ @Override
+ public boolean exists(FloatingIpId floatingIpId) {
+ checkNotNull(floatingIpId, FLOATINGIP_ID_NOT_NULL);
+ return floatingIpStore.containsKey(floatingIpId);
+ }
+
+ @Override
+ public boolean floatingIpIsUsed(IpAddress floatingIpAddr,
+ FloatingIpId floatingIpId) {
+ checkNotNull(floatingIpAddr, "Floating IP address cannot be null");
+ checkNotNull(floatingIpId, "Floating IP Id cannot be null");
+ Collection<FloatingIp> floatingIps = getFloatingIps();
+ for (FloatingIp floatingIp : floatingIps) {
+ if (floatingIp.floatingIp().equals(floatingIpAddr)
+ && !floatingIp.id().equals(floatingIpId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean fixedIpIsUsed(IpAddress fixedIpAddr, TenantId tenantId,
+ FloatingIpId floatingIpId) {
+ checkNotNull(fixedIpAddr, "Fixed IP address cannot be null");
+ checkNotNull(tenantId, "Tenant Id cannot be null");
+ checkNotNull(floatingIpId, "Floating IP Id cannot be null");
+ Collection<FloatingIp> floatingIps = getFloatingIps();
+ for (FloatingIp floatingIp : floatingIps) {
+ IpAddress fixedIp = floatingIp.fixedIp();
+ if (fixedIp != null) {
+ if (fixedIp.equals(fixedIpAddr)
+ && floatingIp.tenantId().equals(tenantId)
+ && !floatingIp.id().equals(floatingIpId)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean createFloatingIps(Collection<FloatingIp> floatingIps) {
+ checkNotNull(floatingIps, FLOATINGIP_NOT_NULL);
+ boolean result = true;
+ for (FloatingIp floatingIp : floatingIps) {
+ verifyFloatingIpData(floatingIp);
+ if (floatingIp.portId() != null) {
+ floatingIpStore.put(floatingIp.id(), floatingIp);
+ if (!floatingIpStore.containsKey(floatingIp.id())) {
+ log.debug("The floating Ip is created failed whose identifier is {}",
+ floatingIp.id().toString());
+ result = false;
+ }
+ } else {
+ FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp.id());
+ if (oldFloatingIp != null) {
+ floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
+ if (floatingIpStore.containsKey(floatingIp.id())) {
+ log.debug("The floating Ip is created failed whose identifier is {}",
+ floatingIp.id().toString());
+ result = false;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean updateFloatingIps(Collection<FloatingIp> floatingIps) {
+ checkNotNull(floatingIps, FLOATINGIP_NOT_NULL);
+ boolean result = true;
+ if (floatingIps != null) {
+ for (FloatingIp floatingIp : floatingIps) {
+ verifyFloatingIpData(floatingIp);
+ if (floatingIp.portId() != null) {
+ floatingIpStore.put(floatingIp.id(), floatingIp);
+ if (!floatingIpStore.containsKey(floatingIp.id())) {
+ log.debug("The floating Ip is updated failed whose identifier is {}",
+ floatingIp.id().toString());
+ result = false;
+ }
+ } else {
+ FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp
+ .id());
+ if (oldFloatingIp != null) {
+ floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
+ if (floatingIpStore.containsKey(floatingIp.id())) {
+ log.debug("The floating Ip is updated failed whose identifier is {}",
+ floatingIp.id().toString());
+ result = false;
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean removeFloatingIps(Collection<FloatingIpId> floatingIpIds) {
+ checkNotNull(floatingIpIds, FLOATINGIP_ID_NOT_NULL);
+ boolean result = true;
+ if (floatingIpIds != null) {
+ for (FloatingIpId floatingIpId : floatingIpIds) {
+ if (!floatingIpStore.containsKey(floatingIpId)) {
+ log.debug("The floatingIp is not exist whose identifier is {}",
+ floatingIpId.toString());
+ throw new IllegalArgumentException(
+ "FloatingIP ID doesn't exist");
+ }
+ FloatingIp floatingIp = floatingIpStore.get(floatingIpId);
+ floatingIpStore.remove(floatingIpId, floatingIp);
+ if (floatingIpStore.containsKey(floatingIpId)) {
+ log.debug("The floating Ip is deleted failed whose identifier is {}",
+ floatingIpId.toString());
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void addListener(FloatingIpListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(FloatingIpListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ /**
+ * Verifies validity of FloatingIp data.
+ *
+ * @param floatingIps floatingIp instance
+ */
+ private void verifyFloatingIpData(FloatingIp floatingIps) {
+ checkNotNull(floatingIps, FLOATINGIP_NOT_NULL);
+ if (!tenantNetworkService.exists(floatingIps.networkId())) {
+ log.debug("The network identifier {} that the floating Ip {} create for is not exist",
+ floatingIps.networkId().toString(), floatingIps.id()
+ .toString());
+ throw new IllegalArgumentException(
+ "Floating network ID doesn't exist");
+ }
+
+ VirtualPortId portId = floatingIps.portId();
+ if (portId != null && !virtualPortService.exists(portId)) {
+ log.debug("The port identifier {} that the floating Ip {} create for is not exist",
+ floatingIps.portId().toString(), floatingIps.id()
+ .toString());
+ throw new IllegalArgumentException("Port ID doesn't exist");
+ }
+
+ RouterId routerId = floatingIps.routerId();
+ if (routerId != null && !routerService.exists(routerId)) {
+ log.debug("The router identifier {} that the floating Ip {} create for is not exist",
+ floatingIps.routerId().toString(), floatingIps.id()
+ .toString());
+ throw new IllegalArgumentException("Router ID doesn't exist");
+ }
+
+ if (floatingIpIsUsed(floatingIps.floatingIp(), floatingIps.id())) {
+ log.debug("The floaing Ip {} that the floating Ip {} create for is used",
+ floatingIps.floatingIp().toString(), floatingIps.id()
+ .toString());
+ throw new IllegalArgumentException(
+ "The floating IP address is used");
+ }
+
+ IpAddress fixedIp = floatingIps.fixedIp();
+ if (fixedIp != null
+ && fixedIpIsUsed(fixedIp, floatingIps.tenantId(),
+ floatingIps.id())) {
+ log.debug("The fixed Ip {} that the floating Ip {} create for is used",
+ floatingIps.fixedIp().toString(), floatingIps.id()
+ .toString());
+ throw new IllegalArgumentException("The fixed IP address is used");
+ }
+ }
+
+ private class InnerFloatingIpStoreListener
+ implements
+ EventuallyConsistentMapListener<FloatingIpId, FloatingIp> {
+
+ @Override
+ public void event(EventuallyConsistentMapEvent<FloatingIpId, FloatingIp> event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ FloatingIp floatingIp = event.value();
+ if (EventuallyConsistentMapEvent.Type.PUT == event.type()) {
+ notifyListeners(new FloatingIpEvent(
+ FloatingIpEvent.Type.FLOATINGIP_PUT,
+ floatingIp));
+ }
+ if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) {
+ notifyListeners(new FloatingIpEvent(
+ FloatingIpEvent.Type.FLOATINGIP_DELETE,
+ floatingIp));
+ }
+ }
+ }
+
+ /**
+ * Notifies specify event to all listeners.
+ *
+ * @param event Floating IP event
+ */
+ private void notifyListeners(FloatingIpEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ listeners.forEach(listener -> listener.event(event));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/package-info.java
new file mode 100644
index 00000000..c638eba0
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides implementation of the FloatingIp service.
+ */
+package org.onosproject.vtnrsc.floatingip.impl;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/package-info.java
new file mode 100644
index 00000000..274cbdd0
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Service for interacting with the inventory of FloatingIp.
+ */
+package org.onosproject.vtnrsc.floatingip;
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 c160d221..c5911ff2 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
@@ -24,49 +24,59 @@ import org.onosproject.vtnrsc.FlowClassifierId;
public interface FlowClassifierService {
/**
- * Store Flow Classifier.
+ * Check whether Flow Classifier is present based on given Flow Classifier
+ * Id.
*
- * @param flowClassifier Flow Classifier
- * @return true if adding Flow Classifier into store is success otherwise return false.
+ * @param id flow classifier identifier
+ * @return true if flow classifier is present otherwise return false
*/
- boolean createFlowClassifier(FlowClassifier flowClassifier);
+ boolean exists(FlowClassifierId id);
/**
- * Return the existing collection of Flow Classifier.
+ * Returns the number of flow classifiers known to the system.
*
- * @return Flow Classifier collections.
+ * @return number of flow classifiers
*/
- Iterable<FlowClassifier> getFlowClassifiers();
+ int getFlowClassifierCount();
+
+ /**
+ * Store Flow Classifier.
+ *
+ * @param flowClassifier flow classifier
+ * @return true if adding flow classifier into store is success otherwise
+ * return false
+ */
+ boolean createFlowClassifier(FlowClassifier flowClassifier);
/**
- * Check whether Flow Classifier is present based on given Flow Classifier Id.
+ * Return the existing collection of Flow Classifier.
*
- * @param id Flow Classifier.
- * @return true if Flow Classifier is present otherwise return false.
+ * @return flow classifier collections
*/
- boolean hasFlowClassifier(FlowClassifierId id);
+ Iterable<FlowClassifier> getFlowClassifiers();
/**
* Retrieve the Flow Classifier based on given Flow Classifier id.
*
- * @param id Flow Classifier Id.
- * @return Flow Classifier if present otherwise returns null.
+ * @param id flow classifier identifier
+ * @return flow classifier if present otherwise returns null
*/
FlowClassifier getFlowClassifier(FlowClassifierId id);
/**
* Update Flow Classifier based on given Flow Classifier Id.
*
- * @param flowClassifier Flow Classifier.
- * @return true if update is success otherwise return false.
+ * @param flowClassifier flow classifier
+ * @return true if flow classifier update is success otherwise return false
*/
boolean updateFlowClassifier(FlowClassifier flowClassifier);
/**
* Remove Flow Classifier from store based on given Flow Classifier Id.
*
- * @param id Flow Classifier Id.
- * @return true if Flow Classifier removal is success otherwise return false.
+ * @param id flow classifier identifier
+ * @return true if flow classifier removal is success otherwise return
+ * false
*/
boolean removeFlowClassifier(FlowClassifierId id);
}
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 ee5873d6..4a60cd34 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
@@ -54,7 +54,7 @@ public class FlowClassifierManager implements FlowClassifierService {
protected StorageService storageService;
@Activate
- private void activate() {
+ protected void activate() {
KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
.register(MultiValuedTimestamp.class)
@@ -67,34 +67,25 @@ public class FlowClassifierManager implements FlowClassifierService {
}
@Deactivate
- private void deactivate() {
+ protected void deactivate() {
flowClassifierStore.destroy();
log.info("Flow Classifier service deactivated");
}
@Override
- public boolean createFlowClassifier(FlowClassifier flowClassifier) {
- log.debug("createFlowClassifier");
- checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
- FlowClassifierId id = flowClassifier.flowClassifierId();
-
- flowClassifierStore.put(id, flowClassifier);
- if (!flowClassifierStore.containsKey(id)) {
- log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString());
- return false;
- }
- return true;
+ public boolean exists(FlowClassifierId id) {
+ checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
+ return flowClassifierStore.containsKey(id);
}
@Override
- public Iterable<FlowClassifier> getFlowClassifiers() {
- return ImmutableList.copyOf(flowClassifierStore.values());
+ public int getFlowClassifierCount() {
+ return flowClassifierStore.size();
}
@Override
- public boolean hasFlowClassifier(FlowClassifierId id) {
- checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
- return flowClassifierStore.containsKey(id);
+ public Iterable<FlowClassifier> getFlowClassifiers() {
+ return ImmutableList.copyOf(flowClassifierStore.values());
}
@Override
@@ -104,10 +95,36 @@ public class FlowClassifierManager implements FlowClassifierService {
}
@Override
- public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
+ public boolean createFlowClassifier(FlowClassifier flowClassifier) {
+ log.debug("createFlowClassifier");
checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
FlowClassifierId id = flowClassifier.flowClassifierId();
+
flowClassifierStore.put(id, flowClassifier);
+ if (!flowClassifierStore.containsKey(id)) {
+ log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
+ checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
+
+ if (!flowClassifierStore.containsKey(flowClassifier.flowClassifierId())) {
+ log.debug("The flowClassifier is not exist whose identifier was {} ", flowClassifier.flowClassifierId()
+ .toString());
+ return false;
+ }
+
+ flowClassifierStore.put(flowClassifier.flowClassifierId(), flowClassifier);
+
+ if (!flowClassifier.equals(flowClassifierStore.get(flowClassifier.flowClassifierId()))) {
+ log.debug("Updation of flowClassifier is failed whose identifier was {} ", flowClassifier
+ .flowClassifierId().toString());
+ return false;
+ }
return true;
}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterEvent.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterEvent.java
new file mode 100644
index 00000000..25bd7b31
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterEvent.java
@@ -0,0 +1,59 @@
+/*
+ * 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 org.onosproject.event.AbstractEvent;
+import org.onosproject.vtnrsc.Router;
+
+/**
+ * Describes network Router event.
+ */
+public class RouterEvent extends AbstractEvent<RouterEvent.Type, Router> {
+ /**
+ * Type of Router events.
+ */
+ public enum Type {
+ /**
+ * Signifies that router has been created.
+ */
+ ROUTER_PUT,
+ /**
+ * Signifies that router has been deleted.
+ */
+ ROUTER_DELETE
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Router.
+ *
+ * @param type Router event type
+ * @param router Router subject
+ */
+ public RouterEvent(Type type, Router router) {
+ super(type, router);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Router.
+ *
+ * @param type Router event type
+ * @param router Router subject
+ * @param time occurrence time
+ */
+ public RouterEvent(Type type, Router router, long time) {
+ super(type, router, time);
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterListener.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterListener.java
new file mode 100644
index 00000000..dc772981
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterListener.java
@@ -0,0 +1,25 @@
+/*
+ * 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 org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of Router related events.
+ */
+public interface RouterListener extends EventListener<RouterEvent> {
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterService.java
new file mode 100644
index 00000000..362fa02b
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/RouterService.java
@@ -0,0 +1,90 @@
+/*
+ * 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 java.util.Collection;
+
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterId;
+
+/**
+ * Service for interacting with the inventory of Routers.
+ */
+public interface RouterService {
+ /**
+ * Returns exists or not of specific router identifier.
+ *
+ * @param routerId router identifier
+ * @return true or false
+ */
+ boolean exists(RouterId routerId);
+
+ /**
+ * Returns a collection of the currently known Routers.
+ *
+ * @return collection of Routers
+ */
+ Collection<Router> getRouters();
+
+ /**
+ * Returns the Router with the specified identifier.
+ *
+ * @param routerId Router identifier
+ * @return Router or null if one with the given identifier is not known
+ */
+ Router getRouter(RouterId routerId);
+
+ /**
+ * Creates new Routers.
+ *
+ * @param routers the collection of Routers
+ * @return true if the identifier Router has been created right.
+ * false if the identifier Router is failed to store
+ */
+ boolean createRouters(Collection<Router> routers);
+
+ /**
+ * Updates existing Routers.
+ *
+ * @param routers the collection of Routers
+ * @return true if Routers were updated successfully.
+ * false if Routers were updated failed
+ */
+ boolean updateRouters(Collection<Router> routers);
+
+ /**
+ * Removes the specified Routers from the store.
+ *
+ * @param routerIds the collection of Routers identifier
+ * @return true if remove identifier Routers successfully. false if remove
+ * identifier Routers failed
+ */
+ boolean removeRouters(Collection<RouterId> routerIds);
+
+ /**
+ * Adds the specified listener to Router manager.
+ *
+ * @param listener Router listener
+ */
+ void addListener(RouterListener listener);
+
+ /**
+ * Removes the specified listener to Router manager.
+ *
+ * @param listener Router listener
+ */
+ void removeListener(RouterListener listener);
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/RouterManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/RouterManager.java
new file mode 100644
index 00000000..b796fd7b
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/RouterManager.java
@@ -0,0 +1,269 @@
+/*
+ * 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.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.EventuallyConsistentMapEvent;
+import org.onosproject.store.service.EventuallyConsistentMapListener;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.onosproject.vtnrsc.DefaultRouter;
+import org.onosproject.vtnrsc.FixedIp;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterGateway;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.router.RouterEvent;
+import org.onosproject.vtnrsc.router.RouterListener;
+import org.onosproject.vtnrsc.router.RouterService;
+import org.onosproject.vtnrsc.subnet.SubnetService;
+import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Provides implementation of the Router service.
+ */
+@Component(immediate = true)
+@Service
+public class RouterManager implements RouterService {
+
+ private static final String ROUTER_ID_NULL = "Router ID cannot be null";
+ private static final String ROUTER_NOT_NULL = "Router cannot be null";
+ private static final String ROUTER = "vtn-router-store";
+ private static final String VTNRSC_APP = "org.onosproject.vtnrsc";
+ private static final String LISTENER_NOT_NULL = "Listener cannot be null";
+ private static final String EVENT_NOT_NULL = "event cannot be null";
+
+ private final Logger log = getLogger(getClass());
+ private final Set<RouterListener> listeners = Sets.newCopyOnWriteArraySet();
+ private EventuallyConsistentMapListener<RouterId, Router> routerListener = new InnerRouterStoreListener();
+ protected EventuallyConsistentMap<RouterId, Router> routerStore;
+ protected ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TenantNetworkService tenantNetworkService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VirtualPortService virtualPortService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected SubnetService subnetService;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(VTNRSC_APP);
+ KryoNamespace.Builder serializer = KryoNamespace
+ .newBuilder()
+ .register(KryoNamespaces.API)
+ .register(Router.class, RouterId.class, DefaultRouter.class,
+ TenantNetworkId.class, TenantId.class,
+ VirtualPortId.class, DefaultRouter.class,
+ RouterGateway.class, Router.Status.class,
+ SubnetId.class);
+ routerStore = storageService
+ .<RouterId, Router>eventuallyConsistentMapBuilder()
+ .withName(ROUTER).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> new WallClockTimestamp())
+ .build();
+ routerStore.addListener(routerListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ routerStore.removeListener(routerListener);
+ routerStore.destroy();
+ listeners.clear();
+ log.info("Stopped");
+ }
+
+ @Override
+ public boolean exists(RouterId routerId) {
+ checkNotNull(routerId, ROUTER_ID_NULL);
+ return routerStore.containsKey(routerId);
+ }
+
+ @Override
+ public Collection<Router> getRouters() {
+ return Collections.unmodifiableCollection(routerStore.values());
+ }
+
+ @Override
+ public Router getRouter(RouterId routerId) {
+ checkNotNull(routerId, ROUTER_ID_NULL);
+ return routerStore.get(routerId);
+ }
+
+ @Override
+ public boolean createRouters(Collection<Router> routers) {
+ checkNotNull(routers, ROUTER_NOT_NULL);
+ for (Router router : routers) {
+ verifyRouterData(router);
+ routerStore.put(router.id(), router);
+ if (!routerStore.containsKey(router.id())) {
+ log.debug("The router is created failed whose identifier is {}",
+ router.id().toString());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updateRouters(Collection<Router> routers) {
+ checkNotNull(routers, ROUTER_NOT_NULL);
+ for (Router router : routers) {
+ if (!routerStore.containsKey(router.id())) {
+ log.debug("The routers is not exist whose identifier is {}",
+ router.id().toString());
+ throw new IllegalArgumentException(
+ "routers ID doesn't exist");
+ }
+ verifyRouterData(router);
+ routerStore.put(router.id(), router);
+ if (!router.equals(routerStore.get(router.id()))) {
+ log.debug("The router is updated failed whose identifier is {}",
+ router.id().toString());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeRouters(Collection<RouterId> routerIds) {
+ checkNotNull(routerIds, ROUTER_ID_NULL);
+ for (RouterId routerId : routerIds) {
+ if (!routerStore.containsKey(routerId)) {
+ log.debug("The router is not exist whose identifier is {}",
+ routerId.toString());
+ throw new IllegalArgumentException(
+ "router ID doesn't exist");
+ }
+ Router router = routerStore.get(routerId);
+ routerStore.remove(routerId, router);
+ if (routerStore.containsKey(routerId)) {
+ log.debug("The router deleted is failed whose identifier is {}",
+ routerId.toString());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void addListener(RouterListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(RouterListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.remove(listener);
+ }
+
+ /**
+ * Verifies validity of Router data.
+ *
+ * @param routers router instance
+ */
+ private void verifyRouterData(Router routers) {
+ checkNotNull(routers, ROUTER_NOT_NULL);
+ if (routers.gatewayPortid() != null
+ && !virtualPortService.exists(routers.gatewayPortid())) {
+ log.debug("The gateway port ID is not exist whose identifier is {}",
+ routers.gatewayPortid().toString());
+ throw new IllegalArgumentException("gateway port ID doesn't exist");
+ }
+
+ if (routers.externalGatewayInfo() != null) {
+ RouterGateway routerGateway = routers.externalGatewayInfo();
+ if (!tenantNetworkService.exists(routerGateway.networkId())) {
+ log.debug("The network ID of gateway info is not exist whose identifier is {}",
+ routers.id().toString());
+ throw new IllegalArgumentException(
+ "network ID of gateway info doesn't exist");
+ }
+ Iterable<FixedIp> fixedIps = routerGateway.externalFixedIps();
+ for (FixedIp fixedIp : fixedIps) {
+ if (!subnetService.exists(fixedIp.subnetId())) {
+ log.debug("The subnet ID of gateway info is not exist whose identifier is {}",
+ routers.id().toString());
+ throw new IllegalArgumentException(
+ "subnet ID of gateway info doesn't exist");
+ }
+ }
+ }
+ }
+
+ private class InnerRouterStoreListener
+ implements EventuallyConsistentMapListener<RouterId, Router> {
+
+ @Override
+ public void event(EventuallyConsistentMapEvent<RouterId, Router> event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ Router router = event.value();
+ if (EventuallyConsistentMapEvent.Type.PUT == event.type()) {
+ notifyListeners(new RouterEvent(RouterEvent.Type.ROUTER_PUT,
+ router));
+ }
+ if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) {
+ notifyListeners(new RouterEvent(RouterEvent.Type.ROUTER_DELETE,
+ router));
+ }
+ }
+ }
+
+ /**
+ * Notifies specify event to all listeners.
+ *
+ * @param event Floating IP event
+ */
+ private void notifyListeners(RouterEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ listeners.forEach(listener -> listener.event(event));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/package-info.java
new file mode 100644
index 00000000..1254f982
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides implementation of the Router service.
+ */
+package org.onosproject.vtnrsc.router.impl;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/package-info.java
new file mode 100644
index 00000000..fb6834aa
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/router/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Service for interacting with the inventory of Router.
+ */
+package org.onosproject.vtnrsc.router;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceEvent.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceEvent.java
new file mode 100644
index 00000000..7f5cfa13
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceEvent.java
@@ -0,0 +1,62 @@
+/*
+ * 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.routerinterface;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.vtnrsc.RouterInterface;
+
+/**
+ * Describes network Router Interface event.
+ */
+public class RouterInterfaceEvent
+ extends AbstractEvent<RouterInterfaceEvent.Type, RouterInterface> {
+
+ /**
+ * Type of Router Interface events.
+ */
+ public enum Type {
+ /**
+ * Signifies that router interface has been added.
+ */
+ ROUTER_INTERFACE_PUT,
+ /**
+ * Signifies that router interface has been removed.
+ */
+ ROUTER_INTERFACE_DELETE
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Router Interface.
+ *
+ * @param type Router Interface event type
+ * @param routerInterface Router Interface subject
+ */
+ public RouterInterfaceEvent(Type type, RouterInterface routerInterface) {
+ super(type, routerInterface);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified Router Interface.
+ *
+ * @param type Router Interface event type.
+ * @param routerInterface Router Interface subject
+ * @param time occurrence time
+ */
+ public RouterInterfaceEvent(Type type, RouterInterface routerInterface,
+ long time) {
+ super(type, routerInterface, time);
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceListener.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceListener.java
new file mode 100644
index 00000000..1d0dab6f
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.routerinterface;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of Router Interface related events.
+ */
+public interface RouterInterfaceListener
+ extends EventListener<RouterInterfaceEvent> {
+
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceService.java
new file mode 100644
index 00000000..8cf147a5
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/RouterInterfaceService.java
@@ -0,0 +1,80 @@
+/*
+ * 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.routerinterface;
+
+import java.util.Collection;
+
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SubnetId;
+
+/**
+ * Service for interacting with the inventory of Router interface.
+ */
+public interface RouterInterfaceService {
+ /**
+ * Returns exists or not of specific subnet identifier.
+ *
+ * @param subnetId subnet identifier
+ * @return true or false
+ */
+ boolean exists(SubnetId subnetId);
+
+ /**
+ * Returns a collection of the currently known Router interface.
+ *
+ * @return collection of RouterInterface
+ */
+ Collection<RouterInterface> getRouterInterfaces();
+
+ /**
+ * Returns the Router interface with the specified subnet identifier.
+ *
+ * @param subnetId subnet identifier
+ * @return RouterInterface or null if one with the given identifier is not
+ * known
+ */
+ RouterInterface getRouterInterface(SubnetId subnetId);
+
+ /**
+ * Adds the specified RouterInterface.
+ *
+ * @param routerInterface the interface add to router
+ * @return true if add router interface successfully
+ */
+ boolean addRouterInterface(RouterInterface routerInterface);
+
+ /**
+ * Removes the specified RouterInterface.
+ *
+ * @param routerInterface the interface remove from router
+ * @return true if remove router interface successfully
+ */
+ boolean removeRouterInterface(RouterInterface routerInterface);
+
+ /**
+ * Adds the specified listener to Router Interface manager.
+ *
+ * @param listener Router Interface listener
+ */
+ void addListener(RouterInterfaceListener listener);
+
+ /**
+ * Removes the specified listener to RouterInterface manager.
+ *
+ * @param listener Router Interface listener
+ */
+ void removeListener(RouterInterfaceListener listener);
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/RouterInterfaceManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/RouterInterfaceManager.java
new file mode 100644
index 00000000..244a5c03
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/RouterInterfaceManager.java
@@ -0,0 +1,235 @@
+/*
+ * 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.routerinterface.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.EventuallyConsistentMapEvent;
+import org.onosproject.store.service.EventuallyConsistentMapListener;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.onosproject.vtnrsc.RouterId;
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.router.RouterService;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceEvent;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceListener;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
+import org.onosproject.vtnrsc.subnet.SubnetService;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Provides implementation of the Router interface service.
+ */
+@Component(immediate = true)
+@Service
+public class RouterInterfaceManager implements RouterInterfaceService {
+ private static final String SUBNET_ID_NULL = "Subnet ID cannot be null";
+ private static final String ROUTER_INTERFACE_NULL = "Router Interface cannot be null";
+ private static final String ROUTER_INTERFACE = "vtn-router-interface-store";
+ private static final String VTNRSC_APP = "org.onosproject.vtnrsc";
+ private static final String LISTENER_NOT_NULL = "Listener cannot be null";
+ private static final String EVENT_NOT_NULL = "event cannot be null";
+
+ private final Logger log = getLogger(getClass());
+ private final Set<RouterInterfaceListener> listeners = Sets
+ .newCopyOnWriteArraySet();
+ private EventuallyConsistentMapListener<SubnetId, RouterInterface> routerInterfaceListener =
+ new InnerRouterInterfaceStoreListener();
+ protected EventuallyConsistentMap<SubnetId, RouterInterface> routerInterfaceStore;
+ protected ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VirtualPortService virtualPortService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected SubnetService subnetService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RouterService routerService;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(VTNRSC_APP);
+ KryoNamespace.Builder serializer = KryoNamespace
+ .newBuilder()
+ .register(KryoNamespaces.API)
+ .register(RouterId.class, TenantId.class, VirtualPortId.class,
+ RouterInterface.class, SubnetId.class);
+ routerInterfaceStore = storageService
+ .<SubnetId, RouterInterface>eventuallyConsistentMapBuilder()
+ .withName(ROUTER_INTERFACE).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> new WallClockTimestamp())
+ .build();
+ routerInterfaceStore.addListener(routerInterfaceListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ routerInterfaceStore.removeListener(routerInterfaceListener);
+ routerInterfaceStore.destroy();
+ listeners.clear();
+ log.info("Stopped");
+ }
+
+ @Override
+ public boolean exists(SubnetId subnetId) {
+ checkNotNull(subnetId, SUBNET_ID_NULL);
+ return routerInterfaceStore.containsKey(subnetId);
+ }
+
+ @Override
+ public Collection<RouterInterface> getRouterInterfaces() {
+ return Collections
+ .unmodifiableCollection(routerInterfaceStore.values());
+ }
+
+ @Override
+ public RouterInterface getRouterInterface(SubnetId subnetId) {
+ checkNotNull(subnetId, SUBNET_ID_NULL);
+ return routerInterfaceStore.get(subnetId);
+ }
+
+ @Override
+ public boolean addRouterInterface(RouterInterface routerInterface) {
+ checkNotNull(routerInterface, ROUTER_INTERFACE_NULL);
+ verifyRouterInterfaceData(routerInterface);
+ routerInterfaceStore.put(routerInterface.subnetId(), routerInterface);
+ if (!routerInterfaceStore.containsKey(routerInterface.subnetId())) {
+ log.debug("The router interface is created failed whose identifier is {}",
+ routerInterface.subnetId().toString());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeRouterInterface(RouterInterface routerInterface) {
+ checkNotNull(routerInterface, ROUTER_INTERFACE_NULL);
+ if (!routerInterfaceStore.containsKey(routerInterface.subnetId())) {
+ log.debug("The router interface is not exist whose identifier is {}",
+ routerInterface.subnetId().toString());
+ throw new IllegalArgumentException("subnet ID doesn't exist");
+ }
+ verifyRouterInterfaceData(routerInterface);
+ routerInterfaceStore
+ .remove(routerInterface.subnetId(), routerInterface);
+ if (routerInterfaceStore.containsKey(routerInterface.subnetId())) {
+ log.debug("The router interface deleted is failed whose identifier is {}",
+ routerInterface.subnetId().toString());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void addListener(RouterInterfaceListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(RouterInterfaceListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.remove(listener);
+ }
+
+ /**
+ * Verifies validity of Router interface data.
+ *
+ * @param routers router instance
+ */
+ private void verifyRouterInterfaceData(RouterInterface routerInterface) {
+ checkNotNull(routerInterface, ROUTER_INTERFACE_NULL);
+ if (!subnetService.exists(routerInterface.subnetId())) {
+ log.debug("The subnet ID of interface is not exist whose identifier is {}",
+ routerInterface.subnetId().toString());
+ throw new IllegalArgumentException(
+ "subnet ID of interface doesn't exist");
+ }
+ if (!virtualPortService.exists(routerInterface.portId())) {
+ log.debug("The port ID of interface is not exist whose identifier is {}",
+ routerInterface.portId().toString());
+ throw new IllegalArgumentException(
+ "port ID of interface doesn't exist");
+ }
+ if (!routerService.exists(routerInterface.routerId())) {
+ log.debug("The router ID of interface is not exist whose identifier is {}",
+ routerInterface.routerId().toString());
+ throw new IllegalArgumentException(
+ "router ID of interface doesn't exist");
+ }
+ }
+
+ private class InnerRouterInterfaceStoreListener
+ implements
+ EventuallyConsistentMapListener<SubnetId, RouterInterface> {
+
+ @Override
+ public void event(EventuallyConsistentMapEvent<SubnetId, RouterInterface> event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ RouterInterface routerInterface = event.value();
+ if (EventuallyConsistentMapEvent.Type.PUT == event.type()) {
+ notifyListeners(new RouterInterfaceEvent(
+ RouterInterfaceEvent.Type.ROUTER_INTERFACE_PUT,
+ routerInterface));
+ }
+ if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) {
+ notifyListeners(new RouterInterfaceEvent(
+ RouterInterfaceEvent.Type.ROUTER_INTERFACE_DELETE,
+ routerInterface));
+ }
+ }
+ }
+
+ /**
+ * Notifies specify event to all listeners.
+ *
+ * @param event Floating IP event
+ */
+ private void notifyListeners(RouterInterfaceEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ listeners.forEach(listener -> listener.event(event));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/package-info.java
new file mode 100644
index 00000000..71db9dc5
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides implementation of the RouterInterface service.
+ */
+package org.onosproject.vtnrsc.routerinterface.impl;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/package-info.java
new file mode 100644
index 00000000..3804089a
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/routerinterface/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Service for interacting with the inventory of RouterInterface.
+ */
+package org.onosproject.vtnrsc.routerinterface;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java
new file mode 100644
index 00000000..21161ba5
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java
@@ -0,0 +1,94 @@
+/*
+ * 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.service;
+
+import java.util.Iterator;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.vtnrsc.SegmentationId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.event.VtnRscListener;
+
+/**
+ * Service for interacting with the inventory of Vtn resource.
+ */
+public interface VtnRscService {
+ /**
+ * Adds the specified listener.
+ *
+ * @param listener VtnRsc listener
+ */
+ void addListener(VtnRscListener listener);
+
+ /**
+ * Removes the specified listener.
+ *
+ * @param listener VtnRsc listener
+ */
+ void removeListener(VtnRscListener listener);
+
+ /**
+ * Returns the SegmentationId of tenant.
+ *
+ * @param tenantId tenant identifier
+ * @return SegmentationId the SegmentationId of tenant
+ */
+ SegmentationId getL3vni(TenantId tenantId);
+
+ /**
+ * Returns Classifier Ovs list of the specific tenant.
+ *
+ * @param tenantId tenant identifier
+ * @return iterable collection of Device
+ */
+ Iterator<Device> getClassifierOfTenant(TenantId tenantId);
+
+ /**
+ * Returns Service function forwarders Ovs list of the specific tenant.
+ *
+ * @param tenantId tenant identifier
+ * @return iterable collection of Device
+ */
+ Iterator<Device> getSFFOfTenant(TenantId tenantId);
+
+ /**
+ * Returns gateway mac address of the specific host.
+ *
+ * @param hostId host identifier
+ * @return MacAddress of host
+ */
+ MacAddress getGatewayMac(HostId hostId);
+
+ /**
+ * Checks if a specific port is a service function.
+ *
+ * @param portId port identifier
+ * @return true or false
+ */
+ boolean isServiceFunction(VirtualPortId portId);
+
+ /**
+ * Returns device identifier mapping to the specific port.
+ *
+ * @param portId port identifier
+ * @return device identifier
+ */
+ DeviceId getSFToSFFMaping(VirtualPortId portId);
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java
new file mode 100644
index 00000000..ec9ca3ef
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java
@@ -0,0 +1,472 @@
+/*
+ * 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.service.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+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.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.host.HostEvent;
+import org.onosproject.net.host.HostListener;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.LogicalClockService;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.vtnrsc.FixedIp;
+import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.Router;
+import org.onosproject.vtnrsc.RouterInterface;
+import org.onosproject.vtnrsc.SegmentationId;
+import org.onosproject.vtnrsc.Subnet;
+import org.onosproject.vtnrsc.SubnetId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPort;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.event.VtnRscEvent;
+import org.onosproject.vtnrsc.event.VtnRscEventFeedback;
+import org.onosproject.vtnrsc.event.VtnRscListener;
+import org.onosproject.vtnrsc.floatingip.FloatingIpEvent;
+import org.onosproject.vtnrsc.floatingip.FloatingIpListener;
+import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+import org.onosproject.vtnrsc.router.RouterEvent;
+import org.onosproject.vtnrsc.router.RouterListener;
+import org.onosproject.vtnrsc.router.RouterService;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceEvent;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceListener;
+import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
+import org.onosproject.vtnrsc.service.VtnRscService;
+import org.onosproject.vtnrsc.subnet.SubnetService;
+import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Provides implementation of the VtnRsc service.
+ */
+@Component(immediate = true)
+@Service
+public class VtnRscManager implements VtnRscService {
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LogicalClockService clockService;
+
+ private final Logger log = getLogger(getClass());
+ private final Set<VtnRscListener> listeners = Sets.newCopyOnWriteArraySet();
+ private HostListener hostListener = new InnerHostListener();
+ private FloatingIpListener floatingIpListener = new InnerFloatingIpListener();
+ private RouterListener routerListener = new InnerRouterListener();
+ private RouterInterfaceListener routerInterfaceListener = new InnerRouterInterfaceListener();
+
+ private EventuallyConsistentMap<TenantId, SegmentationId> l3vniMap;
+ private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap;
+ private EventuallyConsistentMap<TenantId, Set<DeviceId>> sffOvsMap;
+
+ private static final String IFACEID = "ifaceid";
+ private static final String RUNNELOPTOPOIC = "tunnel-ops-ids";
+ private static final String LISTENER_NOT_NULL = "listener cannot be null";
+ private static final String EVENT_NOT_NULL = "event cannot be null";
+ private static final String TENANTID_NOT_NULL = "tenantId cannot be null";
+ private static final String DEVICEID_NOT_NULL = "deviceId cannot be null";
+ private static final String OVSMAP_NOT_NULL = "ovsMap cannot be null";
+ private static final String L3VNIMAP = "l3vniMap";
+ private static final String CLASSIFIEROVSMAP = "classifierOvsMap";
+ private static final String SFFOVSMAP = "sffOvsMap";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RouterService routerService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FloatingIpService floatingIpService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RouterInterfaceService routerInterfaceService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VirtualPortService virtualPortService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostService hostService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected SubnetService subnetService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TenantNetworkService tenantNetworkService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Activate
+ public void activate() {
+ hostService.addListener(hostListener);
+ floatingIpService.addListener(floatingIpListener);
+ routerService.addListener(routerListener);
+ routerInterfaceService.addListener(routerInterfaceListener);
+
+ KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
+ .register(KryoNamespaces.API)
+ .register(TenantId.class, DeviceId.class);
+ l3vniMap = storageService
+ .<TenantId, SegmentationId>eventuallyConsistentMapBuilder()
+ .withName(L3VNIMAP).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> clockService.getTimestamp())
+ .build();
+
+ classifierOvsMap = storageService
+ .<TenantId, Set<DeviceId>>eventuallyConsistentMapBuilder()
+ .withName(CLASSIFIEROVSMAP).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> clockService.getTimestamp())
+ .build();
+
+ sffOvsMap = storageService
+ .<TenantId, Set<DeviceId>>eventuallyConsistentMapBuilder()
+ .withName(SFFOVSMAP).withSerializer(serializer)
+ .withTimestampProvider((k, v) -> clockService.getTimestamp())
+ .build();
+ }
+
+ @Deactivate
+ public void deactivate() {
+ hostService.removeListener(hostListener);
+ floatingIpService.removeListener(floatingIpListener);
+ routerService.removeListener(routerListener);
+ routerInterfaceService.removeListener(routerInterfaceListener);
+ l3vniMap.destroy();
+ classifierOvsMap.destroy();
+ sffOvsMap.destroy();
+ listeners.clear();
+ log.info("Stopped");
+ }
+
+ @Override
+ public void addListener(VtnRscListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(VtnRscListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public SegmentationId getL3vni(TenantId tenantId) {
+ checkNotNull(tenantId, "tenantId cannot be null");
+ SegmentationId l3vni = l3vniMap.get(tenantId);
+ if (l3vni == null) {
+ long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC)
+ .getNewId();
+ l3vni = SegmentationId.segmentationId(String
+ .valueOf(segmentationId));
+ l3vniMap.put(tenantId, l3vni);
+ }
+ return l3vni;
+ }
+
+ private class InnerHostListener implements HostListener {
+
+ @Override
+ public void event(HostEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ Host host = event.subject();
+ String ifaceId = host.annotations().value(IFACEID);
+ VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
+ TenantId tenantId = virtualPortService.getPort(hPortId).tenantId();
+ DeviceId deviceId = host.location().deviceId();
+ if (HostEvent.Type.HOST_ADDED == event.type()) {
+ if (isServiceFunction(hPortId)) {
+ addDeviceIdOfOvsMap(tenantId, deviceId, sffOvsMap);
+ } else {
+ addDeviceIdOfOvsMap(tenantId, deviceId, classifierOvsMap);
+ }
+ } else if (HostEvent.Type.HOST_REMOVED == event.type()) {
+ if (isLastSFHostOfTenant(host, deviceId, tenantId)) {
+ removeDeviceIdOfOvsMap(tenantId, deviceId, sffOvsMap);
+ }
+ if (isLastClassifierHostOfTenant(host, deviceId, tenantId)) {
+ removeDeviceIdOfOvsMap(tenantId, deviceId, classifierOvsMap);
+ }
+ }
+ }
+ }
+
+ private class InnerFloatingIpListener implements FloatingIpListener {
+
+ @Override
+ public void event(FloatingIpEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ FloatingIp floatingIp = event.subject();
+ if (FloatingIpEvent.Type.FLOATINGIP_PUT == event.type()) {
+ notifyListeners(new VtnRscEvent(
+ VtnRscEvent.Type.FLOATINGIP_PUT,
+ new VtnRscEventFeedback(
+ floatingIp)));
+ }
+ if (FloatingIpEvent.Type.FLOATINGIP_DELETE == event.type()) {
+ notifyListeners(new VtnRscEvent(
+ VtnRscEvent.Type.FLOATINGIP_DELETE,
+ new VtnRscEventFeedback(
+ floatingIp)));
+ }
+ }
+ }
+
+ private class InnerRouterListener implements RouterListener {
+
+ @Override
+ public void event(RouterEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ Router router = event.subject();
+ if (RouterEvent.Type.ROUTER_PUT == event.type()) {
+ notifyListeners(new VtnRscEvent(VtnRscEvent.Type.ROUTER_PUT,
+ new VtnRscEventFeedback(router)));
+ }
+ if (RouterEvent.Type.ROUTER_DELETE == event.type()) {
+ notifyListeners(new VtnRscEvent(VtnRscEvent.Type.ROUTER_DELETE,
+ new VtnRscEventFeedback(router)));
+ }
+ }
+ }
+
+ private class InnerRouterInterfaceListener
+ implements RouterInterfaceListener {
+
+ @Override
+ public void event(RouterInterfaceEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ RouterInterface routerInterface = event.subject();
+ if (RouterInterfaceEvent.Type.ROUTER_INTERFACE_PUT == event.type()) {
+ notifyListeners(new VtnRscEvent(
+ VtnRscEvent.Type.ROUTER_INTERFACE_PUT,
+ new VtnRscEventFeedback(
+ routerInterface)));
+ }
+ if (RouterInterfaceEvent.Type.ROUTER_INTERFACE_DELETE == event
+ .type()) {
+ notifyListeners(new VtnRscEvent(
+ VtnRscEvent.Type.ROUTER_INTERFACE_DELETE,
+ new VtnRscEventFeedback(
+ routerInterface)));
+ }
+ }
+ }
+
+ @Override
+ public Iterator<Device> getClassifierOfTenant(TenantId tenantId) {
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ Set<DeviceId> deviceIdSet = classifierOvsMap.get(tenantId);
+ Set<Device> deviceSet = new HashSet<>();
+ if (deviceIdSet != null) {
+ for (DeviceId deviceId : deviceIdSet) {
+ deviceSet.add(deviceService.getDevice(deviceId));
+ }
+ }
+ return deviceSet.iterator();
+ }
+
+ @Override
+ public Iterator<Device> getSFFOfTenant(TenantId tenantId) {
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ Set<DeviceId> deviceIdSet = sffOvsMap.get(tenantId);
+ Set<Device> deviceSet = new HashSet<>();
+ if (deviceIdSet != null) {
+ for (DeviceId deviceId : deviceIdSet) {
+ deviceSet.add(deviceService.getDevice(deviceId));
+ }
+ }
+ return deviceSet.iterator();
+ }
+
+ @Override
+ public MacAddress getGatewayMac(HostId hostId) {
+ checkNotNull(hostId, "hostId cannot be null");
+ Host host = hostService.getHost(hostId);
+ String ifaceId = host.annotations().value(IFACEID);
+ VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
+ VirtualPort hPort = virtualPortService.getPort(hPortId);
+ SubnetId subnetId = hPort.fixedIps().iterator().next().subnetId();
+ Subnet subnet = subnetService.getSubnet(subnetId);
+ IpAddress gatewayIp = subnet.gatewayIp();
+ Iterable<VirtualPort> virtualPorts = virtualPortService.getPorts();
+ MacAddress macAddress = null;
+ for (VirtualPort port : virtualPorts) {
+ Set<FixedIp> fixedIpSet = port.fixedIps();
+ for (FixedIp fixedIp : fixedIpSet) {
+ if (fixedIp.ip().equals(gatewayIp)) {
+ macAddress = port.macAddress();
+ }
+ }
+ }
+ return macAddress;
+ }
+
+ @Override
+ public boolean isServiceFunction(VirtualPortId portId) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public DeviceId getSFToSFFMaping(VirtualPortId portId) {
+ checkNotNull(portId, "portId cannot be null");
+ VirtualPort vmPort = virtualPortService.getPort(portId);
+ Set<Host> hostSet = hostService.getHostsByMac(vmPort.macAddress());
+ for (Host host : hostSet) {
+ if (host.annotations().value(IFACEID).equals(vmPort.portId())) {
+ return host.location().deviceId();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks whether the last Service Function host of a specific tenant in
+ * this device.
+ *
+ * @param host the host on device
+ * @param deviceId the device identifier
+ * @param tenantId the tenant identifier
+ * @return true or false
+ */
+ private boolean isLastSFHostOfTenant(Host host, DeviceId deviceId,
+ TenantId tenantId) {
+ checkNotNull(host, "host cannot be null");
+ checkNotNull(deviceId, DEVICEID_NOT_NULL);
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ Set<Host> hostSet = hostService.getConnectedHosts(deviceId);
+ for (Host h : hostSet) {
+ String ifaceId = h.annotations().value(IFACEID);
+ VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
+ if (virtualPortService.getPort(hPortId).tenantId() != tenantId) {
+ hostSet.remove(h);
+ } else {
+ if (!isServiceFunction(hPortId)) {
+ hostSet.remove(h);
+ }
+ }
+ }
+ if (hostSet.size() == 1 && hostSet.contains(host)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the last Classifier host of a specific tenant in this
+ * device.
+ *
+ * @param host the host on device
+ * @param deviceId the device identifier
+ * @param tenantId the tenant identifier
+ * @return true or false
+ */
+ private boolean isLastClassifierHostOfTenant(Host host, DeviceId deviceId,
+ TenantId tenantId) {
+ checkNotNull(host, "host cannot be null");
+ checkNotNull(deviceId, DEVICEID_NOT_NULL);
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ Set<Host> hostSet = hostService.getConnectedHosts(deviceId);
+ for (Host h : hostSet) {
+ String ifaceId = h.annotations().value(IFACEID);
+ VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
+ if (virtualPortService.getPort(hPortId).tenantId() != tenantId) {
+ hostSet.remove(h);
+ } else {
+ if (isServiceFunction(hPortId)) {
+ hostSet.remove(h);
+ }
+ }
+ }
+ if (hostSet.size() == 1 && hostSet.contains(host)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Adds specify Device identifier to OvsMap.
+ *
+ * @param tenantId the tenant identifier
+ * @param deviceId the device identifier
+ * @param ovsMap the instance of map to store device identifier
+ */
+ private void addDeviceIdOfOvsMap(TenantId tenantId,
+ DeviceId deviceId,
+ EventuallyConsistentMap<TenantId, Set<DeviceId>> ovsMap) {
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ checkNotNull(deviceId, DEVICEID_NOT_NULL);
+ checkNotNull(ovsMap, OVSMAP_NOT_NULL);
+ if (ovsMap.containsKey(tenantId)) {
+ Set<DeviceId> deviceIdSet = ovsMap.get(tenantId);
+ deviceIdSet.add(deviceId);
+ ovsMap.put(tenantId, deviceIdSet);
+ } else {
+ Set<DeviceId> deviceIdSet = new HashSet<>();
+ deviceIdSet.add(deviceId);
+ ovsMap.put(tenantId, deviceIdSet);
+ }
+ }
+
+ /**
+ * Removes specify Device identifier from OvsMap.
+ *
+ * @param tenantId the tenant identifier
+ * @param deviceId the device identifier
+ * @param ovsMap the instance of map to store device identifier
+ */
+ private void removeDeviceIdOfOvsMap(TenantId tenantId,
+ DeviceId deviceId,
+ EventuallyConsistentMap<TenantId, Set<DeviceId>> ovsMap) {
+ checkNotNull(tenantId, TENANTID_NOT_NULL);
+ checkNotNull(deviceId, DEVICEID_NOT_NULL);
+ checkNotNull(ovsMap, OVSMAP_NOT_NULL);
+ Set<DeviceId> deviceIdSet = ovsMap.get(tenantId);
+ if (deviceIdSet.size() > 1) {
+ deviceIdSet.remove(deviceId);
+ ovsMap.put(tenantId, deviceIdSet);
+ } else {
+ ovsMap.remove(tenantId);
+ }
+ }
+
+ /**
+ * Notifies specify event to all listeners.
+ *
+ * @param event VtnRsc event
+ */
+ private void notifyListeners(VtnRscEvent event) {
+ checkNotNull(event, EVENT_NOT_NULL);
+ listeners.forEach(listener -> listener.event(event));
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/package-info.java
new file mode 100644
index 00000000..aaea08b3
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides implementation of the VtnRsc service.
+ */
+package org.onosproject.vtnrsc.service.impl;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/package-info.java
new file mode 100644
index 00000000..37af604a
--- /dev/null
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Service for interacting with the inventory of Vtn resource.
+ */
+package org.onosproject.vtnrsc.service;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
index 890beb29..94430389 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
@@ -144,21 +144,19 @@ public class SubnetManager implements SubnetService {
@Override
public boolean updateSubnets(Iterable<Subnet> subnets) {
checkNotNull(subnets, SUBNET_NOT_NULL);
- if (subnets != null) {
- for (Subnet subnet : subnets) {
- if (!subnetStore.containsKey(subnet.id())) {
- log.debug("The subnet is not exist whose identifier is {}",
- subnet.id().toString());
- return false;
- }
-
- subnetStore.put(subnet.id(), subnet);
-
- if (!subnet.equals(subnetStore.get(subnet.id()))) {
- log.debug("The subnet is updated failed whose identifier is {}",
- subnet.id().toString());
- return false;
- }
+ for (Subnet subnet : subnets) {
+ if (!subnetStore.containsKey(subnet.id())) {
+ log.debug("The subnet is not exist whose identifier is {}",
+ subnet.id().toString());
+ return false;
+ }
+
+ subnetStore.put(subnet.id(), subnet);
+
+ if (!subnet.equals(subnetStore.get(subnet.id()))) {
+ log.debug("The subnet is updated failed whose identifier is {}",
+ subnet.id().toString());
+ return false;
}
}
return true;
@@ -167,14 +165,12 @@ public class SubnetManager implements SubnetService {
@Override
public boolean removeSubnets(Iterable<SubnetId> subnetIds) {
checkNotNull(subnetIds, SUBNET_ID_NULL);
- if (subnetIds != null) {
- for (SubnetId subnetId : subnetIds) {
- subnetStore.remove(subnetId);
- if (subnetStore.containsKey(subnetId)) {
- log.debug("The subnet created is failed whose identifier is {}",
- subnetId.toString());
- return false;
- }
+ for (SubnetId subnetId : subnetIds) {
+ subnetStore.remove(subnetId);
+ if (subnetStore.containsKey(subnetId)) {
+ log.debug("The subnet created is failed whose identifier is {}",
+ subnetId.toString());
+ return false;
}
}
return true;