CORD-176 Added new classes for the VTN service network and port
Change-Id: Ia26522712d02ef8da698f254cf00a53eaa92f666
diff --git a/src/main/java/org/opencord/cordvtn/api/AddressPair.java b/src/main/java/org/opencord/cordvtn/api/AddressPair.java
new file mode 100644
index 0000000..03ad60f
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/AddressPair.java
@@ -0,0 +1,98 @@
+/*
+ * 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.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of the IP and MAC address pair.
+ */
+public final class AddressPair {
+
+ private final IpAddress ip;
+ private final MacAddress mac;
+
+ private AddressPair(IpAddress ip, MacAddress mac) {
+ this.ip = ip;
+ this.mac = mac;
+ }
+
+ /**
+ * Returns the IP address.
+ *
+ * @return ip address
+ */
+ public IpAddress ip() {
+ return ip;
+ }
+
+ /**
+ * Returns the MAC address.
+ *
+ * @return mac address
+ */
+ public MacAddress mac() {
+ return mac;
+ }
+
+ /**
+ * Returns an address pair instance with the given ip and mac address.
+ *
+ * @param ip ip address
+ * @param mac mac address
+ * @return address pair
+ */
+ public static AddressPair of(IpAddress ip, MacAddress mac) {
+ checkNotNull(ip, "AddressPair IP cannot be null");
+ checkNotNull(mac, "AddressPair MAC cannot be null");
+
+ return new AddressPair(ip, mac);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof AddressPair) {
+ AddressPair that = (AddressPair) obj;
+ if (Objects.equals(ip, that.ip) && Objects.equals(mac, that.mac)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip, mac);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("ip", ip)
+ .add("mac", mac)
+ .toString();
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/NetworkId.java b/src/main/java/org/opencord/cordvtn/api/NetworkId.java
new file mode 100644
index 0000000..843be7e
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/NetworkId.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 identifier.
+ */
+public final class NetworkId extends Identifier<String> {
+
+ /**
+ * Default constructor.
+ *
+ * @param id string network identifier
+ */
+ private NetworkId(String id) {
+ super(id);
+ }
+
+ /**
+ * Returns the network identifier with the supplied value.
+ *
+ * @param id string network identifier
+ * @return network identifier
+ */
+ public static NetworkId of(String id) {
+ return new NetworkId(id);
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/PortId.java b/src/main/java/org/opencord/cordvtn/api/PortId.java
new file mode 100644
index 0000000..6162070
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/PortId.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 port identifier.
+ */
+public final class PortId extends Identifier<String> {
+
+ /**
+ * Default constructor.
+ *
+ * @param id string port identifier
+ */
+ private PortId(String id) {
+ super(id);
+ }
+
+ /**
+ * Returns the port identifier with the supplied value.
+ *
+ * @param id string port identifier
+ * @return port identifier
+ */
+ public static PortId of(String id) {
+ return new PortId(id);
+ }
+}
diff --git a/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java b/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java
new file mode 100644
index 0000000..bc639da
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/ServiceNetwork.java
@@ -0,0 +1,197 @@
+/*
+ * 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.ImmutableMap;
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a service network.
+ */
+public final class ServiceNetwork {
+
+ public enum ServiceNetworkType {
+ PRIVATE,
+ PUBLIC,
+ MANAGEMENT_HOST,
+ MANAGEMENT_LOCAL,
+ VSG,
+ ACCESS_AGENT
+ }
+
+ public enum DirectAccessType {
+ BIDIRECTIONAL,
+ UNIDIRECTIONAL
+ }
+
+ 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;
+ }
+
+ /**
+ * Returns the network id of the service network.
+ *
+ * @return network id
+ */
+ public NetworkId id() {
+ return id;
+ }
+
+ /**
+ * Returns the type of the service network.
+ *
+ * @return service network type
+ */
+ public ServiceNetworkType type() {
+ return type;
+ }
+
+ /**
+ * Returns the provider networks of this service network if exists.
+ *
+ * @return provider networks
+ */
+ public Map<NetworkId, DirectAccessType> providers() {
+ return providers;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof ServiceNetwork) {
+ ServiceNetwork that = (ServiceNetwork) obj;
+ if (Objects.equals(id, that.id) &&
+ Objects.equals(type, that.type) &&
+ Objects.equals(providers, that.providers)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, type, providers);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("networkId", id)
+ .add("type", type)
+ .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
new file mode 100644
index 0000000..61b0e52
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/api/ServicePort.java
@@ -0,0 +1,182 @@
+/*
+ * 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.VlanId;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a service port.
+ */
+public final class ServicePort {
+
+ private final PortId id;
+ private final VlanId vlanId;
+ private final Set<AddressPair> addressPairs;
+
+ private ServicePort(PortId id,
+ VlanId vlanId,
+ Set<AddressPair> addressPairs) {
+ this.id = id;
+ this.vlanId = vlanId;
+ this.addressPairs = addressPairs;
+ }
+
+ /**
+ * Returns the port id of the service port.
+ *
+ * @return port id
+ */
+ public PortId id() {
+ return id;
+ }
+
+ /**
+ * Returns the vlan id of the the service port if exists.
+ *
+ * @return vlan id
+ */
+ public Optional<VlanId> vlanId() {
+ return Optional.ofNullable(vlanId);
+ }
+
+ /**
+ * Returns the additional address pairs used in this port.
+ *
+ * @return set of ip and mac address pairs
+ */
+ public Set<AddressPair> addressPairs() {
+ return addressPairs;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof ServicePort) {
+ ServicePort that = (ServicePort) obj;
+ if (Objects.equals(id, that.id) &&
+ Objects.equals(vlanId, that.vlanId) &&
+ Objects.equals(addressPairs, that.addressPairs)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, vlanId, addressPairs);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("portId", id)
+ .add("vlanId", vlanId)
+ .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;
+ }
+ }
+}