CORD-176, CORD-431 Switch to new VTN API
- Implemented VTN store and manager to keep network states
- Implemented the new VTN API for service network and port
Change-Id: Id8f5d0e609fa3deba782ff2265fc0d3175cbcb4c
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnAdminService.java b/src/main/java/org/opencord/cordvtn/api/CordVtnAdminService.java
new file mode 100644
index 0000000..afb2a1e
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnAdminService.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+import org.openstack4j.model.network.Subnet;
+
+/**
+ * Service for administering the inventory of virtual network and service network.
+ */
+public interface CordVtnAdminService extends CordVtnService {
+
+ /**
+ * Creates vtn port with given service port information.
+ *
+ * @param servicePort the new service port
+ */
+ void createVtnPort(ServicePort servicePort);
+
+ /**
+ * Updates vtn port with given service port information.
+ *
+ * @param servicePort the updated service port
+ */
+ void updateVtnPort(ServicePort servicePort);
+
+ /**
+ * Removes vtn port with given port id.
+ *
+ * @param portId port id
+ */
+ void removeVtnPort(PortId portId);
+
+ /**
+ * Creates vtn network with given service network information.
+ *
+ * @param serviceNet the new service network
+ */
+ void createVtnNetwork(ServiceNetwork serviceNet);
+
+ /**
+ * Updates the vtn network with given service network information.
+ *
+ * @param serviceNet the updated service network
+ */
+ void updateVtnNetwork(ServiceNetwork serviceNet);
+
+ /**
+ * Removes the vtn network.
+ *
+ * @param netId network id
+ */
+ void removeVtnNetwork(NetworkId netId);
+
+ /**
+ * Creates a port.
+ *
+ * @param port port
+ */
+ void createPort(Port port);
+
+ /**
+ * Updates the port.
+ *
+ * @param port the updated port
+ */
+ void updatePort(Port port);
+
+ /**
+ * Removes the port with the given port id.
+ *
+ * @param portId port id
+ */
+ void removePort(PortId portId);
+
+ /**
+ * Creates a network.
+ *
+ * @param network network
+ */
+ void createNetwork(Network network);
+
+ /**
+ * Updates the network.
+ *
+ * @param network the updated network
+ */
+ void updateNetwork(Network network);
+
+ /**
+ * Removes the network with the given network id.
+ *
+ * @param netId network id
+ */
+ void removeNetwork(NetworkId netId);
+
+ /**
+ * Creates a subnet.
+ *
+ * @param subnet subnet id
+ */
+ void createSubnet(Subnet subnet);
+
+ /**
+ * Updates the subnet.
+ *
+ * @param subnet the updated subnet
+ */
+ void updateSubnet(Subnet subnet);
+
+ /**
+ * Removes the subnet with the given subnet id.
+ *
+ * @param subnetId subnet id
+ */
+ void removeSubnet(SubnetId subnetId);
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java b/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
index 41e869d..d0a9562 100644
--- a/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnConfig.java
@@ -25,8 +25,6 @@
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
-import org.onosproject.xosclient.api.OpenStackAccess;
-import org.onosproject.xosclient.api.XosAccess;
import org.slf4j.Logger;
import java.util.Map;
@@ -236,28 +234,5 @@
return publicGateways;
}
- /**
- * Returns XOS access information.
- *
- * @return XOS access, or null
- */
- public XosAccess xosAccess() {
- JsonNode jsonNode = object.get(XOS);
- return new XosAccess(getConfig(jsonNode, ENDPOINT),
- getConfig(jsonNode, USER),
- getConfig(jsonNode, PASSWORD));
- }
-
- /**
- * Returns OpenStack API access information.
- *
- * @return openstack access
- */
- public OpenStackAccess openstackAccess() {
- JsonNode jsonNode = object.get(OPENSTACK);
- return new OpenStackAccess(jsonNode.path(ENDPOINT).asText(),
- jsonNode.path(TENANT).asText(),
- jsonNode.path(USER).asText(),
- jsonNode.path(PASSWORD).asText());
- }
+ // TODO add methods to get XOS and OpenStack API access
}
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnService.java b/src/main/java/org/opencord/cordvtn/api/CordVtnService.java
new file mode 100644
index 0000000..5b0849e
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnService.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.onosproject.event.ListenerService;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+import org.openstack4j.model.network.Subnet;
+
+import java.util.Set;
+
+/**
+ * Service for interacting with the inventory of VTN network and port.
+ */
+public interface CordVtnService
+ extends ListenerService<VtnNetworkEvent, VtnNetworkListener> {
+
+ /**
+ * Returns the service port with the given port id.
+ *
+ * @param portId port id
+ * @return service port
+ */
+ VtnPort getVtnPort(PortId portId);
+
+ /**
+ * Returns the vtn port with the given port id. It returns the VTN port with
+ * the default settings if no service port exists for the port.
+ *
+ * @param portId port id
+ * @return vtn port for the port, of the default vtn port if no service port
+ * exists for the port
+ */
+ VtnPort getVtnPortOrDefault(PortId portId);
+
+ /**
+ * Returns the VTN port with the given port name.
+ *
+ * @param portName port name
+ * @return vtn port
+ */
+ VtnPort getVtnPort(String portName);
+
+ /**
+ * Returns all service ports.
+ *
+ * @return set of service ports
+ */
+ Set<VtnPort> getVtnPorts();
+
+ /**
+ * Returns the service network with the given network id.
+ *
+ * @param netId network id
+ * @return service network
+ */
+ VtnNetwork getVtnNetwork(NetworkId netId);
+
+ /**
+ * Returns the vtn network with the given network id. It returns the VTN
+ * network with default settings if no service network exists for the network.
+ *
+ * @param netId network id
+ * @return vtn network for the network id, or the default vtn network if no
+ * service network is created for the network
+ */
+ VtnNetwork getVtnNetworkOrDefault(NetworkId netId);
+
+ /**
+ * Returns all service networks.
+ *
+ * @return set of service networks
+ */
+ Set<VtnNetwork> getVtnNetworks();
+
+ /**
+ * Returns the port with the given port id.
+ *
+ * @param portId port id
+ * @return port
+ */
+ Port getPort(PortId portId);
+
+ /**
+ * Returns all ports.
+ *
+ * @return set of ports
+ */
+ Set<Port> getPorts();
+
+ /**
+ * Returns the network with the given network id.
+ *
+ * @param netId network id
+ * @return network
+ */
+ Network getNetwork(NetworkId netId);
+
+ /**
+ * Returns all networks.
+ *
+ * @return set of networks
+ */
+ Set<Network> getNetworks();
+
+ /**
+ * Returns the subnet with the given subnet id.
+ *
+ * @param subnetId subnet id
+ * @return subnet
+ */
+ Subnet getSubnet(SubnetId subnetId);
+
+ /**
+ * Returns all subnets.
+ *
+ * @return set of subnets
+ */
+ Set<Subnet> getSubnets();
+
+ /**
+ * Returns instance attached to the given port.
+ *
+ * @param portId port identifier
+ * @return instance, or null if no instance for the port
+ */
+ Instance getInstance(PortId portId);
+
+ /**
+ * Returns instances in the given network.
+ *
+ * @param netId network identifier
+ * @return set of instances, empty set if no instances in the network
+ */
+ Set<Instance> getInstances(NetworkId netId);
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnStore.java b/src/main/java/org/opencord/cordvtn/api/CordVtnStore.java
index d6d7a9b..bfa84f7 100644
--- a/src/main/java/org/opencord/cordvtn/api/CordVtnStore.java
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnStore.java
@@ -15,77 +15,195 @@
*/
package org.opencord.cordvtn.api;
+import org.onosproject.store.Store;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+import org.openstack4j.model.network.Subnet;
+
import java.util.Set;
/**
- * Manages VTN service networks and ports.
+ * Manages inventory of virtual and vtn networks; not intended for direct use.
*/
-public interface CordVtnStore {
+public interface CordVtnStore extends Store<VtnNetworkEvent, CordVtnStoreDelegate> {
/**
- * Creates service network.
+ * Creates vtn network.
*
- * @param serviceNet the new service network
+ * @param serviceNet the new vtn network
*/
- void createServiceNetwork(ServiceNetwork serviceNet);
+ void createVtnNetwork(VtnNetwork serviceNet);
/**
- * Updates the service network.
+ * Updates the vtn network.
*
- * @param serviceNet the updated service network
+ * @param serviceNet the updated vtn network
*/
- void updateServiceNetwork(ServiceNetwork serviceNet);
+ void updateVtnNetwork(VtnNetwork serviceNet);
/**
- * Returns the service network with the given network id.
+ * Returns the vtn network with the given network id.
*
* @param netId network id
- * @return service network
+ * @return vtn network
*/
- ServiceNetwork getServiceNetwork(NetworkId netId);
+ VtnNetwork getVtnNetwork(NetworkId netId);
/**
- * Returns all service networks.
+ * Returns all vtn networks.
*
- * @return set of service networks
+ * @return set of vtn networks
*/
- Set<ServiceNetwork> getServiceNetworks();
+ Set<VtnNetwork> getVtnNetworks();
/**
- * Removes the service network.
+ * Removes the vtn network.
*
* @param netId network id
*/
- void removeServiceNetwork(NetworkId netId);
+ void removeVtnNetwork(NetworkId netId);
/**
- * Creates service port.
+ * Creates vtn port.
*
- * @param servicePort the new service port
+ * @param servicePort the new vtn port
*/
- void createServicePort(ServicePort servicePort);
+ void createVtnPort(VtnPort servicePort);
/**
- * Returns the service port with the given port id.
+ * Updates the vtn port.
+ *
+ * @param servicePort vtn port
+ */
+ void updateVtnPort(VtnPort servicePort);
+
+ /**
+ * Returns the vtn port with the given port id.
*
* @param portId port id
- * @return service port
+ * @return vtn port
*/
- ServicePort getServicePort(PortId portId);
+ VtnPort getVtnPort(PortId portId);
/**
- * Returns all service ports.
+ * Returns all vtn ports.
*
- * @return set of service ports
+ * @return set of vtn ports
*/
- Set<ServicePort> getServicePorts();
+ Set<VtnPort> getVtnPorts();
/**
- * Removes service port.
+ * Removes vtn port.
*
* @param portId port id
*/
- void removeServicePort(PortId portId);
+ void removeVtnPort(PortId portId);
- // TODO add apis for the virtual network and port
+ /**
+ * Creates a network.
+ *
+ * @param net network
+ */
+ void createNetwork(Network net);
+
+ /**
+ * Updates the network.
+ *
+ * @param net the updated network
+ */
+ void updateNetwork(Network net);
+
+ /**
+ * Returns the network with the given network id.
+ *
+ * @param netId network id
+ * @return network
+ */
+ Network getNetwork(NetworkId netId);
+
+ /**
+ * Returns all networks.
+ *
+ * @return set of networks
+ */
+ Set<Network> getNetworks();
+
+ /**
+ * Removes the network with the given network id.
+ *
+ * @param netId network id
+ */
+ void removeNetwork(NetworkId netId);
+
+ /**
+ * Creates a port.
+ *
+ * @param port port
+ */
+ void createPort(Port port);
+
+ /**
+ * Updates the port.
+ *
+ * @param port the updated port
+ */
+ void updatePort(Port port);
+
+ /**
+ * Returns the port with the given port id.
+ *
+ * @param portId port id
+ * @return port
+ */
+ Port getPort(PortId portId);
+
+ /**
+ * Returns all ports.
+ *
+ * @return set of ports
+ */
+ Set<Port> getPorts();
+
+ /**
+ * Removes the port with the given port id.
+ *
+ * @param portId port id
+ */
+ void removePort(PortId portId);
+
+ /**
+ * Creates a subnet.
+ *
+ * @param subnet subnet id
+ */
+ void createSubnet(Subnet subnet);
+
+ /**
+ * Updates the subnet.
+ *
+ * @param subnet the updated subnet
+ */
+ void updateSubnet(Subnet subnet);
+
+ /**
+ * Returns the subnet with the given subnet id.
+ *
+ * @param subnetId subnet id
+ * @return subnet
+ */
+ Subnet getSubnet(SubnetId subnetId);
+
+ /**
+ * Returns all subnets.
+ *
+ * @return set of subnets
+ */
+ Set<Subnet> getSubnets();
+
+ /**
+ * Removes the subnet with the given subnet id.
+ *
+ * @param subnetId subnet id
+ */
+ void removeSubnet(SubnetId subnetId);
}
diff --git a/src/main/java/org/opencord/cordvtn/api/CordVtnStoreDelegate.java b/src/main/java/org/opencord/cordvtn/api/CordVtnStoreDelegate.java
new file mode 100644
index 0000000..eb43f92
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/CordVtnStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * VTN store delegate abstraction.
+ */
+public interface CordVtnStoreDelegate extends StoreDelegate<VtnNetworkEvent> {
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/Dependency.java b/src/main/java/org/opencord/cordvtn/api/Dependency.java
new file mode 100644
index 0000000..bbe7ef5
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/Dependency.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a dependency between two networks, subscriber and provider.
+ */
+public final class Dependency {
+
+ public enum Type {
+ BIDIRECTIONAL,
+ UNIDIRECTIONAL
+ }
+
+ private final VtnNetwork subscriber;
+ private final VtnNetwork provider;
+ private final Type type;
+
+ private Dependency(VtnNetwork subscriber, VtnNetwork provider, Type type) {
+ this.subscriber = subscriber;
+ this.provider = provider;
+ this.type = type;
+ }
+
+ /**
+ * Returns subscriber network.
+ *
+ * @return vtn network
+ */
+ public VtnNetwork subscriber() {
+ return subscriber;
+ }
+
+ /**
+ * Returns provider network.
+ *
+ * @return vtn network
+ */
+ public VtnNetwork provider() {
+ return provider;
+ }
+
+ /**
+ * Returns direct access type between subscriber and provider networks.
+ *
+ * @return type
+ */
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof Dependency) {
+ Dependency that = (Dependency) obj;
+ if (Objects.equals(subscriber, that.subscriber) &&
+ Objects.equals(provider, that.provider) &&
+ Objects.equals(type, that.type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(subscriber, provider, type);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("subscriber", subscriber.id())
+ .add("provider", provider.id())
+ .add("type", type)
+ .toString();
+ }
+
+ /**
+ * Returns new dependency builder instance.
+ *
+ * @return dependency
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of the dependency entities.
+ */
+ public static final class Builder {
+ private VtnNetwork subscriber;
+ private VtnNetwork provider;
+ private Type type;
+
+ private Builder() {
+ }
+
+ /**
+ * Builds an immutable dependency.
+ *
+ * @return dependency instance
+ */
+ public Dependency build() {
+ checkNotNull(subscriber);
+ checkNotNull(provider);
+ checkNotNull(type);
+
+ return new Dependency(subscriber, provider, type);
+ }
+
+ /**
+ * Returns dependency with the supplied subscriber.
+ *
+ * @param subscriber subscriber network
+ * @return dependency builder
+ */
+ public Builder subscriber(VtnNetwork subscriber) {
+ this.subscriber = subscriber;
+ return this;
+ }
+
+ /**
+ * Returns dependency with the supplied provider.
+ *
+ * @param provider provider network
+ * @return dependency builder
+ */
+ public Builder provider(VtnNetwork provider) {
+ this.provider = provider;
+ return this;
+ }
+
+ /**
+ * Returns dependency with the supplied type.
+ *
+ * @param type type
+ * @return dependency builder
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/DependencyService.java b/src/main/java/org/opencord/cordvtn/api/DependencyService.java
index 48905da..08ad58d 100644
--- a/src/main/java/org/opencord/cordvtn/api/DependencyService.java
+++ b/src/main/java/org/opencord/cordvtn/api/DependencyService.java
@@ -15,7 +15,7 @@
*/
package org.opencord.cordvtn.api;
-import org.onosproject.xosclient.api.VtnServiceId;
+import org.opencord.cordvtn.api.Dependency.Type;
/**
* Provides dependency services.
@@ -25,17 +25,17 @@
/**
* Creates dependencies for a given tenant service.
*
- * @param tServiceId id of the service which has a dependency
- * @param pServiceId id of the service which provide dependency
- * @param isBidirectional true to enable bidirectional connectivity between two services
+ * @param subscriber subscriber network id
+ * @param provider provider network id
+ * @param type bidirectional access type
*/
- void createDependency(VtnServiceId tServiceId, VtnServiceId pServiceId, boolean isBidirectional);
+ void createDependency(NetworkId subscriber, NetworkId provider, Type type);
/**
* Removes all dependencies from a given tenant service.
*
- * @param tServiceId id of the service which has a dependency
- * @param pServiceId id of the service which provide dependency
+ * @param subscriber subscriber network id
+ * @param provider provider network id
*/
- void removeDependency(VtnServiceId tServiceId, VtnServiceId pServiceId);
+ void removeDependency(NetworkId subscriber, NetworkId provider);
}
diff --git a/src/main/java/org/opencord/cordvtn/api/Instance.java b/src/main/java/org/opencord/cordvtn/api/Instance.java
index 23841b6..d81440e 100644
--- a/src/main/java/org/opencord/cordvtn/api/Instance.java
+++ b/src/main/java/org/opencord/cordvtn/api/Instance.java
@@ -21,21 +21,19 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.PortNumber;
-import org.onosproject.xosclient.api.VtnPortId;
-import org.onosproject.xosclient.api.VtnServiceApi.ServiceType;
-import org.onosproject.xosclient.api.VtnServiceId;
+import org.opencord.cordvtn.api.ServiceNetwork.ServiceNetworkType;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
- * Provides methods to help to handle network service instance.
+ * Provides methods to help to handle network network instance.
*/
public final class Instance {
- public static final String SERVICE_ID = "serviceId";
- public static final String SERVICE_TYPE = "serviceType";
- public static final String PORT_ID = "vtnPortId";
+ public static final String NETWORK_ID = "networkId";
+ public static final String NETWORK_TYPE = "networkType";
+ public static final String PORT_ID = "portId";
public static final String CREATE_TIME = "createTime";
public static final String NESTED_INSTANCE = "nestedInstance";
public static final String TRUE = "true";
@@ -68,8 +66,8 @@
*/
public static Instance of(Host host) {
checkNotNull(host);
- checkArgument(!Strings.isNullOrEmpty(host.annotations().value(SERVICE_ID)));
- checkArgument(!Strings.isNullOrEmpty(host.annotations().value(SERVICE_TYPE)));
+ checkArgument(!Strings.isNullOrEmpty(host.annotations().value(NETWORK_ID)));
+ checkArgument(!Strings.isNullOrEmpty(host.annotations().value(NETWORK_TYPE)));
checkArgument(!Strings.isNullOrEmpty(host.annotations().value(PORT_ID)));
checkArgument(!Strings.isNullOrEmpty(host.annotations().value(CREATE_TIME)));
@@ -77,33 +75,33 @@
}
/**
- * Returns service ID of a given host.
+ * Returns network ID of a given host.
*
- * @return vtn service id
+ * @return network id
*/
- public VtnServiceId serviceId() {
- String serviceId = host.annotations().value(SERVICE_ID);
- return VtnServiceId.of(serviceId);
+ public NetworkId netId() {
+ String netId = host.annotations().value(NETWORK_ID);
+ return NetworkId.of(netId);
}
/**
- * Returns service type of a given host.
+ * Returns network type of a given host.
*
- * @return vtn service type
+ * @return network type
*/
- public ServiceType serviceType() {
- String serviceType = host.annotations().value(SERVICE_TYPE);
- return ServiceType.valueOf(serviceType);
+ public ServiceNetworkType netType() {
+ String netType = host.annotations().value(NETWORK_TYPE);
+ return ServiceNetworkType.valueOf(netType);
}
/**
* Returns port ID of a given host.
*
- * @return vtn port id
+ * @return port id
*/
- public VtnPortId portId() {
+ public PortId portId() {
String portId = host.annotations().value(PORT_ID);
- return VtnPortId.of(portId);
+ return PortId.of(portId);
}
/**
diff --git a/src/main/java/org/opencord/cordvtn/api/InstanceHandler.java b/src/main/java/org/opencord/cordvtn/api/InstanceHandler.java
index ea44857..a2364fd 100644
--- a/src/main/java/org/opencord/cordvtn/api/InstanceHandler.java
+++ b/src/main/java/org/opencord/cordvtn/api/InstanceHandler.java
@@ -28,6 +28,13 @@
void instanceDetected(Instance instance);
/**
+ * Handles updated instance.
+ *
+ * @param instance instance
+ */
+ void instanceUpdated(Instance instance);
+
+ /**
* Handles removed instance.
*
* @param instance instance
diff --git a/src/main/java/org/opencord/cordvtn/api/InstanceService.java b/src/main/java/org/opencord/cordvtn/api/InstanceService.java
index a8e0f77..add968f 100644
--- a/src/main/java/org/opencord/cordvtn/api/InstanceService.java
+++ b/src/main/java/org/opencord/cordvtn/api/InstanceService.java
@@ -25,7 +25,8 @@
public interface InstanceService {
/**
- * Adds a service instance on a given connect point.
+ * Adds a service instance on a given connect point. Or updates if the
+ * instance already exists.
*
* @param connectPoint connect point of the instance
*/
diff --git a/src/main/java/org/opencord/cordvtn/api/ProviderNetwork.java b/src/main/java/org/opencord/cordvtn/api/ProviderNetwork.java
new file mode 100644
index 0000000..9caabbd
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/ProviderNetwork.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import com.google.common.base.MoreObjects;
+import org.opencord.cordvtn.api.Dependency.Type;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a provider network.
+ */
+public final class ProviderNetwork {
+
+ private final NetworkId id;
+ private final Type type;
+
+ private ProviderNetwork(NetworkId id, Type type) {
+ this.id = id;
+ this.type = type;
+ }
+
+ /**
+ * Returns network id.
+ *
+ * @return network id
+ */
+ public NetworkId id() {
+ return id;
+ }
+
+ /**
+ * Returns the direct access type with this provider network.
+ *
+ * @return direct access type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns immutable provider network with the supplied network id and type.
+ *
+ * @param id network id
+ * @param type direct access type
+ * @return provider network
+ */
+ public static ProviderNetwork of(NetworkId id, Type type) {
+ checkNotNull(id);
+ checkNotNull(type);
+ return new ProviderNetwork(id, type);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof ProviderNetwork) {
+ ProviderNetwork that = (ProviderNetwork) obj;
+ if (Objects.equals(id, that.id) &&
+ Objects.equals(type, that.type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, type);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("id", id)
+ .add("type", type)
+ .toString();
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/SegmentId.java b/src/main/java/org/opencord/cordvtn/api/SegmentId.java
new file mode 100644
index 0000000..e4101b3
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/SegmentId.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of the network segmentation identifier.
+ */
+public final class SegmentId extends Identifier<Long> {
+
+ /**
+ * Default constructor.
+ *
+ * @param id long segmentation identifier
+ */
+ private SegmentId(Long id) {
+ super(id);
+ }
+
+ /**
+ * Returns the segmentation identifier with the supplied value.
+ *
+ * @param id long segmentation identifier
+ * @return segmentation identifier
+ */
+ public static SegmentId of(Long id) {
+ return new SegmentId(id);
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java b/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java
index bc639da..6da6833 100644
--- a/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java
+++ b/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java
@@ -16,18 +16,20 @@
package org.opencord.cordvtn.api;
import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
+import com.google.common.collect.ImmutableSet;
-import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of a service network.
*/
-public final class ServiceNetwork {
+public class ServiceNetwork {
+
+ private static final String ERR_ID = "Service network ID cannot be null";
+ private static final String ERR_TYPE = "Service network type cannot be null";
public enum ServiceNetworkType {
PRIVATE,
@@ -38,21 +40,16 @@
ACCESS_AGENT
}
- public enum DirectAccessType {
- BIDIRECTIONAL,
- UNIDIRECTIONAL
- }
+ protected final NetworkId id;
+ protected final ServiceNetworkType type;
+ protected final Set<ProviderNetwork> providers;
- private final NetworkId id;
- private final ServiceNetworkType type;
- private final Map<NetworkId, DirectAccessType> providers;
-
- private ServiceNetwork(NetworkId id,
- ServiceNetworkType type,
- Map<NetworkId, DirectAccessType> providers) {
- this.id = id;
- this.type = type;
- this.providers = providers;
+ public ServiceNetwork(NetworkId id,
+ ServiceNetworkType type,
+ Set<ProviderNetwork> providers) {
+ this.id = checkNotNull(id, ERR_ID);
+ this.type = checkNotNull(type, ERR_TYPE);
+ this.providers = providers == null ? ImmutableSet.of() : providers;
}
/**
@@ -78,10 +75,21 @@
*
* @return provider networks
*/
- public Map<NetworkId, DirectAccessType> providers() {
+ public Set<ProviderNetwork> providers() {
return providers;
}
+ /**
+ * Returns if the given network is the provider of this network or not.
+ *
+ * @param netId network id
+ * @return true if the given network is the provider of this network
+ */
+ public boolean isProvider(NetworkId netId) {
+ return providers.stream().filter(p -> Objects.equals(p.id(), netId))
+ .findAny().isPresent();
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -112,86 +120,4 @@
.add("providers", providers)
.toString();
}
-
- /**
- * Returns new service network builder instance.
- *
- * @return service network builder
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Builder of the service network entities.
- */
- public static final class Builder {
- private NetworkId id;
- private ServiceNetworkType type;
- private Map<NetworkId, DirectAccessType> providers = Maps.newHashMap();
-
- private Builder() {
- }
-
- /**
- * Builds an immutable service network.
- *
- * @return service network instance
- */
- public ServiceNetwork build() {
- checkNotNull(id, "Service network id cannot be null");
- checkNotNull(type, "Service network type cannot be null");
- providers = providers == null ? ImmutableMap.of() : providers;
-
- return new ServiceNetwork(id, type, providers);
- }
-
- /**
- * Returns service network builder with the supplied network ID.
- *
- * @param id network id
- * @return service network builder
- */
- public Builder id(NetworkId id) {
- this.id = id;
- return this;
- }
-
- /**
- * Returns service network builder with the supplied service network type.
- *
- * @param type service network type
- * @return service network builder
- */
- public Builder type(ServiceNetworkType type) {
- this.type = type;
- return this;
- }
-
- /**
- * Returns service network builder with the supplied provider service networks.
- *
- * @param providers provider service networks
- * @return service network builder
- */
- public Builder providers(Map<NetworkId, DirectAccessType> providers) {
- this.providers = providers;
- return this;
- }
-
- /**
- * Returns service network builder with the given additional provider network.
- *
- * @param id provider network id
- * @param type direct access type to the provider network
- * @return service network builder
- */
- public Builder addProvider(NetworkId id, DirectAccessType type) {
- checkNotNull(id, "Provider network ID cannot be null");
- checkNotNull(type, "Provider network type cannot be null");
-
- this.providers.put(id, type);
- return this;
- }
- }
}
diff --git a/src/main/java/org/opencord/cordvtn/api/ServicePort.java b/src/main/java/org/opencord/cordvtn/api/ServicePort.java
index 61b0e52..3ed18ee 100644
--- a/src/main/java/org/opencord/cordvtn/api/ServicePort.java
+++ b/src/main/java/org/opencord/cordvtn/api/ServicePort.java
@@ -17,7 +17,6 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
import org.onlab.packet.VlanId;
import java.util.Objects;
@@ -29,18 +28,20 @@
/**
* Representation of a service port.
*/
-public final class ServicePort {
+public class ServicePort {
- private final PortId id;
- private final VlanId vlanId;
- private final Set<AddressPair> addressPairs;
+ private static final String ERR_ID = "Service port ID cannot be null";
- private ServicePort(PortId id,
- VlanId vlanId,
- Set<AddressPair> addressPairs) {
- this.id = id;
+ protected final PortId id;
+ protected final VlanId vlanId;
+ protected final Set<AddressPair> addressPairs;
+
+ public ServicePort(PortId id,
+ VlanId vlanId,
+ Set<AddressPair> addressPairs) {
+ this.id = checkNotNull(id, ERR_ID);
this.vlanId = vlanId;
- this.addressPairs = addressPairs;
+ this.addressPairs = addressPairs == null ? ImmutableSet.of() : addressPairs;
}
/**
@@ -100,83 +101,4 @@
.add("addressPairs", addressPairs)
.toString();
}
-
- /**
- * Returns new service port builder instance.
- *
- * @return service port builder
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Builder of the service port entities.
- */
- public static final class Builder {
- private PortId id;
- private VlanId vlanId;
- private Set<AddressPair> addressPairs = Sets.newHashSet();
-
- private Builder() {
- }
-
- /**
- * Builds an immutable service port.
- *
- * @return service port instance
- */
- public ServicePort build() {
- checkNotNull(id, "ServicePort port id cannot be null");
- addressPairs = addressPairs == null ? ImmutableSet.of() : addressPairs;
-
- return new ServicePort(id, vlanId, addressPairs);
- }
-
- /**
- * Returns service port builder with the supplied port port id.
- *
- * @param id port id
- * @return service port builder
- */
- public Builder id(PortId id) {
- this.id = id;
- return this;
- }
-
- /**
- * Returns service port builder with the supplied VLAN ID.
- *
- * @param vlanId vlan id
- * @return service port builder
- */
- public Builder vlanId(VlanId vlanId) {
- this.vlanId = vlanId;
- return this;
- }
-
- /**
- * Returns service port builder with the supplied address pairs.
- *
- * @param addressPairs set of address pairs
- * @return service port builder
- */
- public Builder addressPairs(Set<AddressPair> addressPairs) {
- this.addressPairs = addressPairs;
- return this;
- }
-
- /**
- * Returns service port builder with the given additional address pair.
- *
- * @param addressPair address pair to add
- * @return service port builder
- */
- public Builder addAddressPair(AddressPair addressPair) {
- checkNotNull(addressPair, "ServicePort address pair cannot be null");
-
- this.addressPairs.add(addressPair);
- return this;
- }
- }
}
diff --git a/src/main/java/org/opencord/cordvtn/api/SubnetId.java b/src/main/java/org/opencord/cordvtn/api/SubnetId.java
new file mode 100644
index 0000000..e98ebd8
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/SubnetId.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of the subnet identifier.
+ */
+public final class SubnetId extends Identifier<String> {
+
+ /**
+ * Default constructor.
+ *
+ * @param id string subnet identifier
+ */
+ private SubnetId(String id) {
+ super(id);
+ }
+
+ /**
+ * Returns the subnet identifier with the supplied value.
+ *
+ * @param id string subnet identifier
+ * @return subnet identifier
+ */
+ public static SubnetId of(String id) {
+ return new SubnetId(id);
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/VtnNetwork.java b/src/main/java/org/opencord/cordvtn/api/VtnNetwork.java
new file mode 100644
index 0000000..644a939
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/VtnNetwork.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Subnet;
+
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opencord.cordvtn.api.ServiceNetwork.ServiceNetworkType.PRIVATE;
+
+/**
+ * Representation of the network containing all network information consumed by
+ * VTN service.
+ */
+public final class VtnNetwork extends ServiceNetwork {
+
+ private static final String ERR_SEGMENT_ID_MISSING = "VTN network segment ID is missing";
+ private static final String ERR_GATEWAY_IP_MISSING = "VTN subnet gateway IP is missing";
+
+ private final SegmentId segmentId;
+ private final IpPrefix subnet;
+ private final IpAddress serviceIp;
+
+ private VtnNetwork(NetworkId id,
+ SegmentId segmentId,
+ IpPrefix subnet,
+ IpAddress serviceIp,
+ ServiceNetworkType type,
+ Set<ProviderNetwork> providers) {
+ super(id, type, providers);
+ this.segmentId = segmentId;
+ this.subnet = subnet;
+ this.serviceIp = serviceIp;
+ }
+
+ /**
+ * Returns the network ID.
+ *
+ * @return network id
+ */
+ public NetworkId id() {
+ return id;
+ }
+
+ /**
+ * Returns the segment ID of this network.
+ *
+ * @return segment id
+ */
+ public SegmentId segmentId() {
+ return segmentId;
+ }
+
+ /**
+ * Returns the subnet used in this network.
+ *
+ * @return subnet
+ */
+ public IpPrefix subnet() {
+ return subnet;
+ }
+
+ /**
+ * Returns the service IP address of this network.
+ *
+ * @return ip address
+ */
+ public IpAddress serviceIp() {
+ return serviceIp;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof VtnNetwork) {
+ VtnNetwork that = (VtnNetwork) obj;
+ if (Objects.equals(id, that.id) &&
+ Objects.equals(segmentId, that.segmentId) &&
+ Objects.equals(subnet, that.subnet) &&
+ Objects.equals(serviceIp, that.serviceIp) &&
+ Objects.equals(type, that.type) &&
+ Objects.equals(providers, that.providers)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, segmentId, subnet, serviceIp, type, providers);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("id", id)
+ .add("segmentId", segmentId)
+ .add("subnet", subnet)
+ .add("serviceIp", serviceIp)
+ .add("type", type)
+ .add("providers", providers)
+ .toString();
+ }
+
+ /**
+ * Returns immutable VTN network with the supplied Neutron network, subnet,
+ * and additional service network information.
+ *
+ * @param network neutron network
+ * @param subnet neutron subnet
+ * @param serviceNet service network
+ * @return vtn network
+ */
+ public static VtnNetwork of(Network network, Subnet subnet, ServiceNetwork serviceNet) {
+ validateNeutronNetwork(network, subnet);
+ if (serviceNet != null) {
+ checkArgument(Objects.equals(network.getId(), serviceNet.id().id()));
+ }
+
+ return builder().id(NetworkId.of(network.getId()))
+ .segmentId(SegmentId.of(Long.valueOf(network.getProviderSegID())))
+ .subnet(IpPrefix.valueOf(subnet.getCidr()))
+ .serviceIp(IpAddress.valueOf(subnet.getGateway()))
+ .type(serviceNet == null ? PRIVATE : serviceNet.type())
+ .providers(serviceNet == null ? ImmutableSet.of() : serviceNet.providers())
+ .build();
+ }
+
+ private static void validateNeutronNetwork(Network network, Subnet subnet) {
+ checkNotNull(network);
+ checkNotNull(subnet);
+ checkArgument(Objects.equals(network.getId(), subnet.getNetworkId()));
+ checkArgument(!Strings.isNullOrEmpty(network.getProviderSegID()), ERR_SEGMENT_ID_MISSING);
+ checkArgument(!Strings.isNullOrEmpty(subnet.getGateway()), ERR_GATEWAY_IP_MISSING);
+ }
+
+ /**
+ * Returns new vtn network builder instance.
+ *
+ * @return vtn network builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Returns new vtn network builder instance with copy of the given vtn network.
+ *
+ * @param vtnNet vtn network
+ * @return vtn network builder
+ */
+ public static Builder builder(VtnNetwork vtnNet) {
+ return new Builder()
+ .id(vtnNet.id())
+ .segmentId(vtnNet.segmentId())
+ .subnet(vtnNet.subnet())
+ .serviceIp(vtnNet.serviceIp())
+ .type(vtnNet.type())
+ .providers(vtnNet.providers());
+ }
+
+ /**
+ * Builder of the vtn network entities.
+ */
+ public static final class Builder {
+ private NetworkId id;
+ private SegmentId segmentId;
+ private IpPrefix subnet;
+ private IpAddress serviceIp;
+ private ServiceNetworkType type;
+ private Set<ProviderNetwork> providers = ImmutableSet.of();
+
+ private Builder() {
+ }
+
+ /**
+ * Builds an immutable vtn network.
+ *
+ * @return vtn network instance
+ */
+ public VtnNetwork build() {
+ checkNotNull(id, "VTN network id cannot be null");
+ checkNotNull(segmentId, "VTN network segment id cannot be null");
+ checkNotNull(subnet, "VTN network subnet cannot be null");
+ checkNotNull(serviceIp, "VTN network service IP cannot be null");
+ checkNotNull(type, "VTN network type cannot be null");
+ providers = providers == null ? ImmutableSet.of() : providers;
+
+ return new VtnNetwork(id, segmentId, subnet, serviceIp, type, providers);
+ }
+
+ /**
+ * Returns vtn network builder with the supplied network ID.
+ *
+ * @param id network id
+ * @return vtn network builder
+ */
+ public Builder id(NetworkId id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder with the supplied segment ID.
+ *
+ * @param segmentId segment id
+ * @return vtn network builder
+ */
+ public Builder segmentId(SegmentId segmentId) {
+ this.segmentId = segmentId;
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder with the supplied subnet.
+ *
+ * @param subnet subnet
+ * @return vtn network builder
+ */
+ public Builder subnet(IpPrefix subnet) {
+ this.subnet = subnet;
+ return this;
+ }
+
+ /**
+ * Returns vtn network service IP address.
+ *
+ * @param serviceIp service ip address
+ * @return vtn network builder
+ */
+ public Builder serviceIp(IpAddress serviceIp) {
+ this.serviceIp = serviceIp;
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder with the supplied service network type.
+ *
+ * @param type service network type
+ * @return vtn network builder
+ */
+ public Builder type(ServiceNetworkType type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder with the supplied provider service networks.
+ *
+ * @param providers provider service networks
+ * @return vtn network builder
+ */
+ public Builder providers(Set<ProviderNetwork> providers) {
+ this.providers = providers;
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder with the given additional provider network.
+ *
+ * @param providerId provider network id
+ * @param type direct access type to the provider network
+ * @return vtn network builder
+ */
+ public Builder addProvider(NetworkId providerId, Dependency.Type type) {
+ checkNotNull(providerId, "Provider network ID cannot be null");
+ checkNotNull(type, "Provider network type cannot be null");
+
+ Set<ProviderNetwork> updated = Sets.newHashSet(this.providers);
+ updated.add(ProviderNetwork.of(providerId, type));
+ this.providers = ImmutableSet.copyOf(updated);
+ return this;
+ }
+
+ /**
+ * Returns vtn network builder without the given provider network.
+ *
+ * @param providerId provider network id
+ * @return vtn network builder
+ */
+ public Builder delProvider(NetworkId providerId) {
+ checkNotNull(providerId, "Provider network ID cannot be null");
+
+ ProviderNetwork provider = this.providers.stream()
+ .filter(p -> Objects.equals(p.id(), providerId))
+ .findAny().orElse(null);
+ if (provider != null) {
+ Set<ProviderNetwork> updated = Sets.newHashSet(this.providers);
+ updated.remove(provider);
+ this.providers = ImmutableSet.copyOf(updated);
+ }
+ return this;
+ }
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/VtnNetworkEvent.java b/src/main/java/org/opencord/cordvtn/api/VtnNetworkEvent.java
new file mode 100644
index 0000000..c1d6fef
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/VtnNetworkEvent.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.joda.time.LocalDateTime;
+import org.onosproject.event.AbstractEvent;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Describes vtn network event.
+ */
+public class VtnNetworkEvent extends AbstractEvent<VtnNetworkEvent.Type, VtnNetwork> {
+
+ private final VtnPort vtnPort;
+
+ /**
+ * Type of vtn network event.
+ */
+ public enum Type {
+ /**
+ * Signifies that a new vtn network has been created.
+ */
+ VTN_NETWORK_CREATED,
+
+ /**
+ * Signifies that some vtn network attributes have changed.
+ */
+ VTN_NETWORK_UPDATED,
+
+ /**
+ * Signifies that a vtn network has been removed.
+ */
+ VTN_NETWORK_REMOVED,
+
+ /**
+ * Signifies that a new vtn port has been created.
+ */
+ VTN_PORT_CREATED,
+
+ /**
+ * Signifies that some vtn port attributes have changed.
+ */
+ VTN_PORT_UPDATED,
+
+ /**
+ * Signifies that a vtn port has been removed.
+ */
+ VTN_PORT_REMOVED
+ }
+
+ /**
+ * Creates an event of a given type and for the specified vtn network and
+ * the current time.
+ *
+ * @param type vtn network event type
+ * @param vtnNet vtn network subject
+ */
+ public VtnNetworkEvent(Type type, VtnNetwork vtnNet) {
+ super(type, vtnNet);
+ this.vtnPort = null;
+ }
+
+ /**
+ * Creates an event of a given type and for the specified vtn network,
+ * port and the current time.
+ *
+ * @param type vtn network event type
+ * @param vtnNet vtn network subject
+ * @param vtnPort optional vtn port subject
+ */
+ public VtnNetworkEvent(Type type, VtnNetwork vtnNet, VtnPort vtnPort) {
+ super(type, vtnNet);
+ this.vtnPort = vtnPort;
+ }
+
+ /**
+ * Returns the vtn port subject.
+ * It returns valid value only with the vtn port events.
+ *
+ * @return vtn port or null if the event is not vtn port specific
+ */
+ public VtnPort vtnPort() {
+ return vtnPort;
+ }
+
+ @Override
+ public String toString() {
+ if (vtnPort == null) {
+ return super.toString();
+ }
+ return toStringHelper(this)
+ .add("time", new LocalDateTime(time()))
+ .add("type", type())
+ .add("vtnNet", subject())
+ .add("vtnPort", vtnPort)
+ .toString();
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/VtnNetworkListener.java b/src/main/java/org/opencord/cordvtn/api/VtnNetworkListener.java
new file mode 100644
index 0000000..be78ef0
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/VtnNetworkListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for vtn network event.
+ */
+public interface VtnNetworkListener extends EventListener<VtnNetworkEvent> {
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/VtnPort.java b/src/main/java/org/opencord/cordvtn/api/VtnPort.java
new file mode 100644
index 0000000..a7d8385
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/VtnPort.java
@@ -0,0 +1,296 @@
+/*
+ * Copyright 2016-present 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.opencord.cordvtn.api;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.openstack4j.model.network.Port;
+
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of the port containing all port information consumed by VTN service.
+ */
+public final class VtnPort extends ServicePort {
+
+ private static final String ERR_IP_MISSING = "VTN port IP adderess is missing";
+
+ private final NetworkId netId;
+ private final MacAddress mac;
+ private final IpAddress ip;
+
+ private VtnPort(PortId id,
+ NetworkId netId,
+ MacAddress mac,
+ IpAddress ip,
+ VlanId vlanId,
+ Set<AddressPair> addressPairs) {
+ super(id, vlanId, addressPairs);
+ this.netId = netId;
+ this.mac = mac;
+ this.ip = ip;
+ }
+
+ /**
+ * Returns the network ID of this port.
+ *
+ * @return network id
+ */
+ public NetworkId netId() {
+ return netId;
+ }
+
+ /**
+ * Returns the MAC address of this port.
+ *
+ * @return mac address
+ */
+ public MacAddress mac() {
+ return mac;
+ }
+
+ /**
+ * Returns the IP address of this port.
+ *
+ * @return ip address
+ */
+ public IpAddress ip() {
+ return ip;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof VtnPort) {
+ VtnPort that = (VtnPort) obj;
+ if (Objects.equals(id, that.id) &&
+ Objects.equals(netId, that.netId) &&
+ Objects.equals(mac, that.mac) &&
+ Objects.equals(ip, that.ip) &&
+ Objects.equals(vlanId, that.vlanId) &&
+ Objects.equals(addressPairs, that.addressPairs)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, netId, mac, ip, vlanId, addressPairs);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("id", id)
+ .add("netId", netId)
+ .add("mac", mac)
+ .add("ip", ip)
+ .add("vlanId", vlanId)
+ .add("addressPairs", addressPairs)
+ .toString();
+ }
+
+ /**
+ * Returns the immutable VTN port with the supplied Neutron port with additional
+ * vtn port information.
+ *
+ * @param port neutron port
+ * @param servicePort vtn port
+ * @return vtn port
+ */
+ public static VtnPort of(Port port, ServicePort servicePort) {
+ validateNeutronPort(port);
+ if (servicePort != null) {
+ checkArgument(Objects.equals(port.getId(), servicePort.id().id()));
+ }
+
+ return builder().id(PortId.of(port.getId()))
+ .netId(NetworkId.of(port.getNetworkId()))
+ .mac(MacAddress.valueOf(port.getMacAddress()))
+ .ip(IpAddress.valueOf(port.getFixedIps().iterator().next().getIpAddress()))
+ .vlanId(servicePort == null ? null : servicePort.vlanId().orElse(null))
+ .addressPairs(servicePort == null ? ImmutableSet.of() : servicePort.addressPairs())
+ .build();
+ }
+
+ private static void validateNeutronPort(Port port) {
+ checkNotNull(port);
+ checkArgument(port.getFixedIps().size() > 0, ERR_IP_MISSING);
+ }
+
+ /**
+ * Returns the immutable VTN port with the supplied VTN port with additional
+ * vtn port information.
+ *
+ * @param vtnPort vtn port
+ * @param servicePort vtn port
+ * @return vtn port
+ */
+ public static VtnPort of(VtnPort vtnPort, ServicePort servicePort) {
+ return builder(vtnPort)
+ .vlanId(servicePort.vlanId().orElse(null))
+ .addressPairs(servicePort.addressPairs())
+ .build();
+ }
+
+ /**
+ * Returns new vtn port builder instance.
+ *
+ * @return vtn port builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Returns new vtn port builder instance with copy of the supplied vtn port.
+ *
+ * @param vtnPort vtn port
+ * @return vtn port builder
+ */
+ public static Builder builder(VtnPort vtnPort) {
+ return new Builder().id(vtnPort.id())
+ .netId(vtnPort.netId())
+ .mac(vtnPort.mac())
+ .ip(vtnPort.ip())
+ .vlanId(vtnPort.vlanId().orElse(null))
+ .addressPairs(vtnPort.addressPairs());
+ }
+
+ /**
+ * Builder of the vtn port entities.
+ */
+ public static final class Builder {
+ private PortId id;
+ private NetworkId netId;
+ private MacAddress mac;
+ private IpAddress ip;
+ private VlanId vlanId;
+ private Set<AddressPair> addressPairs = ImmutableSet.of();
+
+ private Builder() {
+ }
+
+ /**
+ * Builds an immutable vtn port.
+ *
+ * @return vtn port instance
+ */
+ public VtnPort build() {
+ checkNotNull(id, "VtnPort port id cannot be null");
+ checkNotNull(netId, "VtnPort network id cannot be null");
+ checkNotNull(mac, "VtnPort mac address cannot be null");
+ checkNotNull(ip, "VtnPort ip address cannot be null");
+ addressPairs = addressPairs == null ? ImmutableSet.of() : addressPairs;
+
+ return new VtnPort(id, netId, mac, ip, vlanId, addressPairs);
+ }
+
+ /**
+ * Returns vtn port builder with the supplied port id.
+ *
+ * @param id port id
+ * @return vtn port builder
+ */
+ public Builder id(PortId id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the supplied network id.
+ *
+ * @param netId network id
+ * @return vtn port builder
+ */
+ public Builder netId(NetworkId netId) {
+ this.netId = netId;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the supplied mac address.
+ *
+ * @param mac mac address
+ * @return vtn port builder
+ */
+ public Builder mac(MacAddress mac) {
+ this.mac = mac;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the supplied ip address.
+ *
+ * @param ip ip address
+ * @return vtn port builder
+ */
+ public Builder ip(IpAddress ip) {
+ this.ip = ip;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the supplied VLAN ID.
+ *
+ * @param vlanId vlan id
+ * @return vtn port builder
+ */
+ public Builder vlanId(VlanId vlanId) {
+ this.vlanId = vlanId;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the supplied address pairs.
+ *
+ * @param addressPairs set of address pairs
+ * @return vtn port builder
+ */
+ public Builder addressPairs(Set<AddressPair> addressPairs) {
+ this.addressPairs = addressPairs;
+ return this;
+ }
+
+ /**
+ * Returns vtn port builder with the given additional address pair.
+ *
+ * @param addressPair address pair to add
+ * @return vtn port builder
+ */
+ public Builder addAddressPair(AddressPair addressPair) {
+ checkNotNull(addressPair, "VtnPort address pair cannot be null");
+
+ Set<AddressPair> updated = Sets.newHashSet(this.addressPairs);
+ updated.add(addressPair);
+ this.addressPairs = ImmutableSet.copyOf(updated);
+ return this;
+ }
+ }
+}