Add unit test for simple fabric default classes
Change-Id: I47e88a5819833effe92b4e802a7ecaf001e6a6c2
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
deleted file mode 100644
index 7b92a93..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * 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.simplefabric.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 org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.EncapsulationType;
-import org.onosproject.net.Host;
-import org.onosproject.net.HostId;
-import org.onosproject.net.intf.Interface;
-
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.onosproject.simplefabric.api.Constants.ALLOW_ETH_ADDRESS_SELECTOR;
-
-
-/**
- * Class stores a DefaultFabricNetwork information.
- */
-public final class DefaultFabricNetwork implements FabricNetwork {
-
- private static final String NOT_NULL_MSG = "FabricNetwork % cannot be null";
-
- private final String name;
- private final Set<String> interfaceNames;
- private final EncapsulationType encapsulation;
- private boolean forward;
- private boolean broadcast;
-
- /* status variables */
- private final Set<Interface> interfaces;
- private final Set<HostId> hostIds;
- private boolean dirty;
-
- /**
- * Constructs a DefaultFabricNetwork instance.
- *
- * @param name fabric name name
- * @param interfaceNames a collection of interface names
- * @param encapsulation encapsulation type
- * @param forward flag for forward intents to be installed or not
- * @param broadcast flag for broadcast intents to be installed or not
- */
- private DefaultFabricNetwork(String name, Collection<String> interfaceNames,
- EncapsulationType encapsulation,
- boolean forward, boolean broadcast) {
- this.name = name;
- this.interfaceNames = Sets.newHashSet();
-
- if (interfaceNames != null) {
- this.interfaceNames.addAll(interfaceNames);
- }
-
- this.encapsulation = encapsulation;
- this.forward = (ALLOW_ETH_ADDRESS_SELECTOR) && forward;
- this.broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) && broadcast;
- this.interfaces = Sets.newHashSet();
- this.hostIds = Sets.newHashSet();
- this.dirty = false;
- }
-
- /**
- * Constructs a DefaultFabricNetwork instance.
- *
- * @param name fabric network name
- * @param encapsulation encapsulation type
- */
- private DefaultFabricNetwork(String name, EncapsulationType encapsulation) {
- this.name = name;
- this.interfaceNames = Sets.newHashSet();
- this.encapsulation = encapsulation;
- this.forward = ALLOW_ETH_ADDRESS_SELECTOR;
- this.broadcast = ALLOW_ETH_ADDRESS_SELECTOR;
- this.interfaces = Sets.newHashSet();
- this.hostIds = Sets.newHashSet();
- this.dirty = false;
- }
-
- /**
- * Creates a DefaultFabricNetwork data by given name.
- * The encapsulation type of the DefaultFabricNetwork will be NONE.
- *
- * @param name fabric network name
- * @return DefaultFabricNetwork instance
- */
- public static FabricNetwork of(String name) {
- Objects.requireNonNull(name);
- return new DefaultFabricNetwork(name, EncapsulationType.NONE);
- }
-
- /**
- * Creates a copy of DefaultFabricNetwork instance.
- *
- * @param fabricNetwork DefaultFabricNetwork instance
- * @return the copy of the DefaultFabricNetwork instance
- */
- public static FabricNetwork of(FabricNetwork fabricNetwork) {
- Objects.requireNonNull(fabricNetwork);
- DefaultFabricNetwork fabricNetworkCopy =
- new DefaultFabricNetwork(fabricNetwork.name(), fabricNetwork.encapsulation());
- fabricNetworkCopy.interfaceNames.addAll(fabricNetwork.interfaceNames());
- fabricNetworkCopy.forward = (ALLOW_ETH_ADDRESS_SELECTOR) && fabricNetwork.isForward();
- fabricNetworkCopy.broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) && fabricNetwork.isBroadcast();
- fabricNetworkCopy.interfaces.addAll(fabricNetwork.interfaces());
- fabricNetworkCopy.hostIds.addAll(fabricNetwork.hostIds());
- fabricNetworkCopy.setDirty(fabricNetwork.isDirty());
- return fabricNetworkCopy;
- }
-
- // field queries
-
- @Override
- public String name() {
- return name;
- }
-
- @Override
- public Set<String> interfaceNames() {
- return ImmutableSet.copyOf(interfaceNames);
- }
-
- @Override
- public EncapsulationType encapsulation() {
- return encapsulation;
- }
-
- @Override
- public boolean isForward() {
- return forward;
- }
-
- @Override
- public boolean isBroadcast() {
- return broadcast;
- }
-
- @Override
- public Set<Interface> interfaces() {
- return ImmutableSet.copyOf(interfaces);
- }
-
- @Override
- public Set<HostId> hostIds() {
- return ImmutableSet.copyOf(hostIds);
- }
-
- @Override
- public boolean isDirty() {
- return dirty;
- }
-
- @Override
- public boolean contains(Interface iface) {
- return interfaces.contains(iface);
- }
-
- @Override
- public boolean contains(ConnectPoint port, VlanId vlanId) {
- for (Interface iface : interfaces) {
- if (iface.connectPoint().equals(port) && iface.vlan().equals(vlanId)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean contains(DeviceId deviceId) {
- for (Interface iface : interfaces) {
- if (iface.connectPoint().deviceId().equals(deviceId)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void addInterface(Interface iface) {
- Objects.requireNonNull(iface);
- if (interfaces.add(iface)) {
- setDirty(true);
- }
- }
-
- @Override
- public void addHost(Host host) {
- Objects.requireNonNull(host);
- if (hostIds.add(host.id())) {
- setDirty(true);
- }
- }
-
- @Override
- public void setDirty(boolean newDirty) {
- dirty = newDirty;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("name", name)
- .add("interfaceNames", interfaceNames)
- .add("encapsulation", encapsulation)
- .add("forward", forward)
- .add("broadcast", broadcast)
- .add("interfaces", interfaces)
- .add("hostIds", hostIds)
- .add("isDirty", dirty)
- .toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof DefaultFabricNetwork)) {
- return false;
- }
- DefaultFabricNetwork other = (DefaultFabricNetwork) obj;
- return Objects.equals(other.name, this.name)
- && Objects.equals(other.interfaceNames, this.interfaceNames)
- && Objects.equals(other.encapsulation, this.encapsulation)
- && Objects.equals(other.forward, this.forward)
- && Objects.equals(other.broadcast, this.broadcast)
- && Objects.equals(other.interfaces, this.interfaces)
- && Objects.equals(other.hostIds, this.hostIds);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, interfaces, encapsulation, forward, broadcast);
- }
-
- /**
- * Returns new builder instance.
- *
- * @return fabric network builder
- */
- public static DefaultFabricNetworkBuilder builder() {
- return new DefaultFabricNetworkBuilder();
- }
-
- /**
- * A builder class for fabric network.
- */
- public static final class DefaultFabricNetworkBuilder implements Builder {
- private String name;
- private Set<String> interfaceNames;
- private EncapsulationType encapsulation;
- private boolean forward;
- private boolean broadcast;
-
- private DefaultFabricNetworkBuilder() {
- }
-
- @Override
- public Builder name(String name) {
- this.name = name;
- return this;
- }
-
- @Override
- public Builder interfaceNames(Set<String> interfaceNames) {
- this.interfaceNames = interfaceNames;
- return this;
- }
-
- @Override
- public Builder encapsulation(EncapsulationType encapsulation) {
- this.encapsulation = encapsulation;
- return this;
- }
-
- @Override
- public Builder forward(boolean forward) {
- this.forward = forward;
- return this;
- }
-
- @Override
- public Builder broadcast(boolean broadcast) {
- this.broadcast = broadcast;
- return this;
- }
-
- @Override
- public FabricNetwork build() {
- checkArgument(name != null, NOT_NULL_MSG, "name");
- return new DefaultFabricNetwork(name, interfaceNames,
- encapsulation, forward, broadcast);
- }
- }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
deleted file mode 100644
index 8861f9a..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * 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.simplefabric.api;
-
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onosproject.cluster.NodeId;
-
-import java.util.Objects;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Represents a route.
- */
-public final class DefaultFabricRoute implements FabricRoute {
-
- private static final String VERSION_MISMATCH =
- "Prefix and next hop must be in the same address family";
-
- private static final NodeId UNDEFINED = new NodeId("-");
-
- private final Source source;
- private final IpPrefix prefix;
- private final IpAddress nextHop;
- private final NodeId sourceNode;
-
- /**
- * Creates a route.
- *
- * @param source route source
- * @param prefix IP prefix
- * @param nextHop next hop IP address
- */
- private DefaultFabricRoute(Source source, IpPrefix prefix, IpAddress nextHop) {
- this(source, prefix, nextHop, UNDEFINED);
- }
-
- /**
- * Creates a route.
- *
- * @param source route source
- * @param prefix IP prefix
- * @param nextHop next hop IP address
- * @param sourceNode ONOS node the route was sourced from
- */
- private DefaultFabricRoute(Source source, IpPrefix prefix,
- IpAddress nextHop, NodeId sourceNode) {
- this.source = checkNotNull(source);
- this.prefix = prefix;
- this.nextHop = nextHop;
- this.sourceNode = checkNotNull(sourceNode);
- }
-
- @Override
- public Source source() {
- return source;
- }
-
- @Override
- public IpPrefix prefix() {
- return prefix;
- }
-
- @Override
- public IpAddress nextHop() {
- return nextHop;
- }
-
- @Override
- public NodeId sourceNode() {
- return sourceNode;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(prefix, nextHop);
- }
-
- @Override
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
-
- if (!(other instanceof DefaultFabricRoute)) {
- return false;
- }
-
- DefaultFabricRoute that = (DefaultFabricRoute) other;
-
- return Objects.equals(this.prefix, that.prefix) &&
- Objects.equals(this.nextHop, that.nextHop);
- }
-
- @Override
- public String toString() {
- return toStringHelper(this)
- .add("prefix", prefix)
- .add("nextHop", nextHop)
- .toString();
- }
-
- /**
- * Returns new builder instance.
- *
- * @return fabric route builder
- */
- public static DefaultFabricRouteBuilder builder() {
- return new DefaultFabricRouteBuilder();
- }
-
- /**
- * A builder class for fabric route.
- */
- public static final class DefaultFabricRouteBuilder implements Builder {
- private Source source;
- private IpPrefix prefix;
- private IpAddress nextHop;
- private NodeId sourceNode;
-
- private DefaultFabricRouteBuilder() {
- }
-
- @Override
- public Builder source(Source source) {
- this.source = source;
- return this;
- }
-
- @Override
- public Builder prefix(IpPrefix prefix) {
- this.prefix = prefix;
- return this;
- }
-
- @Override
- public Builder nextHop(IpAddress nextHop) {
- this.nextHop = nextHop;
- return this;
- }
-
- @Override
- public Builder sourceNode(NodeId sourceNode) {
- this.sourceNode = sourceNode;
- return this;
- }
-
- @Override
- public FabricRoute build() {
-
- checkNotNull(prefix);
- checkNotNull(nextHop);
- checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
-
- if (sourceNode != null) {
- return new DefaultFabricRoute(source, prefix, nextHop, sourceNode);
- } else {
- return new DefaultFabricRoute(source, prefix, nextHop);
- }
- }
- }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
deleted file mode 100644
index 79b1ed2..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * 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.simplefabric.api;
-
-import com.google.common.base.MoreObjects;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onlab.packet.MacAddress;
-import org.onosproject.net.EncapsulationType;
-
-import java.util.Objects;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Configuration details for an ip subnet entry.
- */
-public final class DefaultFabricSubnet implements FabricSubnet {
-
- private static final String NOT_NULL_MSG = "FabricSubnet % cannot be null";
-
- private final IpPrefix prefix;
- private final IpAddress gatewayIp;
- private final MacAddress gatewayMac;
- private EncapsulationType encapsulation;
- private final String name;
-
- /**
- * Creates a new subnet entry.
- *
- * @param prefix an ip subnet
- * @param gatewayIp IP of the virtual gateway
- * @param gatewayMac MacAddress of the virtual gateway
- * @param encapsulation encapsulation type
- * @param name subnet name
- */
- private DefaultFabricSubnet(IpPrefix prefix, IpAddress gatewayIp,
- MacAddress gatewayMac, EncapsulationType encapsulation,
- String name) {
- this.prefix = prefix;
- this.gatewayIp = gatewayIp;
- this.gatewayMac = gatewayMac;
- this.encapsulation = encapsulation;
- this.name = name;
- }
-
- @Override
- public IpPrefix prefix() {
- return prefix;
- }
-
- @Override
- public IpAddress gatewayIp() {
- return gatewayIp;
- }
-
- @Override
- public MacAddress gatewayMac() {
- return gatewayMac;
- }
-
- @Override
- public EncapsulationType encapsulation() {
- return encapsulation;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- @Override
- public boolean isIp4() {
- return prefix.isIp4();
- }
-
- @Override
- public boolean isIp6() {
- return prefix.isIp6();
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(prefix, gatewayIp, gatewayMac, encapsulation, name);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof DefaultFabricSubnet)) {
- return false;
- }
- DefaultFabricSubnet that = (DefaultFabricSubnet) obj;
- return Objects.equals(this.prefix, that.prefix)
- && Objects.equals(this.gatewayIp, that.gatewayIp)
- && Objects.equals(this.gatewayMac, that.gatewayMac)
- && Objects.equals(this.encapsulation, that.encapsulation)
- && Objects.equals(this.name, that.name);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("prefix", prefix)
- .add("gatewayIp", gatewayIp)
- .add("gatewayMac", gatewayMac)
- .add("encapsulation", encapsulation)
- .add("name", name)
- .toString();
- }
-
- /**
- * Returns new builder instance.
- *
- * @return fabric IP subnet builder
- */
- public static DefaultSubnetBuilder builder() {
- return new DefaultSubnetBuilder();
- }
-
- /**
- * A builder class for Ip Subnet.
- */
- public static final class DefaultSubnetBuilder implements Builder {
- private IpPrefix ipPrefix;
- private IpAddress gatewayIp;
- private MacAddress gatewayMac;
- private EncapsulationType encapsulation;
- private String name;
-
- private DefaultSubnetBuilder() {
- }
-
- @Override
- public Builder ipPrefix(IpPrefix ipPrefix) {
- this.ipPrefix = ipPrefix;
- return this;
- }
-
- @Override
- public Builder gatewayIp(IpAddress gatewayIp) {
- this.gatewayIp = gatewayIp;
- return this;
- }
-
- @Override
- public Builder gatewayMac(MacAddress gatewayMac) {
- this.gatewayMac = gatewayMac;
- return this;
- }
-
- @Override
- public Builder encapsulation(EncapsulationType encapsulation) {
- this.encapsulation = encapsulation;
- return this;
- }
-
- @Override
- public Builder name(String networkName) {
- this.name = networkName;
- return this;
- }
-
- @Override
- public FabricSubnet build() {
- checkArgument(ipPrefix != null, NOT_NULL_MSG, "prefix");
- checkArgument(gatewayIp != null, NOT_NULL_MSG, "gatewayIp");
- checkArgument(gatewayMac != null, NOT_NULL_MSG, "gatewayMac");
- checkArgument(name != null, NOT_NULL_MSG, "name");
-
- if (this.encapsulation == null) {
- encapsulation = EncapsulationType.NONE;
- }
-
- return new DefaultFabricSubnet(ipPrefix, gatewayIp, gatewayMac,
- encapsulation, name);
- }
- }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
index 2e7ba3c..ca56946 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
@@ -55,11 +55,11 @@
EncapsulationType encapsulation();
/**
- * Gets the subnet name.
+ * Gets the network name.
*
- * @return the subnet name
+ * @return the network name
*/
- String name();
+ String networkName();
/**
* Tests whether the IP version of this entry is IPv4.
@@ -86,7 +86,7 @@
* @param ipPrefix IP prefix
* @return FabricSubnet instance builder
*/
- Builder ipPrefix(IpPrefix ipPrefix);
+ Builder prefix(IpPrefix ipPrefix);
/**
* Returns FabricSubnet builder with supplied gatewayIp.
@@ -113,12 +113,12 @@
Builder encapsulation(EncapsulationType encapsulation);
/**
- * Returns FabricSubnet builder with supplied subnet name.
+ * Returns FabricSubnet builder with supplied network name.
*
- * @param name subnet name
+ * @param networkName network name
* @return FabricSubnet instance builder
*/
- Builder name(String name);
+ Builder networkName(String networkName);
/**
* Builds an immutable FabricSubnet instance.