Add unit test for simple fabric default classes
Change-Id: I47e88a5819833effe92b4e802a7ecaf001e6a6c2
diff --git a/apps/simplefabric/app/BUCK b/apps/simplefabric/app/BUCK
index 104aee1..6aefd2c 100644
--- a/apps/simplefabric/app/BUCK
+++ b/apps/simplefabric/app/BUCK
@@ -17,6 +17,7 @@
api_description = 'REST API for Simple Fabric',
api_package = 'org.onosproject.simplefabric.web',
api_title = 'Simple Fabric API',
+ api_version = '1.0',
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
web_context = '/onos/v1/simplefabric',
diff --git a/apps/simplefabric/app/BUILD b/apps/simplefabric/app/BUILD
index 9d93d06..a84652b 100644
--- a/apps/simplefabric/app/BUILD
+++ b/apps/simplefabric/app/BUILD
@@ -3,10 +3,18 @@
"@concurrent_trees//jar",
]
+TEST_DEPS = TEST_ADAPTERS + TEST_REST + [
+ "//core/api:onos-api-tests",
+ "//core/common:onos-core-common-tests",
+ "//web/api:onos-rest-tests",
+]
+
osgi_jar_with_tests(
api_description = "REST API for Simple Fabric",
api_package = "org.onosproject.simplefabric.web",
api_title = "Simple Fabric API",
+ api_version = "1.0",
+ test_deps = TEST_DEPS,
web_context = "/onos/v1/simplefabric",
deps = COMPILE_DEPS,
)
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java
new file mode 100644
index 0000000..386a345
--- /dev/null
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java
@@ -0,0 +1,316 @@
+/*
+ * 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.impl;
+
+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 org.onosproject.simplefabric.api.FabricNetwork;
+
+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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java
new file mode 100644
index 0000000..6b9a132
--- /dev/null
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java
@@ -0,0 +1,180 @@
+/*
+ * 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.impl;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.simplefabric.api.FabricRoute;
+
+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/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java
new file mode 100644
index 0000000..b7fec47
--- /dev/null
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java
@@ -0,0 +1,195 @@
+/*
+ * 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.impl;
+
+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 org.onosproject.simplefabric.api.FabricSubnet;
+
+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 networkName;
+
+ /**
+ * 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 networkName network name
+ */
+ private DefaultFabricSubnet(IpPrefix prefix, IpAddress gatewayIp,
+ MacAddress gatewayMac, EncapsulationType encapsulation,
+ String networkName) {
+ this.prefix = prefix;
+ this.gatewayIp = gatewayIp;
+ this.gatewayMac = gatewayMac;
+ this.encapsulation = encapsulation;
+ this.networkName = networkName;
+ }
+
+ @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 networkName() {
+ return networkName;
+ }
+
+ @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, networkName);
+ }
+
+ @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.networkName, that.networkName);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("prefix", prefix)
+ .add("gatewayIp", gatewayIp)
+ .add("gatewayMac", gatewayMac)
+ .add("encapsulation", encapsulation)
+ .add("networkName", networkName)
+ .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 prefix;
+ private IpAddress gatewayIp;
+ private MacAddress gatewayMac;
+ private EncapsulationType encapsulation;
+ private String networkName;
+
+ private DefaultSubnetBuilder() {
+ }
+
+ @Override
+ public Builder prefix(IpPrefix prefix) {
+ this.prefix = prefix;
+ 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 networkName(String networkName) {
+ this.networkName = networkName;
+ return this;
+ }
+
+ @Override
+ public FabricSubnet build() {
+ checkArgument(prefix != null, NOT_NULL_MSG, "prefix");
+ checkArgument(gatewayIp != null, NOT_NULL_MSG, "gatewayIp");
+ checkArgument(gatewayMac != null, NOT_NULL_MSG, "gatewayMac");
+ checkArgument(networkName != null, NOT_NULL_MSG, "name");
+
+ if (this.encapsulation == null) {
+ encapsulation = EncapsulationType.NONE;
+ }
+
+ return new DefaultFabricSubnet(prefix, gatewayIp, gatewayMac,
+ encapsulation, networkName);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
index 53c33a4..1d4b97c 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
@@ -24,12 +24,9 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.config.Config;
-import org.onosproject.simplefabric.api.DefaultFabricRoute;
-import org.onosproject.simplefabric.api.DefaultFabricSubnet;
-import org.onosproject.simplefabric.api.DefaultFabricNetwork;
+import org.onosproject.simplefabric.api.FabricNetwork;
import org.onosproject.simplefabric.api.FabricRoute;
import org.onosproject.simplefabric.api.FabricSubnet;
-import org.onosproject.simplefabric.api.FabricNetwork;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -128,11 +125,11 @@
}
try {
subnets.add(DefaultFabricSubnet.builder()
- .ipPrefix(IpPrefix.valueOf(jsonNode.get(PREFIX).asText()))
+ .prefix(IpPrefix.valueOf(jsonNode.get(PREFIX).asText()))
.gatewayIp(IpAddress.valueOf(jsonNode.get(GATEWAY_IP).asText()))
.gatewayMac(MacAddress.valueOf(jsonNode.get(GATEWAY_MAC).asText()))
.encapsulation(EncapsulationType.enumFromString(encapsulation))
- .name(jsonNode.get(NETWORK_NAME).asText())
+ .networkName(jsonNode.get(NETWORK_NAME).asText())
.build());
} catch (Exception e) {
log.warn("Fabric subnet parse failed; skip: jsonNode={}", jsonNode);
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
index de87ba1..1bdcacd 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
@@ -64,7 +64,6 @@
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketService;
-import org.onosproject.simplefabric.api.DefaultFabricNetwork;
import org.onosproject.simplefabric.api.FabricNetwork;
import org.onosproject.simplefabric.api.FabricRoute;
import org.onosproject.simplefabric.api.FabricSubnet;
@@ -450,10 +449,10 @@
log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
return false;
}
- FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.name());
+ FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
if (fabricNetwork == null) {
log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}",
- fabricSubnet.name(), ip);
+ fabricSubnet.networkName(), ip);
return false;
}
log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
index 7a03b9d..9eefc03 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
@@ -245,7 +245,7 @@
for (FabricSubnet subnet : simpleFabric.defaultFabricSubnets()) {
newInterceptFlowRules.add(generateInterceptFlowRule(true, device.id(), subnet.prefix()));
// check if this devices has the fabricSubnet, then add ip broadcast flue rule
- FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.name());
+ FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.networkName());
if (fabricNetwork != null && fabricNetwork.contains(device.id())) {
newInterceptFlowRules.add(generateLocalSubnetIpBctFlowRule(device.id(), subnet.prefix(),
fabricNetwork));
@@ -673,7 +673,7 @@
// destination is local subnet ip
if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
// NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
- FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.name());
+ FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
treatmentSrcMac = ethPkt.getSourceMAC();
if (fabricNetwork != null && fabricNetwork.isForward()) {
// NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java
new file mode 100644
index 0000000..57152e7
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.impl;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.simplefabric.api.FabricNetwork;
+
+import java.util.List;
+import java.util.Set;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Unit tests for the default fabric network class.
+ */
+public final class DefaultFabricNetworkTest {
+
+ private static final String NAME_1 = "network1";
+ private static final String NAME_2 = "network2";
+
+ private static final String INTF_NAMES_1_1 = "h11";
+ private static final String INTF_NAMES_1_2 = "h12";
+ private static final String INTF_NAMES_2_1 = "h21";
+ private static final String INTF_NAMES_2_2 = "h22";
+
+ private static final Set<String> INTF_NAME_SET_1 =
+ ImmutableSet.of(INTF_NAMES_1_1, INTF_NAMES_1_2);
+ private static final Set<String> INTF_NAME_SET_2 =
+ ImmutableSet.of(INTF_NAMES_2_1, INTF_NAMES_2_2);
+
+ private static final EncapsulationType ENCAP_TYPE_1 = EncapsulationType.NONE;
+ private static final EncapsulationType ENCAP_TYPE_2 = EncapsulationType.NONE;
+
+ private static final boolean IS_FORWARD_1 = false;
+ private static final boolean IS_FORWARD_2 = true;
+ private static final boolean IS_BROADCAST_1 = false;
+ private static final boolean IS_BROADCAST_2 = true;
+
+ private FabricNetwork fabricNetwork1;
+ private FabricNetwork sameAsFabricNetwork1;
+ private FabricNetwork fabricNetwork2;
+
+ private static Interface createInterface(int index) {
+
+ String name = "INTF_NAME_" + index;
+ ConnectPoint cp = ConnectPoint.fromString("of:0011223344556677/" + index);
+ InterfaceIpAddress intfIp1 = InterfaceIpAddress.valueOf("10.10.10." + index + "/32");
+ InterfaceIpAddress intfIp2 = InterfaceIpAddress.valueOf("20.20.20." + index + "/32");
+ List<InterfaceIpAddress> intfIps = ImmutableList.of(intfIp1, intfIp2);
+ MacAddress mac = MacAddress.valueOf("00:00:00:00:00:00");
+ VlanId vlanId = VlanId.NONE;
+
+ return new Interface(name, cp, intfIps, mac, vlanId);
+ }
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+
+ fabricNetwork1 = DefaultFabricNetwork.builder()
+ .name(NAME_1)
+ .interfaceNames(INTF_NAME_SET_1)
+ .encapsulation(ENCAP_TYPE_1)
+ .forward(IS_FORWARD_1)
+ .broadcast(IS_BROADCAST_1)
+ .build();
+
+ sameAsFabricNetwork1 = DefaultFabricNetwork.builder()
+ .name(NAME_1)
+ .interfaceNames(INTF_NAME_SET_1)
+ .encapsulation(ENCAP_TYPE_1)
+ .forward(IS_FORWARD_1)
+ .broadcast(IS_BROADCAST_1)
+ .build();
+
+ fabricNetwork2 = DefaultFabricNetwork.builder()
+ .name(NAME_2)
+ .interfaceNames(INTF_NAME_SET_2)
+ .encapsulation(ENCAP_TYPE_2)
+ .forward(IS_FORWARD_2)
+ .broadcast(IS_BROADCAST_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(fabricNetwork1, sameAsFabricNetwork1)
+ .addEqualityGroup(fabricNetwork2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ FabricNetwork network = fabricNetwork1;
+
+ assertEquals(network.name(), NAME_1);
+ assertEquals(network.interfaceNames(), INTF_NAME_SET_1);
+ assertEquals(network.encapsulation(), ENCAP_TYPE_1);
+ assertEquals(network.isForward(), IS_FORWARD_1);
+ assertEquals(network.isBroadcast(), IS_BROADCAST_1);
+ }
+}
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java
new file mode 100644
index 0000000..8a39179
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.impl;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.simplefabric.api.FabricRoute;
+import org.onosproject.simplefabric.api.FabricRoute.Source;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Unit tests for the default fabric router.
+ */
+public final class DefaultFabricRouteTest {
+
+ private static final Source SOURCE_1 = Source.STATIC;
+ private static final Source SOURCE_2 = Source.BGP;
+
+ private static final IpPrefix IP_PREFIX_1 = IpPrefix.valueOf("10.10.10.1/32");
+ private static final IpPrefix IP_PREFIX_2 = IpPrefix.valueOf("20.20.20.2/32");
+
+ private static final IpAddress NEXT_HOP_1 = IpAddress.valueOf("10.10.10.1");
+ private static final IpAddress NEXT_HOP_2 = IpAddress.valueOf("20.20.20.2");
+
+ private static final NodeId SOURCE_NODE_1 = NodeId.nodeId("1");
+ private static final NodeId SOURCE_NODE_2 = NodeId.nodeId("2");
+
+ private FabricRoute fabricRoute1;
+ private FabricRoute sameAsFabricRoute1;
+ private FabricRoute fabricRoute2;
+
+ /**
+ * Tests class immutability.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultFabricRoute.class);
+ }
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+ fabricRoute1 = DefaultFabricRoute.builder()
+ .source(SOURCE_1)
+ .prefix(IP_PREFIX_1)
+ .nextHop(NEXT_HOP_1)
+ .sourceNode(SOURCE_NODE_1)
+ .build();
+
+ sameAsFabricRoute1 = DefaultFabricRoute.builder()
+ .source(SOURCE_1)
+ .prefix(IP_PREFIX_1)
+ .nextHop(NEXT_HOP_1)
+ .sourceNode(SOURCE_NODE_1)
+ .build();
+
+ fabricRoute2 = DefaultFabricRoute.builder()
+ .source(SOURCE_2)
+ .prefix(IP_PREFIX_2)
+ .nextHop(NEXT_HOP_2)
+ .sourceNode(SOURCE_NODE_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(fabricRoute1, sameAsFabricRoute1)
+ .addEqualityGroup(fabricRoute2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ FabricRoute route = fabricRoute1;
+
+ assertEquals(route.source(), SOURCE_1);
+ assertEquals(route.prefix(), IP_PREFIX_1);
+ assertEquals(route.nextHop(), NEXT_HOP_1);
+ assertEquals(route.sourceNode(), SOURCE_NODE_1);
+ }
+}
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java
new file mode 100644
index 0000000..82efd14
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.impl;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.simplefabric.api.FabricSubnet;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Unit tests for the default fabric IP subnet class.
+ */
+public final class DefaultFabricSubnetTest {
+
+ private static final IpPrefix IP_PREFIX_1 = IpPrefix.valueOf("10.10.10.11/32");
+ private static final IpPrefix IP_PREFIX_2 = IpPrefix.valueOf("20.20.20.11/32");
+
+ private static final IpAddress GATEWAY_IP_1 = IpAddress.valueOf("10.10.10.1");
+ private static final IpAddress GATEWAY_IP_2 = IpAddress.valueOf("20.20.20.1");
+
+ private static final MacAddress GATEWAY_MAC_1 = MacAddress.valueOf("00:11:22:33:44:55");
+ private static final MacAddress GATEWAY_MAC_2 = MacAddress.valueOf("11:22:33:44:55:66");
+
+ private static final EncapsulationType ENCAP_TYPE_1 = EncapsulationType.NONE;
+ private static final EncapsulationType ENCAP_TYPE_2 = EncapsulationType.NONE;
+
+ private static final String NETWORK_NAME_1 = "sonaFabric1";
+ private static final String NETWORK_NAME_2 = "sonaFabric2";
+
+ private FabricSubnet subnet1;
+ private FabricSubnet sameAsSubnet1;
+ private FabricSubnet subnet2;
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+
+ subnet1 = DefaultFabricSubnet.builder()
+ .prefix(IP_PREFIX_1)
+ .gatewayIp(GATEWAY_IP_1)
+ .gatewayMac(GATEWAY_MAC_1)
+ .encapsulation(ENCAP_TYPE_1)
+ .networkName(NETWORK_NAME_1)
+ .build();
+
+ sameAsSubnet1 = DefaultFabricSubnet.builder()
+ .prefix(IP_PREFIX_1)
+ .gatewayIp(GATEWAY_IP_1)
+ .gatewayMac(GATEWAY_MAC_1)
+ .encapsulation(ENCAP_TYPE_1)
+ .networkName(NETWORK_NAME_1)
+ .build();
+
+ subnet2 = DefaultFabricSubnet.builder()
+ .prefix(IP_PREFIX_2)
+ .gatewayIp(GATEWAY_IP_2)
+ .gatewayMac(GATEWAY_MAC_2)
+ .encapsulation(ENCAP_TYPE_2)
+ .networkName(NETWORK_NAME_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(subnet1, sameAsSubnet1)
+ .addEqualityGroup(subnet2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ FabricSubnet subnet = subnet1;
+
+ assertEquals(subnet.prefix(), IP_PREFIX_1);
+ assertEquals(subnet.gatewayIp(), GATEWAY_IP_1);
+ assertEquals(subnet.gatewayMac(), GATEWAY_MAC_1);
+ assertEquals(subnet.encapsulation(), ENCAP_TYPE_1);
+ assertEquals(subnet.networkName(), NETWORK_NAME_1);
+ }
+}