Adding Encapsulation in VPLS and correcting bugs.
Change-Id: Idc0c1834ae2bbd0fdaf564fd65360cc0f018d18d
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/IntentInstaller.java b/apps/vpls/src/main/java/org/onosproject/vpls/IntentInstaller.java
index 52a3924..2cec14a 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/IntentInstaller.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/IntentInstaller.java
@@ -15,21 +15,25 @@
*/
package org.onosproject.vpls;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.Host;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.intent.ConnectivityIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
+import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.routing.IntentSynchronizationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +42,8 @@
import java.util.List;
import java.util.Set;
+import static org.onosproject.net.EncapsulationType.*;
+
/**
* Synchronizes intents between the in-memory intent store and the
* IntentService.
@@ -64,7 +70,7 @@
static final String PREFIX_BROADCAST = "brc";
static final String PREFIX_UNICAST = "uni";
- static final String DASH = "-";
+ static final String SEPARATOR = "-";
private final ApplicationId appId;
private final IntentSynchronizationService intentSynchronizer;
@@ -107,8 +113,8 @@
/**
* Returns list of intents belongs to a VPLS.
*
- * @param name required VPLS network name
- * @return list of intents belongs to a VPLS
+ * @param name the name of the VPLS
+ * @return the list of intents belonging to a VPLS
*/
protected List<Intent> getIntentsFromVpls(String name) {
List<Intent> intents = Lists.newArrayList();
@@ -128,28 +134,32 @@
* @param key key to identify the intent
* @param src the source connect point
* @param dsts the destination connect points
+ * @param encap the encapsulation type
* @return the generated single-point to multi-point intent
*/
protected SinglePointToMultiPointIntent buildBrcIntent(Key key,
FilteredConnectPoint src,
- Set<FilteredConnectPoint> dsts) {
- log.debug(SP2MP, src);
+ Set<FilteredConnectPoint> dsts,
+ EncapsulationType encap) {
+ log.debug("Building broadcast intent {} for source {}", SP2MP, src);
- SinglePointToMultiPointIntent intent;
+ SinglePointToMultiPointIntent.Builder intentBuilder;
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(MacAddress.BROADCAST)
.build();
- intent = SinglePointToMultiPointIntent.builder()
+ intentBuilder = SinglePointToMultiPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.filteredIngressPoint(src)
.filteredEgressPoints(dsts)
- .priority(PRIORITY_OFFSET)
- .build();
- return intent;
+ .priority(PRIORITY_OFFSET);
+
+ encap(intentBuilder, encap);
+
+ return intentBuilder.build();
}
/**
@@ -159,54 +169,60 @@
* @param srcs the source Connect Points
* @param dst the destination Connect Point
* @param host destination Host
+ * @param encap the encapsulation type
* @return the generated multi-point to single-point intent
*/
protected MultiPointToSinglePointIntent buildUniIntent(Key key,
Set<FilteredConnectPoint> srcs,
FilteredConnectPoint dst,
- Host host) {
- log.debug(MP2SP, dst);
+ Host host,
+ EncapsulationType encap) {
+ log.debug("Building unicast intent {} for destination {}", MP2SP, dst);
+
+ MultiPointToSinglePointIntent.Builder intentBuilder;
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(host.mac())
.build();
-
- return MultiPointToSinglePointIntent.builder()
+ intentBuilder = MultiPointToSinglePointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.filteredIngressPoints(srcs)
.filteredEgressPoint(dst)
- .priority(PRIORITY_OFFSET)
- .build();
+ .priority(PRIORITY_OFFSET);
+ encap(intentBuilder, encap);
+
+ return intentBuilder.build();
}
/**
- * Builds an intent Key for either for a single-point to multi-point or
- * multi-point to single-point intent, based on a prefix that defines
- * the type of intent, the single connection point representing the source
- * or the destination and the VLAN identifier representing the network.
+ * Builds an intent key either for single-point to multi-point or
+ * multi-point to single-point intents, based on a prefix that defines
+ * the type of intent, the single connect point representing the single
+ * source or destination for that intent, the name of the VPLS the intent
+ * belongs to, and the destination host MAC address the intent reaches.
*
- * @param prefix key prefix
- * @param cPoint connect point for single source/destination
- * @param networkName VPLS network name
- * @param hostMac source/destination mac address
- * @return key to identify the intent
+ * @param prefix the key prefix
+ * @param cPoint the connect point identifying the source/destination
+ * @param vplsName the name of the VPLS
+ * @param hostMac the source/destination MAC address
+ * @return the key to identify the intent
*/
protected Key buildKey(String prefix,
ConnectPoint cPoint,
- String networkName,
+ String vplsName,
MacAddress hostMac) {
- String keyString = networkName +
- DASH +
+ String keyString = vplsName +
+ SEPARATOR +
prefix +
- DASH +
+ SEPARATOR +
cPoint.deviceId() +
- DASH +
+ SEPARATOR +
cPoint.port() +
- DASH +
+ SEPARATOR +
hostMac;
return Key.of(keyString, appId);
@@ -215,8 +231,8 @@
/**
* Returns true if the specified intent exists; false otherwise.
*
- * @param intentKey intent key
- * @return true if the intent exists, false otherwise
+ * @param intentKey the intent key
+ * @return true if the intent exists; false otherwise
*/
protected boolean intentExists(Key intentKey) {
if (intentService.getIntent(intentKey) == null) {
@@ -225,10 +241,22 @@
// Intent does not exist if intent withdrawn
IntentState currentIntentState = intentService.getIntentState(intentKey);
- if (WITHDRAWN_INTENT_STATES.contains(currentIntentState)) {
- return false;
- }
+ return !WITHDRAWN_INTENT_STATES.contains(currentIntentState);
- return true;
+ }
+
+ /**
+ * Adds an encapsulation constraint to the builder given, if encap is not
+ * equal to NONE.
+ *
+ * @param builder the intent builder
+ * @param encap the encapsulation type
+ */
+ private static void encap(ConnectivityIntent.Builder builder,
+ EncapsulationType encap) {
+ if (!encap.equals(NONE)) {
+ builder.constraints(ImmutableList.of(
+ new EncapsulationConstraint(encap)));
+ }
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java b/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
index 4e4bd4b..039cd12 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
@@ -33,6 +33,7 @@
import org.onosproject.incubator.net.intf.InterfaceEvent;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
+import org.onosproject.net.EncapsulationType;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.Host;
import org.onosproject.net.config.NetworkConfigEvent;
@@ -63,13 +64,10 @@
import static org.onosproject.vpls.IntentInstaller.PREFIX_UNICAST;
/**
- * Application to create L2 broadcast overlay networks using VLAN.
+ * Application to create L2 broadcast overlay networks using VLANs.
*/
@Component(immediate = true)
public class Vpls {
- /**
- * Application name of VPLS.
- */
static final String VPLS_APP = "org.onosproject.vpls";
private static final String HOST_FCP_NOT_FOUND =
@@ -108,8 +106,8 @@
private final HostListener hostListener = new InternalHostListener();
- private final InternalInterfaceListener interfaceListener
- = new InternalInterfaceListener();
+ private final InternalInterfaceListener interfaceListener =
+ new InternalInterfaceListener();
private final InternalNetworkConfigListener configListener =
new InternalNetworkConfigListener();
@@ -155,16 +153,16 @@
*/
private void setupConnectivity(boolean isNetworkConfigEvent) {
SetMultimap<String, Interface> networkInterfaces =
- vplsConfigService.getVplsNetworks();
+ vplsConfigService.ifacesByVplsName();
Set<String> vplsAffectedByApi =
- new HashSet<>(vplsConfigService.getVplsAffectedByApi());
+ new HashSet<>(vplsConfigService.vplsAffectedByApi());
if (isNetworkConfigEvent && vplsAffectedByApi.isEmpty()) {
- vplsAffectedByApi.addAll(vplsConfigService.getOldVpls());
+ vplsAffectedByApi.addAll(vplsConfigService.vplsNamesOld());
}
- networkInterfaces.asMap().forEach((networkName, interfaces) -> {
+ networkInterfaces.asMap().forEach((vplsName, interfaces) -> {
Set<Host> hosts = Sets.newHashSet();
interfaces.forEach(intf -> {
// Add hosts that belongs to the specific VPLS
@@ -174,14 +172,17 @@
.forEach(hosts::add);
});
- setupConnectivity(networkName, interfaces, hosts,
- vplsAffectedByApi.contains(networkName));
- vplsAffectedByApi.remove(networkName);
+ EncapsulationType encap =
+ vplsConfigService.encap(vplsName);
+
+ setupConnectivity(vplsName, interfaces, hosts, encap,
+ vplsAffectedByApi.contains(vplsName));
+ vplsAffectedByApi.remove(vplsName);
});
if (!vplsAffectedByApi.isEmpty()) {
- for (String networkName:vplsAffectedByApi) {
- withdrawIntents(networkName, Lists.newArrayList());
+ for (String vplsName : vplsAffectedByApi) {
+ withdrawIntents(vplsName, Lists.newArrayList());
}
}
}
@@ -189,28 +190,30 @@
/**
* Sets up connectivity for specific VPLS.
*
- * @param networkName the VPLS name
+ * @param vplsName the VPLS name
* @param interfaces the interfaces that belong to the VPLS
* @param hosts the hosts that belong to the VPLS
+ * @param encap the encapsulation type
* @param affectedByApi true if this function is triggered from the APIs;
* false otherwise
*/
- private void setupConnectivity(String networkName,
+ private void setupConnectivity(String vplsName,
Collection<Interface> interfaces,
Set<Host> hosts,
+ EncapsulationType encap,
boolean affectedByApi) {
List<Intent> intents = Lists.newArrayList();
List<Key> keys = Lists.newArrayList();
Set<FilteredConnectPoint> fcPoints = buildFCPoints(interfaces);
- intents.addAll(buildUnicastIntents(
- networkName, hosts, fcPoints, affectedByApi));
intents.addAll(buildBroadcastIntents(
- networkName, fcPoints, affectedByApi));
+ vplsName, fcPoints, encap, affectedByApi));
+ intents.addAll(buildUnicastIntents(
+ vplsName, hosts, fcPoints, encap, affectedByApi));
if (affectedByApi) {
intents.forEach(intent -> keys.add(intent.key()));
- withdrawIntents(networkName, keys);
+ withdrawIntents(vplsName, keys);
}
intentInstaller.submitIntents(intents);
@@ -219,14 +222,13 @@
/**
* Withdraws intents belonging to a VPLS, given a VPLS name.
*
- * @param networkName the VPLS name
+ * @param vplsName the VPLS name
* @param keys the keys of the intents to be installed
*/
- private void withdrawIntents(String networkName,
- List<Key> keys) {
+ private void withdrawIntents(String vplsName, List<Key> keys) {
List<Intent> intents = Lists.newArrayList();
- intentInstaller.getIntentsFromVpls(networkName)
+ intentInstaller.getIntentsFromVpls(vplsName)
.forEach(intent -> {
if (!keys.contains(intent.key())) {
intents.add(intent);
@@ -239,14 +241,16 @@
/**
* Sets up broadcast intents between any given filtered connect point.
*
- * @param networkName the VPLS name
+ * @param vplsName the VPLS name
* @param fcPoints the set of filtered connect points
+ * @param encap the encapsulation type
* @param affectedByApi true if the function triggered from APIs;
* false otherwise
* @return the set of broadcast intents
*/
- private Set<Intent> buildBroadcastIntents(String networkName,
+ private Set<Intent> buildBroadcastIntents(String vplsName,
Set<FilteredConnectPoint> fcPoints,
+ EncapsulationType encap,
boolean affectedByApi) {
Set<Intent> intents = Sets.newHashSet();
fcPoints.forEach(point -> {
@@ -257,14 +261,15 @@
Key brcKey = intentInstaller.buildKey(PREFIX_BROADCAST,
point.connectPoint(),
- networkName,
+ vplsName,
MacAddress.BROADCAST);
- if ((!intentInstaller.intentExists(brcKey) || affectedByApi) &&
- !otherPoints.isEmpty()) {
+ if ((!intentInstaller.intentExists(brcKey) || affectedByApi)
+ && !otherPoints.isEmpty()) {
intents.add(intentInstaller.buildBrcIntent(brcKey,
point,
- otherPoints));
+ otherPoints,
+ encap));
}
});
@@ -274,16 +279,18 @@
/**
* Sets up unicast intents between any given filtered connect point.
*
- * @param networkName the VPLS name
+ * @param vplsName the VPLS name
* @param hosts the set of destination hosts
* @param fcPoints the set of filtered connect points
+ * @param encap the encapsulation type
* @param affectedByApi true if the function triggered from APIs;
* false otherwise
* @return the set of unicast intents
*/
- private Set<Intent> buildUnicastIntents(String networkName,
+ private Set<Intent> buildUnicastIntents(String vplsName,
Set<Host> hosts,
Set<FilteredConnectPoint> fcPoints,
+ EncapsulationType encap,
boolean affectedByApi) {
Set<Intent> intents = Sets.newHashSet();
hosts.forEach(host -> {
@@ -301,7 +308,7 @@
Key uniKey = intentInstaller.buildKey(PREFIX_UNICAST,
host.location(),
- networkName,
+ vplsName,
host.mac());
if ((!intentInstaller.intentExists(uniKey) || affectedByApi) &&
@@ -309,7 +316,8 @@
intents.add(intentInstaller.buildUniIntent(uniKey,
otherPoints,
hostPoint,
- host));
+ host,
+ encap));
}
});
@@ -346,7 +354,7 @@
* @return the set of filtered connect points
*/
private Set<FilteredConnectPoint> buildFCPoints(Collection<Interface> interfaces) {
- // Build all filtered connected points in the network
+ // Build all filtered connected points in the VPLS
return interfaces
.stream()
.map(intf -> {
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/VplsNeighbourHandler.java b/apps/vpls/src/main/java/org/onosproject/vpls/VplsNeighbourHandler.java
index d706dca..f2bfa9d 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/VplsNeighbourHandler.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/VplsNeighbourHandler.java
@@ -45,14 +45,14 @@
import static org.slf4j.LoggerFactory.getLogger;
/**
- * Handles neighbour messages for VPLS use case.
- * Handlers will be changed automatically by interface or network configuration events.
+ * Handles neighbour messages for on behalf of the VPLS application. Handlers
+ * will be changed automatically by interface or network configuration events.
*/
@Component(immediate = true)
public class VplsNeighbourHandler {
private static final String UNKNOWN_CONTEXT = "Unknown context type: {}";
- private static final String CAN_NOT_FIND_NETWORK =
+ private static final String CAN_NOT_FIND_VPLS =
"Cannot find VPLS for port {} with VLAN Id {}.";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -70,8 +70,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService configService;
- private VplsInterfaceListener interfaceListener
- = new VplsInterfaceListener();
+ private VplsInterfaceListener interfaceListener =
+ new VplsInterfaceListener();
protected VplsNeighbourMessageHandler neighbourHandler =
new VplsNeighbourMessageHandler();
@@ -101,7 +101,7 @@
private void configNeighbourHandler() {
neighbourService.unregisterNeighbourHandlers(appId);
- Set<Interface> interfaces = vplsConfigService.getAllInterfaces();
+ Set<Interface> interfaces = vplsConfigService.allIfaces();
interfaceService.getInterfaces()
.stream()
@@ -145,17 +145,18 @@
*/
protected void handleRequest(NeighbourMessageContext context) {
- SetMultimap<String, Interface> vplsNetwork =
- vplsConfigService.getVplsNetwork(context.vlan(), context.inPort());
+ SetMultimap<String, Interface> vpls =
+ vplsConfigService.ifacesByVplsName(context.vlan(),
+ context.inPort());
- if (vplsNetwork != null) {
- Collection<Interface> vplsInterfaces = vplsNetwork.values();
+ if (vpls != null) {
+ Collection<Interface> vplsInterfaces = vpls.values();
vplsInterfaces.stream()
.filter(intf -> !context.inPort().equals(intf.connectPoint()))
.forEach(context::forward);
} else {
- log.debug(CAN_NOT_FIND_NETWORK, context.inPort(), context.vlan());
+ log.debug(CAN_NOT_FIND_VPLS, context.inPort(), context.vlan());
}
}
@@ -168,18 +169,19 @@
protected void handleReply(NeighbourMessageContext context,
HostService hostService) {
- SetMultimap<String, Interface> vplsNetwork =
- vplsConfigService.getVplsNetwork(context.vlan(), context.inPort());
+ SetMultimap<String, Interface> vpls =
+ vplsConfigService.ifacesByVplsName(context.vlan(),
+ context.inPort());
Set<Host> hosts = hostService.getHostsByMac(context.dstMac());
- if (vplsNetwork != null) {
- Collection<Interface> vplsInterfaces = vplsNetwork.values();
+ if (vpls != null) {
+ Collection<Interface> vplsInterfaces = vpls.values();
hosts.forEach(host -> vplsInterfaces.stream()
.filter(intf -> intf.connectPoint().equals(host.location()))
.filter(intf -> intf.vlan().equals(host.vlan()))
.forEach(context::forward));
} else {
- log.debug(CAN_NOT_FIND_NETWORK, context.inPort(), context.vlan());
+ log.debug(CAN_NOT_FIND_VPLS, context.inPort(), context.vlan());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddCommand.java
index ffeb81f..b2c1da5 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddCommand.java
@@ -26,9 +26,9 @@
/**
* CLI to create VPLSs.
*/
-@Command(scope = "onos", name = "vpls-add", description = "Create a new VPLS")
+@Command(scope = "onos", name = "vpls-add", description = "Creates a new VPLS")
public class VplsAddCommand extends AbstractShellCommand {
- private static final String VPLS_EXIST = "VPLS already exists: %s";
+
private VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
@@ -38,11 +38,12 @@
@Override
protected void execute() {
-
- if (vplsConfigService.getAllVpls().contains(vplsName)) {
- print(VPLS_EXIST, vplsName);
+ // Check if the VPLS name is already configured
+ if (VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_ALREADY_EXISTS, vplsName);
return;
}
- vplsConfigService.addVpls(vplsName, new HashSet<>());
+
+ vplsConfigService.addVpls(vplsName, new HashSet<>(), null);
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddIfaceCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddIfaceCommand.java
index 5daaa9e..d6a50ff 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddIfaceCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsAddIfaceCommand.java
@@ -21,19 +21,14 @@
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.vpls.config.VplsConfigurationService;
-import java.util.Map;
-
/**
* CLI to add an interface to a VPLS.
*/
@Command(scope = "onos", name = "vpls-add-iface",
- description = "Add an interface to an existing VPLS")
+ description = "Adds an interface to an existing VPLS")
public class VplsAddIfaceCommand extends AbstractShellCommand {
- private static final String IFACE_ADD_FAIL = "Interface cannot be added.";
- private static final String IFACE_EXIST =
- "Interface %s already associated to network %s.";
- private VplsConfigurationService vplsConfigService =
+ private static VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
@Argument(index = 0, name = "vplsName", description = "Name of the VPLS",
@@ -46,24 +41,25 @@
@Override
protected void execute() {
- if (!vplsConfigService.getAllVpls().contains(vplsName)) {
- print(IFACE_ADD_FAIL);
+ // Check if the VPLS exists
+ if (!VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
return;
}
- if (vplsConfigService.getAllInterfaces()
- .stream()
- .anyMatch(e -> e.name().equals(ifaceName))) {
- print(IFACE_EXIST, ifaceName, vplsConfigService.getVplsNetworks()
- .entries()
- .stream()
- .filter(e->e.getValue().name().equals(ifaceName))
- .map(Map.Entry::getKey)
- .findFirst()
- .get());
+ // Check if the interface exists
+ if (!VplsCommandUtils.ifaceExists(ifaceName)) {
+ print(VplsCommandUtils.IFACE_NOT_FOUND, ifaceName);
return;
}
- vplsConfigService.addInterfaceToVpls(vplsName, ifaceName);
+ // Check if the interface is already associated to a VPLS
+ if (VplsCommandUtils.ifaceAlreadyAssociated(ifaceName)) {
+ print(VplsCommandUtils.IFACE_ALREADY_ASSOCIATED,
+ ifaceName, VplsCommandUtils.vplsNameFromIfaceName(ifaceName));
+ return;
+ }
+
+ vplsConfigService.addIface(vplsName, ifaceName);
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCleanCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCleanCommand.java
index 6507d6b..4156e08 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCleanCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCleanCommand.java
@@ -31,6 +31,6 @@
@Override
protected void execute() {
- vplsConfigService.cleanVpls();
+ vplsConfigService.cleanVplsConfig();
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCommandUtils.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCommandUtils.java
new file mode 100644
index 0000000..52c74a4
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsCommandUtils.java
@@ -0,0 +1,118 @@
+package org.onosproject.vpls.cli;
+
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
+import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.incubator.net.intf.InterfaceService;
+import org.onosproject.vpls.config.VplsConfigurationService;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+/**
+ * Util class for VPLS Commands.
+ */
+public final class VplsCommandUtils {
+
+ protected static final String VPLS_NAME = "VPLS name %s: ";
+ protected static final String VPLS_DISPLAY = "VPLS name: %s, associated " +
+ "interfaces: %s, encapsulation: %s";
+ protected static final String VPLS_NOT_FOUND = "VPLS %s not found.";
+ protected static final String IFACE_NOT_FOUND = "Interface %s not found.";
+ protected static final String VPLS_ALREADY_EXISTS = "VPLS %s already exists.";
+ protected static final String IFACE_ALREADY_ASSOCIATED =
+ "Interface %s already associated to VPLS %s.";
+ protected static final String IFACE_NOT_ASSOCIATED =
+ "Interface %s is associated to VPLS %s.";
+
+ private static VplsConfigurationService vplsConfigService =
+ getService(VplsConfigurationService.class);
+ private static InterfaceService interfaceService =
+ getService(InterfaceService.class);
+
+ private VplsCommandUtils() {}
+
+ /**
+ * States if a VPLS exists or not.
+ *
+ * @param vplsName the name of the VPLS
+ * @return true if the VPLS exists; false otherwise
+ */
+ protected static boolean vplsExists(String vplsName) {
+ return vplsConfigService.vplsNames().contains(vplsName);
+ }
+
+ /**
+ * States if an interface is defined or not in the system.
+ *
+ * @param ifaceName the name of the interface
+ * @return true if the interface is defined; false otherwise
+ */
+ protected static boolean ifaceExists(String ifaceName) {
+ return interfaceService.getInterfaces()
+ .stream()
+ .anyMatch(iface -> iface.name().equals(ifaceName));
+ }
+
+ /**
+ * States if an interface is already associated or not to a VPLS.
+ *
+ * @param ifaceName the name of the interface
+ * @return true if the interface is already associated to a VPLS; false
+ * otherwise
+ */
+ protected static boolean ifaceAlreadyAssociated(String ifaceName) {
+ return vplsConfigService.allIfaces()
+ .stream()
+ .anyMatch(iface -> iface.name().equals(ifaceName));
+ }
+
+ /**
+ * Returns the name of a VPLS, given the name of an interface associated to
+ * it.
+ *
+ * @param ifaceName the name of the interface
+ * @return the name of the VPLS that has the interface configured; null if
+ * the interface does not exist or is not associated to any VPLS
+ */
+ protected static String vplsNameFromIfaceName(String ifaceName) {
+ String vplsName = null;
+
+ Optional<String> optVplsName = vplsConfigService.ifacesByVplsName()
+ .entries()
+ .stream()
+ .filter(iface -> iface.getValue().name().equals(ifaceName))
+ .map(Map.Entry::getKey)
+ .findFirst();
+
+ if (optVplsName.isPresent()) {
+ vplsName = optVplsName.get();
+ }
+
+ return vplsName;
+ }
+
+ /**
+ * Returns a list of interfaces associated to a VPLS, given a VPLS name.
+ *
+ * @param vplsName the name of the VPLS
+ * @return the set of interfaces associated to the given VPLS; null if the
+ * VPLS is not found
+ */
+ protected static Set<String> ifacesFromVplsName(String vplsName) {
+ if (!vplsExists(vplsName)) {
+ return null;
+ }
+
+ SetMultimap<String, Interface> ifacesByVplsName =
+ vplsConfigService.ifacesByVplsName();
+ Set<String> ifaceNames = Sets.newHashSet();
+
+ ifacesByVplsName.get(vplsName).forEach(iface -> ifaceNames.add(iface.name()));
+
+ return ifaceNames;
+ }
+}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelCommand.java
index 693ad97..23e77ee 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelCommand.java
@@ -25,11 +25,9 @@
* CLI to remove VPLSs.
*/
@Command(scope = "onos", name = "vpls-del",
- description = "Deletes a VPLS")
+ description = "Deletes an existing VPLS")
public class VplsDelCommand extends AbstractShellCommand {
- private static final String NETWORK_NOT_FOUND =
- "VPLS %s not found";
private VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
@@ -39,9 +37,8 @@
@Override
protected void execute() {
-
- if (!vplsConfigService.getAllVpls().contains(vplsName)) {
- print(NETWORK_NOT_FOUND, vplsName);
+ if (!VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
return;
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelIfaceCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelIfaceCommand.java
index 695e48f..adf9ce9 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelIfaceCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsDelIfaceCommand.java
@@ -19,11 +19,8 @@
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
-import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.vpls.config.VplsConfigurationService;
-import java.util.Set;
-
/**
* CLI to remove an interface from an existing VPLS.
*/
@@ -31,23 +28,36 @@
description = "Removes an interface from an existing VPLS")
public class VplsDelIfaceCommand extends AbstractShellCommand {
- private static final String NO_CONFIGURATION = "Interface %s is not configured";
private VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- @Argument(index = 0, name = "IFACE_NAME", description = "Name of the interface" +
- " to remove from the VPLS", required = true, multiValued = false)
+ @Argument(index = 0, name = "vplsName", description = "Name of the VPLS",
+ required = true, multiValued = false)
+ private String vplsName = null;
+
+ @Argument(index = 1, name = "ifaceName", description = "Name of the interface" +
+ " to be removed from the VPLS", required = true, multiValued = false)
private String ifaceName = null;
@Override
protected void execute() {
- Set<Interface> ifaces = vplsConfigService.getAllInterfaces();
-
- if (!ifaces.stream().map(Interface::name).anyMatch(ifaceName::equals)) {
- print(NO_CONFIGURATION, ifaceName);
+ if (!VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
+ return;
}
- vplsConfigService.removeInterfaceFromVpls(ifaceName);
+ if (!VplsCommandUtils.ifaceExists(ifaceName)) {
+ print(VplsCommandUtils.IFACE_NOT_FOUND, ifaceName);
+ return;
+ }
+
+ if (!VplsCommandUtils.ifaceAlreadyAssociated(ifaceName)) {
+ print(VplsCommandUtils.IFACE_NOT_ASSOCIATED,
+ ifaceName, VplsCommandUtils.vplsNameFromIfaceName(ifaceName));
+ return;
+ }
+
+ vplsConfigService.removeIface(ifaceName);
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsListCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsListCommand.java
index bfbb054..aca247c 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsListCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsListCommand.java
@@ -23,15 +23,15 @@
/**
* CLI to list VPLSs.
*/
-@Command(scope = "onos", name = "vpls-list", description = "Lists the existing VPLSs")
+@Command(scope = "onos", name = "vpls-list", description = "List the VPLSs configured")
public class VplsListCommand extends AbstractShellCommand {
private VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
@Override
protected void execute() {
- vplsConfigService.getAllVpls().forEach(vpls -> {
- print("%s", vpls);
+ vplsConfigService.vplsNames().forEach(vpls -> {
+ print(VplsCommandUtils.VPLS_NAME, vpls);
});
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsSetEncapCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsSetEncapCommand.java
new file mode 100644
index 0000000..ba46ea7
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsSetEncapCommand.java
@@ -0,0 +1,54 @@
+/*
+ * 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.onosproject.vpls.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vpls.config.VplsConfigurationService;
+
+/**
+ * CLI to set encapsulation for a VPLS.
+ */
+@Command(scope = "onos", name = "vpls-set-encap",
+ description = "Sets the encapsulation type for a given VPLS. None means" +
+ "no encapsulation has been set")
+public class VplsSetEncapCommand extends AbstractShellCommand {
+
+ private static final String VPLS_NOT_FOUND = "VPLS %s not found.";
+ private VplsConfigurationService vplsConfigService =
+ get(VplsConfigurationService.class);
+
+ @Argument(index = 0, name = "vplsName", description = "Name of the VPLS",
+ required = true, multiValued = false)
+ private String vplsName = null;
+
+ @Argument(index = 1, name = "encapsulation", description = "The encapsulation" +
+ "type. For example, VLAN or MPLS. None for no encapsulation",
+ required = true, multiValued = false)
+ String encap = null;
+
+ @Override
+ protected void execute() {
+ if (!VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
+ return;
+ }
+
+ vplsConfigService.setEncap(vplsName, encap);
+ }
+}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsShowCommand.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsShowCommand.java
index 550d122..9dbeed6 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsShowCommand.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/VplsShowCommand.java
@@ -16,14 +16,13 @@
package org.onosproject.vpls.cli;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
-import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.net.EncapsulationType;
import org.onosproject.vpls.config.VplsConfigurationService;
+import java.util.Map;
import java.util.Set;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -35,40 +34,36 @@
description = "Shows the details of an existing VPLS")
public class VplsShowCommand extends AbstractShellCommand {
- private static final String NAME_FORMAT = "%10s: interface=%s";
- private static final String NETWORK_NOT_FOUND =
- "VPLS with name \'%s\' not found";
private VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- @Argument(index = 0, name = "NETWORK_NAME", description = "Name of the VPLS",
+ @Argument(index = 0, name = "vplsName", description = "Name of the VPLS",
required = false, multiValued = false)
private String vplsName = null;
@Override
protected void execute() {
- Set<String> vplsNames = vplsConfigService.getAllVpls();
- SetMultimap<String, Interface> vplsNetowrks = vplsConfigService.getVplsNetworks();
- Set<String> ifaceNames = Sets.newHashSet();
-
+ Set<String> vplsNames = vplsConfigService.vplsNames();
+ Map<String, EncapsulationType> encapByVplsName =
+ vplsConfigService.encapByVplsName();
if (!isNullOrEmpty(vplsName)) {
-
- if (vplsNames.contains(vplsName)) {
- vplsNetowrks.get(vplsName).stream()
- .map(Interface::name)
- .forEach(ifaceNames::add);
- print(NAME_FORMAT, vplsName, ifaceNames);
+ // A VPLS name is provided. Check first if the VPLS exists
+ if (VplsCommandUtils.vplsExists(vplsName)) {
+ print(VplsCommandUtils.VPLS_DISPLAY,
+ vplsName,
+ VplsCommandUtils.ifacesFromVplsName(vplsName).toString(),
+ encapByVplsName.get(vplsName).toString());
} else {
- print(NETWORK_NOT_FOUND, vplsName);
+ print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
}
} else {
+ // No VPLS names are provided. Display all VPLSs configured
vplsNames.forEach(vplsName -> {
- ifaceNames.clear();
- vplsNetowrks.get(vplsName).stream()
- .map(Interface::name)
- .forEach(ifaceNames::add);
- print(NAME_FORMAT, vplsName, ifaceNames);
+ print(VplsCommandUtils.VPLS_DISPLAY,
+ vplsName,
+ VplsCommandUtils.ifacesFromVplsName(vplsName).toString(),
+ encapByVplsName.get(vplsName).toString());
});
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCommandCompleter.java
similarity index 88%
rename from apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java
rename to apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCommandCompleter.java
index 9534635..a1cdfbb 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCommandCompleter.java
@@ -26,12 +26,12 @@
/**
* Completer for "vpls-add-inf" command.
*/
-public class VplsAddIfaceCmdCompleter extends AbstractChoicesCompleter {
+public class VplsAddIfaceCommandCompleter extends AbstractChoicesCompleter {
@Override
protected List<String> choices() {
VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- return Lists.newArrayList(vplsConfigService.getAllVpls());
+ return Lists.newArrayList(vplsConfigService.vplsNames());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelCommandCompleter.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelCommandCompleter.java
index 9c6c061..d360b2a 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelCommandCompleter.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelCommandCompleter.java
@@ -33,6 +33,6 @@
protected List<String> choices() {
VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- return Lists.newArrayList(vplsConfigService.getAllVpls());
+ return Lists.newArrayList(vplsConfigService.vplsNames());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelIfaceCommandCompleter.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelIfaceCommandCompleter.java
index 81a1583..794ccfc 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelIfaceCommandCompleter.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsDelIfaceCommandCompleter.java
@@ -35,7 +35,7 @@
protected List<String> choices() {
VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- Set<Interface> ifaces = vplsConfigService.getAllInterfaces();
+ Set<Interface> ifaces = vplsConfigService.allIfaces();
return ifaces.stream().map(Interface::name).collect(Collectors.toList());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsSetEncapCommandCompleter.java
similarity index 85%
copy from apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java
copy to apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsSetEncapCommandCompleter.java
index 9534635..409d2a7 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsAddIfaceCmdCompleter.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsSetEncapCommandCompleter.java
@@ -21,17 +21,18 @@
import org.onosproject.vpls.config.VplsConfigurationService;
import java.util.List;
+
import static org.onosproject.cli.AbstractShellCommand.get;
/**
- * Completer for "vpls-add-inf" command.
+ * Completer for "vpls-set-encap" command.
*/
-public class VplsAddIfaceCmdCompleter extends AbstractChoicesCompleter {
+public class VplsSetEncapCommandCompleter extends AbstractChoicesCompleter {
@Override
protected List<String> choices() {
VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- return Lists.newArrayList(vplsConfigService.getAllVpls());
+ return Lists.newArrayList(vplsConfigService.vplsNames());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsShowCommandCompleter.java b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsShowCommandCompleter.java
index 75ce663..0f572ea 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsShowCommandCompleter.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/cli/completer/VplsShowCommandCompleter.java
@@ -33,6 +33,6 @@
protected List<String> choices() {
VplsConfigurationService vplsConfigService =
get(VplsConfigurationService.class);
- return Lists.newArrayList(vplsConfigService.getAllVpls());
+ return Lists.newArrayList(vplsConfigService.vplsNames());
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java
new file mode 100644
index 0000000..398962e
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java
@@ -0,0 +1,220 @@
+/*
+ * 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.onosproject.vpls.config;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Sets;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.config.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+/**
+ * Represents the VPLS application configuration.
+ */
+public class VplsAppConfig extends Config<ApplicationId> {
+ private static final String VPLS = "vplsList";
+ private static final String NAME = "name";
+ private static final String INTERFACE = "interfaces";
+ private static final String ENCAPSULATION = "encapsulation";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ /**
+ * Returns a set of configured VPLSs.
+ *
+ * @return set of VPLSs
+ */
+ public Set<VplsConfig> vplss() {
+ Set<VplsConfig> vplss = Sets.newHashSet();
+
+ JsonNode vplsNode = object.get(VPLS);
+
+ if (vplsNode == null) {
+ return vplss;
+ }
+
+ vplsNode.forEach(jsonNode -> {
+ String name = jsonNode.get(NAME).asText();
+
+ Set<String> ifaces = Sets.newHashSet();
+ jsonNode.path(INTERFACE).forEach(ifacesNode ->
+ ifaces.add(ifacesNode.asText())
+ );
+
+ String encap = null;
+ if (jsonNode.hasNonNull(ENCAPSULATION)) {
+ encap = jsonNode.get(ENCAPSULATION).asText();
+ }
+ vplss.add(new VplsConfig(name,
+ ifaces,
+ EncapsulationType.enumFromString(encap)));
+ });
+
+ return vplss;
+ }
+
+ /**
+ * Returns the VPLS configuration given a VPLS name.
+ *
+ * @param name the name of the VPLS
+ * @return the VPLS configuration if it exists; null otherwise
+ */
+ public VplsConfig getVplsWithName(String name) {
+ return vplss().stream()
+ .filter(vpls -> vpls.name().equals(name))
+ .findFirst()
+ .orElse(null);
+ }
+
+ /**
+ * Adds a VPLS to the configuration.
+ *
+ * @param vpls the name of the VPLS
+ */
+ public void addVpls(VplsConfig vpls) {
+ ObjectNode vplsNode = JsonNodeFactory.instance.objectNode();
+
+ vplsNode.put(NAME, vpls.name());
+
+ ArrayNode ifacesNode = vplsNode.putArray(INTERFACE);
+ vpls.ifaces().forEach(ifacesNode::add);
+
+ vplsNode.put(ENCAPSULATION, vpls.encap().toString());
+
+ ArrayNode vplsArray = vplss().isEmpty() ?
+ initVplsConfiguration() : (ArrayNode) object.get(VPLS);
+ vplsArray.add(vplsNode);
+ }
+
+ /**
+ * Removes a VPLS from the configuration.
+ *
+ * @param vplsName the vplsName of the VPLS to be removed
+ */
+ public void removeVpls(String vplsName) {
+ ArrayNode configuredVpls = (ArrayNode) object.get(VPLS);
+
+ for (int i = 0; i < configuredVpls.size(); i++) {
+ if (configuredVpls.get(i).hasNonNull(NAME) &&
+ configuredVpls.get(i).get(NAME).asText().equals(vplsName)) {
+ configuredVpls.remove(i);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Finds a VPLS with a given network interface.
+ *
+ * @param iface the network interface
+ * @return the VPLS if found; null otherwise
+ */
+ public VplsConfig vplsFromIface(String iface) {
+ for (VplsConfig vpls : vplss()) {
+ if (vpls.isAttached(iface)) {
+ return vpls;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Adds a network interface to a VPLS.
+ *
+ * @param vplsName the vplsName of the VPLS
+ * @param iface the network interface to be added
+ */
+ public void addIface(String vplsName, String iface) {
+ JsonNode vplsNodes = object.get(VPLS);
+ vplsNodes.forEach(vplsNode -> {
+ if (hasNamedNode(vplsNode, vplsName)) {
+ ArrayNode ifacesNode = (ArrayNode) vplsNode.get(INTERFACE);
+ for (int i = 0; i < ifacesNode.size(); i++) {
+ if (ifacesNode.get(i).asText().equals(iface)) {
+ return; // Interface already exists.
+ }
+ }
+ ifacesNode.add(iface);
+ }
+ });
+ }
+
+ /**
+ * Removes a network interface from a VPLS.
+ *
+ * @param name the name of the VPLS
+ * @param iface the network interface to be removed
+ */
+ public void removeIface(VplsConfig name, String iface) {
+ JsonNode vplsNodes = object.get(VPLS);
+ vplsNodes.forEach(vplsNode -> {
+ if (hasNamedNode(vplsNode, name.name())) {
+ ArrayNode ifacesNode = (ArrayNode) vplsNode.get(INTERFACE);
+ for (int i = 0; i < ifacesNode.size(); i++) {
+ if (ifacesNode.get(i).asText().equals(iface)) {
+ ifacesNode.remove(i);
+ return;
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Activate, deactivates, sets the encapsulation type for a given VPLS.
+ *
+ * @param vplsName the vplsName of the VPLS
+ * @param encap the encapsulation type, if set
+ */
+ public void setEncap(String vplsName, EncapsulationType encap) {
+ JsonNode vplsNodes = object.get(VPLS);
+ vplsNodes.forEach(vplsNode -> {
+ if (hasNamedNode(vplsNode, vplsName)) {
+ ((ObjectNode) vplsNode).put(ENCAPSULATION, encap.toString());
+ }
+ });
+ }
+
+ /**
+ * States if a JSON node has a "name" attribute and if the value is equal to
+ * the name given.
+ *
+ * @param jsonNode the JSON node
+ * @param name the node name
+ * @return true if the JSON node has a "name" attribute with value equal to
+ * the name given; false otherwise
+ */
+ private boolean hasNamedNode(JsonNode jsonNode, String name) {
+ return jsonNode.hasNonNull(NAME) &&
+ jsonNode.get(NAME).asText().equals(name);
+ }
+
+ /**
+ * Creates an empty VPLS configuration.
+ *
+ * @return empty ArrayNode to store the VPLS configuration
+ */
+ private ArrayNode initVplsConfiguration() {
+ return object.putArray(VPLS);
+ }
+}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
index f8323ef..94e96ab 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
@@ -15,180 +15,88 @@
*/
package org.onosproject.vpls.config;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.Sets;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.config.Config;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.EncapsulationType;
+import java.util.Objects;
import java.util.Set;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
- * Configuration object for VPLS config.
+ * Configuration of a VPLS.
*/
-public class VplsConfig extends Config<ApplicationId> {
- private static final String VPLS = "vplsNetworks";
- private static final String NAME = "name";
- private static final String INTERFACE = "interfaces";
+public class VplsConfig {
+ private final String name;
+ private final Set<String> ifaces;
+ private final EncapsulationType encap;
/**
- * Returns a set of configured VPLSs.
- *
- * @return set of VPLSs
- */
- public Set<VplsNetworkConfig> vplsNetworks() {
- Set<VplsNetworkConfig> vpls = Sets.newHashSet();
-
- JsonNode vplsNode = object.get(VPLS);
-
- if (vplsNode == null) {
- return vpls;
- }
-
- vplsNode.forEach(jsonNode -> {
- Set<String> ifaces = Sets.newHashSet();
- jsonNode.path(INTERFACE).forEach(ifacesNode ->
- ifaces.add(ifacesNode.asText())
- );
-
- String name = jsonNode.get(NAME).asText();
-
- vpls.add(new VplsNetworkConfig(name, ifaces));
- });
-
- return vpls;
- }
-
- /**
- * Returns the VPLS configuration given a VPLS name.
+ * Creates a new VPLS configuration.
*
* @param name the VPLS name
- * @return the VPLS configuration if it exists; null otherwise
+ * @param ifaces the interfaces associated with the VPLS
+ * @param encap the encapsulation type if set
*/
- public VplsNetworkConfig getVplsWithName(String name) {
- for (VplsNetworkConfig vpls : vplsNetworks()) {
- if (vpls.name().equals(name)) {
- return vpls;
- }
+ public VplsConfig(String name, Set<String> ifaces, EncapsulationType encap) {
+ this.name = checkNotNull(name);
+ this.ifaces = checkNotNull(ImmutableSet.copyOf(ifaces));
+ this.encap = checkNotNull(encap);
+ }
+
+ /**
+ * The name of the VPLS.
+ *
+ * @return the name of the VPLS
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * The name of the interfaces associated with the VPLS.
+ *
+ * @return a set of interface names associated with the VPLS
+ */
+ public Set<String> ifaces() {
+ return ImmutableSet.copyOf(ifaces);
+ }
+
+ /**
+ * The encapsulation type.
+ *
+ * @return the encapsulation type, if active; null otherwise
+ */
+ public EncapsulationType encap() {
+ return encap;
+ }
+
+ /**
+ * States if a given interface is part of a VPLS.
+ *
+ * @param iface the interface attached to a VPLS
+ * @return true if the interface is associated to the VPLS; false otherwise
+ */
+ public boolean isAttached(String iface) {
+ return ifaces.stream().anyMatch(iface::equals);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
}
- return null;
- }
-
- /**
- * Adds a VPLS to the configuration.
- *
- * @param name the name of the VPLS to be added
- */
- public void addVpls(VplsNetworkConfig name) {
- ObjectNode vplsNode = JsonNodeFactory.instance.objectNode();
-
- vplsNode.put(NAME, name.name());
-
- ArrayNode ifacesNode = vplsNode.putArray(INTERFACE);
- name.ifaces().forEach(ifacesNode::add);
-
- ArrayNode vplsArray = vplsNetworks().isEmpty() ?
- initVplsConfiguration() : (ArrayNode) object.get(VPLS);
- vplsArray.add(vplsNode);
- }
-
- /**
- * Removes a VPLS from the configuration.
- *
- * @param name the name of the VPLS to be removed
- */
- public void removeVpls(String name) {
- ArrayNode vplsArray = (ArrayNode) object.get(VPLS);
-
- for (int i = 0; i < vplsArray.size(); i++) {
- if (vplsArray.get(i).hasNonNull(NAME) &&
- vplsArray.get(i).get(NAME).asText().equals(name)) {
- vplsArray.remove(i);
- return;
- }
+ if (obj instanceof VplsConfig) {
+ VplsConfig that = (VplsConfig) obj;
+ return Objects.equals(name, that.name) &&
+ Objects.equals(ifaces, that.ifaces) &&
+ Objects.equals(encap, that.encap);
}
+ return false;
}
- /**
- * Finds a VPLS with a given network interface.
- *
- * @param iface the network interface
- * @return the VPLS if found; null otherwise
- */
- public VplsNetworkConfig getVplsFromInterface(String iface) {
- for (VplsNetworkConfig vpls : vplsNetworks()) {
- if (vpls.isAttached(iface)) {
- return vpls;
- }
- }
- return null;
- }
-
- /**
- * Adds a network interface to a VPLS.
- *
- * @param name the name of the VPLS
- * @param iface the network interface to be added
- */
- public void addInterfaceToVpls(String name, String iface) {
- JsonNode vplsNode = object.get(VPLS);
- vplsNode.forEach(jsonNode -> {
-
- if (hasNamedNode(jsonNode, name)) {
- ArrayNode ifacesNode = (ArrayNode) jsonNode.get(INTERFACE);
- for (int i = 0; i < ifacesNode.size(); i++) {
- if (ifacesNode.get(i).asText().equals(iface)) {
- return; // Interface already exists.
- }
- }
- ifacesNode.add(iface);
- }
- });
- }
-
- /**
- * Removes a network interface from a VPLS.
- *
- * @param name the name of the VPLS
- * @param iface the network interface to be removed
- */
- public void removeInterfaceFromVpls(VplsNetworkConfig name, String iface) {
- JsonNode vplsNode = object.get(VPLS);
- vplsNode.forEach(jsonNode -> {
- if (hasNamedNode(jsonNode, name.name())) {
- ArrayNode ifacesNode = (ArrayNode) jsonNode.get(INTERFACE);
- for (int i = 0; i < ifacesNode.size(); i++) {
- if (ifacesNode.get(i).asText().equals(iface)) {
- ifacesNode.remove(i);
- return;
- }
- }
- }
- });
- }
-
- /**
- * States if a JSON node has a "name" attribute and if the value is equal to
- * the name given.
- *
- * @param jsonNode the JSON node
- * @param name the node name
- * @return true if the JSON node has a "name" attribute with value equal to
- * the name given; false otherwise
- */
- private boolean hasNamedNode(JsonNode jsonNode, String name) {
- return jsonNode.hasNonNull(NAME) &&
- jsonNode.get(NAME).asText().equals(name);
- }
-
- /**
- * Creates an empty VPLS configuration.
- *
- * @return empty ArrayNode to store the VPLS configuration
- */
- private ArrayNode initVplsConfiguration() {
- return object.putArray(VPLS);
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, ifaces, encap);
}
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java
index 16cd4c4..6579378 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java
@@ -19,102 +19,129 @@
import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
+import java.util.Map;
import java.util.Set;
/**
* Provides information about the VPLS configuration.
*/
public interface VplsConfigurationService {
- Class<VplsConfig> CONFIG_CLASS = VplsConfig.class;
+ Class<VplsAppConfig> CONFIG_CLASS = VplsAppConfig.class;
/**
* Adds a VPLS to the configuration.
*
- * @param name the name of the VPLS
+ * @param vplsName the name of the VPLS
* @param ifaces the interfaces associated with the VPLS
+ * @param encap the encapsulation type
*/
- void addVpls(String name, Set<String> ifaces);
+ void addVpls(String vplsName, Set<String> ifaces, String encap);
/**
* Removes a VPLS from the configuration.
*
- * @param name the name of the VPLS to be removed
+ * @param vplsName the name of the VPLS to be removed
*/
- void removeVpls(String name);
+ void removeVpls(String vplsName);
/**
* Adds a network interface to a VPLS.
*
- * @param name the name of the VPLS
+ * @param vplsName the name of the VPLS
* @param iface the network interface to be added to the VPLS
*/
- void addInterfaceToVpls(String name, String iface);
+ void addIface(String vplsName, String iface);
+
+ /**
+ * Sets an encapsulation parameter for a VPLS.
+ *
+ * @param vplsName the name of the VPLS
+ * @param encap the encapsulation used (i.e. MPLS or VLAN) or
+ */
+ void setEncap(String vplsName, String encap);
+
+ /**
+ * Returns the encapsulation type in use for a given VPLS.
+ *
+ * @param vplsName the name of the VPLS
+ * @return the encapsulation type in use, if any
+ */
+ EncapsulationType encap(String vplsName);
/**
* Removes a network interface from a VPLS.
*
* @param iface the network interface to be removed from the VPLS
*/
- void removeInterfaceFromVpls(String iface);
+ void removeIface(String iface);
/**
* Cleans up the VPLS configuration. Removes all VPLSs.
*/
- void cleanVpls();
+ void cleanVplsConfig();
/**
* Retrieves the VPLS names modified from CLI.
*
- * @return a set of VPLS names modified from CLI
+ * @return the VPLS names modified from CLI
*/
- Set<String> getVplsAffectedByApi();
- // TODO Removes this function after intent framework fix race condition
+ Set<String> vplsAffectedByApi();
+ // TODO Remove this function after the intent framework race condition has been fixed
/**
* Retrieves the interfaces from the VPLS configuration.
*
* @return a set of interfaces contained in the VPLS configuration
*/
- Set<Interface> getAllInterfaces();
+ Set<Interface> allIfaces();
/**
* Retrieves the interfaces belonging to the VPLS.
*
- * @param name the name of the VPLS
+ * @param vplsName the name of the VPLS
* @return a set of interfaces belonging to the VPLS
*/
- Set<Interface> getVplsInterfaces(String name);
+ Set<Interface> ifaces(String vplsName);
/**
* Retrieves all VPLS names.
*
* @return a set of VPLS names
*/
- Set<String> getAllVpls();
+ Set<String> vplsNames();
/**
* Retrieves all VPLS names from the old config.
*
* @return a set of VPLS names
*/
- Set<String> getOldVpls();
+ Set<String> vplsNamesOld();
// TODO Removes this function after intent framework fix race condition
/**
- * Retrieves the VPLS names and associated interfaces from the configuration.
+ * Returns the VPLS names and associated interfaces from the configuration.
*
- * @return a map VPLS names and associated interfaces
+ * @return a map of VPLS names and associated interfaces
*/
- SetMultimap<String, Interface> getVplsNetworks();
+ SetMultimap<String, Interface> ifacesByVplsName();
/**
- * Retrieves a VPLS network given a VLAN Id and a connect point.
+ * Returns the list of interfaces grouped by VPLS name, given a VLAN Id and
+ * a connect point.
*
* @param vlan the VLAN Id
* @param connectPoint the connect point
- * @return a map VPLS names and associated interfaces; null otherwise
+ * @return a map of VPLS names and associated interfaces; null otherwise
*/
- SetMultimap<String, Interface> getVplsNetwork(VlanId vlan,
- ConnectPoint connectPoint);
+ SetMultimap<String, Interface> ifacesByVplsName(VlanId vlan,
+ ConnectPoint connectPoint);
+
+ /**
+ * Returns the VPLS names and associated encapsulation type.
+ *
+ * @return a map of VPLS names and associated encapsulation type
+ */
+ Map<String, EncapsulationType> encapByVplsName();
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsNetworkConfig.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsNetworkConfig.java
deleted file mode 100644
index b3c721b..0000000
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsNetworkConfig.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.onosproject.vpls.config;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.Objects;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Configuration of a VPLS Network.
- */
-public class VplsNetworkConfig {
- private final String name;
- private final Set<String> ifaces;
-
- /**
- * Creates a new VPLS configuration.
- *
- * @param name the VPLS name
- * @param ifaces the interfaces associated with the VPLS
- */
- public VplsNetworkConfig(String name, Set<String> ifaces) {
- this.name = checkNotNull(name);
- this.ifaces = checkNotNull(ImmutableSet.copyOf(ifaces));
- }
-
- /**
- * Returns the name of the VPLS.
- *
- * @return the name of the VPLS
- */
- public String name() {
- return name;
- }
-
- /**
- * Returns the name of interfaces associated with the VPLS.
- *
- * @return a set of interface names associated with the VPLS
- */
- public Set<String> ifaces() {
- return ImmutableSet.copyOf(ifaces);
- }
-
- /**
- * States if a given interface is part of a VPLS.
- *
- * @param iface the interface attached to a VPLS
- * @return true if the interface is associated to the VPLS; false otherwise
- */
- public boolean isAttached(String iface) {
- return ifaces.stream().anyMatch(i -> i.equals(iface));
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof VplsNetworkConfig) {
- final VplsNetworkConfig that = (VplsNetworkConfig) obj;
- return Objects.equals(this.name, that.name) &&
- Objects.equals(this.ifaces, that.ifaces);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, ifaces);
- }
-}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java
index e977170..0c2f09b 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java
@@ -16,8 +16,10 @@
package org.onosproject.vpls.config.impl;
import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -31,19 +33,22 @@
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.net.config.NetworkConfigListener;
-import org.onosproject.net.config.NetworkConfigEvent;
-import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.vpls.config.VplsAppConfig;
import org.onosproject.vpls.config.VplsConfig;
-import org.onosproject.vpls.config.VplsNetworkConfig;
import org.onosproject.vpls.config.VplsConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -80,21 +85,22 @@
private final Set<String> vplsAffectedByApi = new HashSet<>();
- private VplsConfig vplsConfig = new VplsConfig();
+ private VplsAppConfig vplsAppConfig = new VplsAppConfig();
private SetMultimap<String, String> ifacesOfVpls = HashMultimap.create();
private SetMultimap<String, String> oldIfacesOfVpls = HashMultimap.create();
- private SetMultimap<String, Interface> vplsNetworks = HashMultimap.create();
+ private SetMultimap<String, Interface> vplsIfaces = HashMultimap.create();
+ private Map<String, EncapsulationType> vplsEncaps = Maps.newHashMap();
private final InternalNetworkConfigListener configListener =
new InternalNetworkConfigListener();
- private ConfigFactory<ApplicationId, VplsConfig> vplsConfigFactory =
- new ConfigFactory<ApplicationId, VplsConfig>(
- SubjectFactories.APP_SUBJECT_FACTORY, VplsConfig.class, VPLS) {
+ private ConfigFactory<ApplicationId, VplsAppConfig> vplsConfigFactory =
+ new ConfigFactory<ApplicationId, VplsAppConfig>(
+ SubjectFactories.APP_SUBJECT_FACTORY, VplsAppConfig.class, VPLS) {
@Override
- public VplsConfig createConfig() {
- return new VplsConfig();
+ public VplsAppConfig createConfig() {
+ return new VplsAppConfig();
}
};
@@ -115,23 +121,164 @@
log.info("Stopped");
}
+ @Override
+ public void addVpls(String vplsName, Set<String> ifaces, String encap) {
+ EncapsulationType encapType = EncapsulationType.enumFromString(encap);
+
+ if (ifacesOfVpls.containsKey(vplsName)) {
+ if (ifaces.isEmpty()) {
+ return;
+ }
+ ifaces.forEach(iface -> vplsAppConfig.addIface(vplsName, iface));
+ vplsAppConfig.setEncap(vplsName, encapType);
+ } else {
+ vplsAppConfig.addVpls(new VplsConfig(vplsName, ifaces, encapType));
+ }
+
+ vplsAffectedByApi.add(vplsName);
+ applyConfig(vplsAppConfig);
+ }
+
+ @Override
+ public void removeVpls(String vplsName) {
+ if (ifacesOfVpls.containsKey(vplsName)) {
+ vplsAppConfig.removeVpls(vplsName);
+ vplsAffectedByApi.add(vplsName);
+ applyConfig(vplsAppConfig);
+ }
+ }
+
+ @Override
+ public void addIface(String vplsName, String iface) {
+ if (ifacesOfVpls.containsKey(vplsName)) {
+ vplsAppConfig.addIface(vplsName, iface);
+ vplsAffectedByApi.add(vplsName);
+ applyConfig(vplsAppConfig);
+ }
+ }
+
+ @Override
+ public void setEncap(String vplsName, String encap) {
+ EncapsulationType encapType = EncapsulationType.enumFromString(encap);
+
+ if (ifacesOfVpls.containsKey(vplsName)) {
+ vplsAppConfig.setEncap(vplsName, encapType);
+ vplsAffectedByApi.add(vplsName);
+ applyConfig(vplsAppConfig);
+ }
+ }
+
+ @Override
+ public void removeIface(String iface) {
+ if (ifacesOfVpls.containsValue(iface)) {
+ VplsConfig vpls = vplsAppConfig.vplsFromIface(iface);
+ vplsAppConfig.removeIface(vpls, iface);
+ vplsAffectedByApi.add(vpls.name());
+ applyConfig(vplsAppConfig);
+ }
+ }
+
+ @Override
+ public void cleanVplsConfig() {
+ ifacesOfVpls.entries().forEach(e -> {
+ vplsAppConfig.removeVpls(e.getKey());
+ vplsAffectedByApi.add(e.getKey());
+ });
+ applyConfig(vplsAppConfig);
+ }
+
+ @Override
+ public EncapsulationType encap(String vplsName) {
+ EncapsulationType encap = null;
+ if (vplsEncaps.containsKey(vplsName)) {
+ encap = vplsEncaps.get(vplsName);
+ }
+
+ return encap;
+ }
+
+ @Override
+ public Set<String> vplsAffectedByApi() {
+ Set<String> vplsNames = ImmutableSet.copyOf(vplsAffectedByApi);
+ vplsAffectedByApi.clear();
+
+ return vplsNames;
+ }
+
+ @Override
+ public Set<Interface> allIfaces() {
+ Set<Interface> allVplsInterfaces = new HashSet<>();
+ vplsIfaces.values().forEach(allVplsInterfaces::add);
+
+ return allVplsInterfaces;
+ }
+
+ @Override
+ public Set<Interface> ifaces(String vplsName) {
+ Set<Interface> vplsInterfaces = new HashSet<>();
+ vplsIfaces.get(vplsName).forEach(vplsInterfaces::add);
+
+ return vplsInterfaces;
+ }
+
+ @Override
+ public Set<String> vplsNames() {
+ return ifacesOfVpls.keySet();
+ }
+
+ @Override
+ public Set<String> vplsNamesOld() {
+ return oldIfacesOfVpls.keySet();
+ }
+
+ @Override
+ public SetMultimap<String, Interface> ifacesByVplsName() {
+ return ImmutableSetMultimap.copyOf(vplsIfaces);
+ }
+
+ @Override
+ public SetMultimap<String, Interface> ifacesByVplsName(VlanId vlan,
+ ConnectPoint connectPoint) {
+ String vplsName =
+ vplsIfaces.entries().stream()
+ .filter(e -> e.getValue().connectPoint().equals(connectPoint))
+ .filter(e -> e.getValue().vlan().equals(vlan))
+ .map(e -> e.getKey())
+ .findFirst()
+ .orElse(null);
+ SetMultimap<String, Interface> result = HashMultimap.create();
+ if (vplsName != null && vplsIfaces.containsKey(vplsName)) {
+ vplsIfaces.get(vplsName)
+ .forEach(intf -> result.put(vplsName, intf));
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, EncapsulationType> encapByVplsName() {
+ return ImmutableMap.copyOf(vplsEncaps);
+ }
+
/**
* Retrieves the VPLS configuration from network configuration.
*/
private void loadConfiguration() {
loadAppId();
- vplsConfig = configService.getConfig(vplsAppId, VplsConfig.class);
+ vplsAppConfig = configService.getConfig(vplsAppId, VplsAppConfig.class);
- if (vplsConfig == null) {
+ if (vplsAppConfig == null) {
log.warn(CONFIG_NULL);
- configService.addConfig(vplsAppId, VplsConfig.class);
+ configService.addConfig(vplsAppId, VplsAppConfig.class);
return;
}
oldIfacesOfVpls = ifacesOfVpls;
ifacesOfVpls = getConfigInterfaces();
- vplsNetworks = getConfigCPoints();
+ vplsIfaces = getConfigCPoints();
+ vplsEncaps = getConfigEncap();
+
log.debug(CONFIG_CHANGED, ifacesOfVpls);
}
@@ -148,21 +295,37 @@
/**
* Applies a given configuration to the VPLS application.
*/
- private void applyConfig(VplsConfig vplsConfig) {
+ private void applyConfig(VplsAppConfig vplsAppConfig) {
loadAppId();
- configService.applyConfig(vplsAppId, VplsConfig.class, vplsConfig.node());
+ configService.applyConfig(vplsAppId, VplsAppConfig.class, vplsAppConfig.node());
}
/**
- * Retrieves the VPLS names and associated interfaces names from the configuration.
+ * Retrieves the VPLS names and related encapsulation types from the
+ * configuration.
*
- * @return a map VPLS names and associated interface names
+ * @return a map of VPLS names and associated encapsulation types
+ */
+ private Map<String, EncapsulationType> getConfigEncap() {
+ Map<String, EncapsulationType> configEncap = new HashMap<>();
+
+ vplsAppConfig.vplss().forEach(vpls -> {
+ configEncap.put(vpls.name(), vpls.encap());
+ });
+
+ return configEncap;
+ }
+
+ /**
+ * Retrieves the VPLS names and related interfaces names from the configuration.
+ *
+ * @return a map of VPLS names and related interface names
*/
private SetMultimap<String, String> getConfigInterfaces() {
SetMultimap<String, String> confIntfByVpls =
HashMultimap.create();
- vplsConfig.vplsNetworks().forEach(vpls -> {
+ vplsAppConfig.vplss().forEach(vpls -> {
if (vpls.ifaces().isEmpty()) {
confIntfByVpls.put(vpls.name(), EMPTY);
} else {
@@ -174,9 +337,9 @@
}
/**
- * Retrieves the VPLS names and associated interfaces from the configuration.
+ * Retrieves the VPLS names and related interfaces from the configuration.
*
- * @return a map VPLS names and associated interfaces
+ * @return a map of VPLS names and related interfaces
*/
private SetMultimap<String, Interface> getConfigCPoints() {
log.debug(CHECK_CONFIG);
@@ -209,127 +372,10 @@
case CONFIG_REMOVED:
loadConfiguration();
break;
-
default:
break;
}
}
}
}
-
- @Override
- public void addVpls(String name, Set<String> ifaces) {
- VplsNetworkConfig vpls;
-
- if (ifacesOfVpls.containsKey(name)) {
- if (ifaces.isEmpty()) {
- return;
- }
-
- ifaces.forEach(iface ->
- vplsConfig.addInterfaceToVpls(name, iface));
- } else {
- vpls = new VplsNetworkConfig(name, ifaces);
- vplsConfig.addVpls(vpls);
- }
-
- vplsAffectedByApi.add(name);
- applyConfig(vplsConfig);
- }
-
- @Override
- public void removeVpls(String name) {
- if (ifacesOfVpls.containsKey(name)) {
- vplsConfig.removeVpls(name);
- vplsAffectedByApi.add(name);
- applyConfig(vplsConfig);
- }
- }
-
- @Override
- public void addInterfaceToVpls(String name, String iface) {
- if (ifacesOfVpls.containsKey(name)) {
- vplsConfig.addInterfaceToVpls(name, iface);
- vplsAffectedByApi.add(name);
- applyConfig(vplsConfig);
- }
- }
-
- @Override
- public void removeInterfaceFromVpls(String iface) {
- if (ifacesOfVpls.containsValue(iface)) {
- VplsNetworkConfig vpls = vplsConfig.getVplsFromInterface(iface);
- vplsConfig.removeInterfaceFromVpls(vpls, iface);
- vplsAffectedByApi.add(vpls.name());
- applyConfig(vplsConfig);
- }
- }
-
- @Override
- public void cleanVpls() {
- ifacesOfVpls.entries().forEach(e -> {
- vplsConfig.removeVpls(e.getKey());
- vplsAffectedByApi.add(e.getKey());
- });
- applyConfig(vplsConfig);
- }
-
- @Override
- public Set<String> getVplsAffectedByApi() {
- Set<String> vplsNames = ImmutableSet.copyOf(vplsAffectedByApi);
-
- vplsAffectedByApi.clear();
-
- return vplsNames;
- }
-
- @Override
- public Set<Interface> getAllInterfaces() {
- Set<Interface> allInterfaces = new HashSet<>();
- vplsNetworks.values().forEach(allInterfaces::add);
-
- return allInterfaces;
- }
-
- @Override
- public Set<Interface> getVplsInterfaces(String name) {
- Set<Interface> vplsInterfaces = new HashSet<>();
- vplsNetworks.get(name).forEach(vplsInterfaces::add);
-
- return vplsInterfaces;
- }
-
- @Override
- public Set<String> getAllVpls() {
- return ifacesOfVpls.keySet();
- }
-
- @Override
- public Set<String> getOldVpls() {
- return oldIfacesOfVpls.keySet();
- }
-
- @Override
- public SetMultimap<String, Interface> getVplsNetworks() {
- return ImmutableSetMultimap.copyOf(vplsNetworks);
- }
-
- @Override
- public SetMultimap<String, Interface> getVplsNetwork(VlanId vlan,
- ConnectPoint connectPoint) {
- String vplsNetworkName =
- vplsNetworks.entries().stream()
- .filter(e -> e.getValue().connectPoint().equals(connectPoint))
- .filter(e -> e.getValue().vlan().equals(vlan))
- .map(e -> e.getKey())
- .findFirst()
- .orElse(null);
- SetMultimap<String, Interface> result = HashMultimap.create();
- if (vplsNetworkName != null && vplsNetworks.containsKey(vplsNetworkName)) {
- vplsNetworks.get(vplsNetworkName)
- .forEach(intf -> result.put(vplsNetworkName, intf));
- return result;
- }
- return null;
- }
}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/package-info.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/package-info.java
index 3229c7b..b5d6ec9 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/package-info.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/package-info.java
@@ -15,6 +15,6 @@
*/
/**
- * Configuration implementation to create L2 broadcast network using VLAN.
+ * Configuration service implementation for VPLS.
*/
package org.onosproject.vpls.config.impl;
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/package-info.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/package-info.java
index f080044..a0a94d2 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/package-info.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/package-info.java
@@ -17,4 +17,4 @@
/**
* Configuration to create L2 broadcast network using VLAN.
*/
-package org.onosproject.vpls.config;
+package org.onosproject.vpls.config;
\ No newline at end of file
diff --git a/apps/vpls/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/vpls/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 5815ffd..3aa3bd3 100644
--- a/apps/vpls/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/apps/vpls/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -45,6 +45,13 @@
<action class="org.onosproject.vpls.cli.VplsListCommand"/>
</command>
<command>
+ <action class="org.onosproject.vpls.cli.VplsSetEncapCommand"/>
+ <completers>
+ <ref component-id="VplsSetEncapCommandCompleter"/>
+ <null/>
+ </completers>
+ </command>
+ <command>
<action class="org.onosproject.vpls.cli.VplsShowCommand"/>
<completers>
<ref component-id="VplsShowCommandCompleter"/>
@@ -56,8 +63,9 @@
</command>
</command-bundle>
- <bean id="VplsAddIfaceCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsAddIfaceCmdCompleter"/>
+ <bean id="VplsAddIfaceCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsAddIfaceCommandCompleter"/>
<bean id="VplsDelCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsDelCommandCompleter"/>
<bean id="VplsDelIfaceCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsDelIfaceCommandCompleter"/>
+ <bean id="VplsSetEncapCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsSetEncapCommandCompleter"/>
<bean id="VplsShowCommandCompleter" class="org.onosproject.vpls.cli.completer.VplsShowCommandCompleter"/>
-</blueprint>
+</blueprint>
\ No newline at end of file
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsConfigurationServiceAdapter.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsConfigurationServiceAdapter.java
new file mode 100644
index 0000000..a534bd2
--- /dev/null
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsConfigurationServiceAdapter.java
@@ -0,0 +1,79 @@
+package org.onosproject.vpls;
+
+import com.google.common.collect.SetMultimap;
+import org.onlab.packet.VlanId;
+import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.vpls.config.VplsConfigurationService;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Test adapter for VPLS configuration service.
+ */
+public class VplsConfigurationServiceAdapter implements VplsConfigurationService {
+ @Override
+ public void addVpls(String vplsName, Set<String> ifaces, String encap) {}
+
+ @Override
+ public void removeVpls(String vplsName) {}
+
+ @Override
+ public void addIface(String vplsName, String iface) {}
+
+ @Override
+ public void setEncap(String vplsName, String encap) {}
+
+ @Override
+ public EncapsulationType encap(String vplsName) {
+ return null;
+ }
+
+ @Override
+ public void removeIface(String iface) {}
+
+ @Override
+ public void cleanVplsConfig() {}
+
+ @Override
+ public Set<String> vplsAffectedByApi() {
+ return null;
+ }
+
+ @Override
+ public Set<Interface> allIfaces() {
+ return null;
+ }
+
+ @Override
+ public Set<Interface> ifaces(String vplsName) {
+ return null;
+ }
+
+ @Override
+ public Set<String> vplsNames() {
+ return null;
+ }
+
+ @Override
+ public Set<String> vplsNamesOld() {
+ return null;
+ }
+
+ @Override
+ public SetMultimap<String, Interface> ifacesByVplsName() {
+ return null;
+ }
+
+ @Override
+ public SetMultimap<String, Interface> ifacesByVplsName(VlanId vlan, ConnectPoint connectPoint) {
+ return null;
+ }
+
+ @Override
+ public Map<String, EncapsulationType> encapByVplsName() {
+ return null;
+ }
+}
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsNeighbourHandlerTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsNeighbourHandlerTest.java
index 90e3415..66edd13 100644
--- a/apps/vpls/src/test/java/org/onosproject/vpls/VplsNeighbourHandlerTest.java
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsNeighbourHandlerTest.java
@@ -19,6 +19,7 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import org.junit.After;
@@ -41,6 +42,7 @@
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultHost;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
@@ -48,9 +50,9 @@
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.HostServiceAdapter;
import org.onosproject.net.provider.ProviderId;
-import org.onosproject.vpls.config.VplsConfigurationService;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@@ -61,81 +63,88 @@
* Tests the the {@link VplsNeighbourHandler} class.
*/
public class VplsNeighbourHandlerTest {
- private final ConnectPoint of1p1 =
- new ConnectPoint(DeviceId.deviceId("of:1"),
- PortNumber.portNumber(1));
- private final ConnectPoint of4p1 =
- new ConnectPoint(DeviceId.deviceId("of:4"),
- PortNumber.portNumber(1));
- private final ConnectPoint of3p1 =
- new ConnectPoint(DeviceId.deviceId("of:3"),
- PortNumber.portNumber(1));
- private final ConnectPoint of4p2 =
- new ConnectPoint(DeviceId.deviceId("of:4"),
- PortNumber.portNumber(2));
- private final ConnectPoint of2p1 =
- new ConnectPoint(DeviceId.deviceId("of:2"),
- PortNumber.portNumber(1));
- private final VlanId vlan100 = VlanId.vlanId("100");
- private final VlanId vlan200 = VlanId.vlanId("200");
- private final VlanId vlan300 = VlanId.vlanId("300");
+ private static final String IFACES_NOT_EXPECTED =
+ "The interfaces reached by the packet are not equal to the " +
+ "interfaces expected";
- private final Interface v100h1 =
- new Interface("v100h1", of1p1, null, null, vlan100);
- private final Interface v100h2 =
- new Interface("v100h2", of4p1, null, null, vlan100);
- private final Interface v200h1 =
- new Interface("v200h1", of4p2, null, null, vlan200);
- private final Interface v300h1 =
- new Interface("v300h1", of3p1, null, null, vlan300);
- private final Interface v200h2 =
- new Interface("v200h2", of2p1, null, null, vlan200);
+ private static final DeviceId DID1 = getDeviceId(1);
+ private static final DeviceId DID2 = getDeviceId(2);
+ private static final DeviceId DID3 = getDeviceId(3);
+ private static final DeviceId DID4 = getDeviceId(4);
- private final MacAddress mac1 = MacAddress.valueOf("00:00:00:00:00:01");
- private final MacAddress mac2 = MacAddress.valueOf("00:00:00:00:00:02");
- private final MacAddress mac3 = MacAddress.valueOf("00:00:00:00:00:03");
- private final MacAddress mac4 = MacAddress.valueOf("00:00:00:00:00:04");
- private final MacAddress mac5 = MacAddress.valueOf("00:00:00:00:00:05");
+ private static final PortNumber P1 = PortNumber.portNumber(1);
+ private static final PortNumber P2 = PortNumber.portNumber(2);
- private final ProviderId pid = new ProviderId("of", "foo");
+ private static final ConnectPoint OF1P1 = new ConnectPoint(DID1, P1);
+ private static final ConnectPoint OF2P1 = new ConnectPoint(DID2, P1);
+ private static final ConnectPoint OF3P1 = new ConnectPoint(DID3, P1);
+ private static final ConnectPoint OF4P1 = new ConnectPoint(DID4, P1);
+ private static final ConnectPoint OF4P2 = new ConnectPoint(DID4, P2);
- private final Host v100host1 = makeHost(mac1, vlan100, of1p1);
- private final Host v100host2 = makeHost(mac2, vlan100, of4p1);
- private final Host v200host1 = makeHost(mac3, vlan200, of4p2);
- private final Host v300host1 = makeHost(mac4, vlan300, of3p1);
- private final Host v200host2 = makeHost(mac5, vlan200, of2p1);
+ private static final String VPLS1 = "vpls1";
+ private static final String VPLS2 = "vpls2";
- private final Set<Host> availableHosts = ImmutableSet.of(v100host1,
- v100host2,
- v200host1,
- v300host1,
- v200host2);
+ private static final VlanId VLAN100 = VlanId.vlanId("100");
+ private static final VlanId VLAN200 = VlanId.vlanId("200");
+ private static final VlanId VLAN300 = VlanId.vlanId("300");
- private final Set<Interface> avaliableInterfaces =
- ImmutableSet.of(v100h1, v100h2, v200h1, v200h2, v300h1);
+ private static final Interface V100H1 =
+ new Interface("v100h1", OF1P1, null, null, VLAN100);
+ private static final Interface V100H2 =
+ new Interface("v100h2", OF4P1, null, null, VLAN100);
+ private static final Interface V200H1 =
+ new Interface("v200h1", OF4P2, null, null, VLAN200);
+ private static final Interface V200H2 =
+ new Interface("v200h2", OF2P1, null, null, VLAN200);
+ private static final Interface V300H1 =
+ new Interface("v300h1", OF3P1, null, null, VLAN300);
+
+ private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
+ private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
+ private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03");
+ private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04");
+ private static final MacAddress MAC5 = MacAddress.valueOf("00:00:00:00:00:05");
+
+ private static final ProviderId PID = new ProviderId("of", "foo");
+
+ private final Host v100Host1 = makeHost(MAC1, VLAN100, OF1P1);
+ private final Host v100Host2 = makeHost(MAC2, VLAN100, OF4P1);
+ private final Host v200Host1 = makeHost(MAC3, VLAN200, OF4P2);
+ private final Host v200Host2 = makeHost(MAC5, VLAN200, OF2P1);
+ private final Host v300Host1 = makeHost(MAC4, VLAN300, OF3P1);
+
+ private final Set<Host> availableHosts = ImmutableSet.of(v100Host1,
+ v100Host2,
+ v200Host1,
+ v300Host1,
+ v200Host2);
+
+ private final Set<Interface> availableInterfaces =
+ ImmutableSet.of(V100H1, V100H2, V200H1, V200H2, V300H1);
private VplsNeighbourHandler vplsNeighbourHandler;
private HostService hostService;
/**
- * Sets up 2 VPLS which contain 2 networks and 5 hosts.
- * net1 contains 3 hosts: v100h1, v200h1 and v300h1
- * net2 contains 2 hosts: v100h2, v200h2
+ * Sets up 2 VPLS.
+ * VPLS 1 contains 3 hosts: v100h1, v200h1 and v300h1
+ * VPLS 2 contains 2 hosts: v100h2, v200h2
*/
@Before
public void setUp() {
vplsNeighbourHandler = new VplsNeighbourHandler();
- SetMultimap<String, Interface> vplsNetworks =
+ SetMultimap<String, Interface> ifacesByVpls =
HashMultimap.create();
- vplsNetworks.put("net1", v100h1);
- vplsNetworks.put("net1", v200h1);
- vplsNetworks.put("net1", v300h1);
- vplsNetworks.put("net2", v100h2);
- vplsNetworks.put("net2", v200h2);
+ ifacesByVpls.put(VPLS1, V100H1);
+ ifacesByVpls.put(VPLS1, V200H1);
+ ifacesByVpls.put(VPLS1, V300H1);
+ ifacesByVpls.put(VPLS2, V100H2);
+ ifacesByVpls.put(VPLS2, V200H2);
+ HashMap<String, EncapsulationType> encap = Maps.newHashMap();
vplsNeighbourHandler.vplsConfigService =
- new TestVplsConfigService(vplsNetworks);
+ new TestVplsConfigService(ifacesByVpls, encap);
vplsNeighbourHandler.interfaceService =
new TestInterfaceService();
vplsNeighbourHandler.neighbourService =
@@ -150,133 +159,133 @@
}
/**
- * Sends request messages to all hosts in VPLS net1.
- * Request messages should be received from other hosts in net1.
+ * Sends request messages to all hosts in VPLS 1.
+ * Request messages should be received from other hosts in VPLS 1.
*/
@Test
- public void testNet1RequestMessage() {
- // Request from v100h1 (net1)
- // Should be received by v200h1 and v300h1
+ public void vpls1RequestMessage() {
+ // Request messages from v100h1 (VPLS 1) should be received by v200h1 and v300h1
TestMessageContext requestMessage =
- makeBroadcastRequestContext(v100host1);
- Set<Interface> expectInterfaces = ImmutableSet.of(v200h1, v300h1);
+ makeBroadcastRequestContext(v100Host1);
+ Set<Interface> expectInterfaces = ImmutableSet.of(V200H1, V300H1);
vplsNeighbourHandler.handleRequest(requestMessage);
- assertEquals(expectInterfaces, requestMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults);
- // Request from v200h1 (net1)
- // Should be received by v100h1 and v300h1
- requestMessage = makeBroadcastRequestContext(v200host1);
- expectInterfaces = ImmutableSet.of(v100h1, v300h1);
+ // Request messages from v200h1 (VPLS 1) should be received by v100h1 and v300h1
+ requestMessage = makeBroadcastRequestContext(v200Host1);
+ expectInterfaces = ImmutableSet.of(V100H1, V300H1);
vplsNeighbourHandler.handleRequest(requestMessage);
- assertEquals(expectInterfaces, requestMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults);
- // Request from v300h1 (net1)
- // Should be received by v100h1 and v200h1
- requestMessage = makeBroadcastRequestContext(v300host1);
- expectInterfaces = ImmutableSet.of(v100h1, v200h1);
+ // Request from v300h1 (VPLS 1) should be received by v100h1 and v200h1
+ requestMessage = makeBroadcastRequestContext(v300Host1);
+ expectInterfaces = ImmutableSet.of(V100H1, V200H1);
vplsNeighbourHandler.handleRequest(requestMessage);
- assertEquals(expectInterfaces, requestMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults);
}
/**
- * Sends request messages to all hosts in VPLS net2.
- * Request messages should be received from other hosts in net2.
+ * Sends request messages to all hosts in VPLS 2.
+ * Request messages should be received from other hosts in VPLS 2.
*/
@Test
- public void testNet2RequestMessage() {
- // Request from v100h2
- // Should be received by v200h2
+ public void vpls2RequestMessage() {
+ // Request messages from v100h2 (VPLS 2) should be received by v200h2
TestMessageContext requestMessage =
- makeBroadcastRequestContext(v100host2);
- Set<Interface> expectInterfaces = ImmutableSet.of(v200h2);
+ makeBroadcastRequestContext(v100Host2);
+ Set<Interface> expectInterfaces = ImmutableSet.of(V200H2);
vplsNeighbourHandler.handleRequest(requestMessage);
- assertEquals(expectInterfaces, requestMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults);
- // Request from v200h2
- // Should be received by v100h2
- requestMessage = makeBroadcastRequestContext(v200host2);
- expectInterfaces = ImmutableSet.of(v100h2);
+ // Request messages from v200h2 (VPLS 2) should be received by v100h2
+ requestMessage = makeBroadcastRequestContext(v200Host2);
+ expectInterfaces = ImmutableSet.of(V100H2);
vplsNeighbourHandler.handleRequest(requestMessage);
- assertEquals(expectInterfaces, requestMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults);
}
/**
- * Sends reply messages to hosts in VPLS net1.
+ * Sends reply messages to hosts in VPLS 1.
* Reply messages should be received by the host with MAC address equal to
* the dstMac of the message context.
*/
@Test
- public void testNet1ReplyMessage() {
- // Response from v100h1 (net1) to v200h1 (net1)
- // Should be received by v200h1
+ public void vpls1ReplyMessage() {
+ // Reply messages from v100h1 (VPLS 1) should be received by v200h1
TestMessageContext replyMessage =
- makeReplyContext(v100host1, v200host1);
- Set<Interface> expectInterfaces = ImmutableSet.of(v200h1);
+ makeReplyContext(v100Host1, v200Host1);
+ Set<Interface> expectInterfaces = ImmutableSet.of(V200H1);
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
- // Response from v200h1 (net1) to v300h1 (net1)
- // Should be received by v300h1
- replyMessage = makeReplyContext(v200host1, v300host1);
- expectInterfaces = ImmutableSet.of(v300h1);
+ // Reply messages from v200h1 (VPLS 1) should be received by v300h1
+ replyMessage = makeReplyContext(v200Host1, v300Host1);
+ expectInterfaces = ImmutableSet.of(V300H1);
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
- // Response from v300h1 (net1) to v100h1 (net1)
- // Should be received by v100h1
- replyMessage = makeReplyContext(v300host1, v100host1);
- expectInterfaces = ImmutableSet.of(v100h1);
+ // Reply messages from v300h1 (VPLS 1) should be received by v100h1
+ replyMessage = makeReplyContext(v300Host1, v100Host1);
+ expectInterfaces = ImmutableSet.of(V100H1);
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
}
/**
- * Sends reply messages to hosts in VPLS net2.
+ * Sends reply messages to hosts in VPLS 2.
* Reply messages should be received by the host with MAC address equal to
* the dstMac of the message context.
*/
@Test
- public void testNet2ReplyMessage() {
- // Response from v100h2 (net2) to v200h2 (net2)
- // Should be received by v200h2
+ public void vpls2ReplyMessage() {
+ // Reply messages from v100h2 (VPLS 2) should be received by v200h2
TestMessageContext replyMessage =
- makeReplyContext(v100host2, v200host2);
- Set<Interface> expectInterfaces = ImmutableSet.of(v200h2);
+ makeReplyContext(v100Host2, v200Host2);
+ Set<Interface> expectInterfaces = ImmutableSet.of(V200H2);
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
- // Response from v200h2 (net2) to v100h2 (net2)
- // Should be received by v100h2
- replyMessage = makeReplyContext(v200host2, v100host2);
- expectInterfaces = ImmutableSet.of(v100h2);
+ // Reply messages from v200h2 (VPLS 2) should be received by v100h2
+ replyMessage = makeReplyContext(v200Host2, v100Host2);
+ expectInterfaces = ImmutableSet.of(V100H2);
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
}
/**
* Sends wrong reply messages to hosts.
* The source and the destination MAC addresses are not set on any host of the VPLS.
- * The reply messages won't be received by any hosts.
+ * The reply messages will not be received by any hosts.
*/
@Test
- public void testWrongReplyMessage() {
- // Response from v100h1 (net1) to v100h2 (net2)
- // forward results should be empty
- TestMessageContext replyMessage = makeReplyContext(v100host1, v100host2);
+ public void wrongReplyMessage() {
+ // Reply message from v100h1 (VPLS 1) to v100h2 (VPLS 2).
+ // Forward results should be empty
+ TestMessageContext replyMessage = makeReplyContext(v100Host1, v100Host2);
Set<Interface> expectInterfaces = ImmutableSet.of();
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
- // Response from v200h2 (net2) to v300h1 (net1)
- // forward results should be empty
- replyMessage = makeReplyContext(v200host2, v300host1);
+ // Reply message from v200h2 (VPLS 2) to v300h1 (VPLS 1).
+ // Forward results should be empty
+ replyMessage = makeReplyContext(v200Host2, v300Host1);
expectInterfaces = ImmutableSet.of();
vplsNeighbourHandler.handleReply(replyMessage, hostService);
- assertEquals(expectInterfaces, replyMessage.forwardResults);
+ assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults);
+ }
+
+ /**
+ * Returns the device Id of the ith device.
+ *
+ * @param i the device to get the Id of
+ * @return the device Id
+ */
+ private static DeviceId getDeviceId(int i) {
+ return DeviceId.deviceId("" + i);
}
private Host makeHost(MacAddress mac, VlanId vlan, ConnectPoint cp) {
- return new DefaultHost(pid,
+ return new DefaultHost(PID,
HostId.hostId(mac, vlan),
mac,
vlan,
@@ -336,6 +345,7 @@
this.forwardResults = Sets.newHashSet();
}
+
@Override
public ConnectPoint inPort() {
return inPort;
@@ -407,21 +417,22 @@
}
}
- private class TestVplsConfigService implements VplsConfigurationService {
+ private class TestVplsConfigService extends VplsConfigurationServiceAdapter {
- private final SetMultimap<String, Interface> vplsNetworks;
+ private final SetMultimap<String, Interface> ifacesByVplsName;
- public TestVplsConfigService(SetMultimap<String, Interface> networks) {
- this.vplsNetworks = networks;
+ public TestVplsConfigService(SetMultimap<String, Interface> ifacesByVplsName,
+ HashMap<String, EncapsulationType> encapByVplsName) {
+ this.ifacesByVplsName = ifacesByVplsName;
}
@Override
- public void addVpls(String name, Set<String> ifaceNames) {
- if (!vplsNetworks.containsKey(name)) {
+ public void addVpls(String vplsName, Set<String> ifaceNames, String encap) {
+ if (!ifacesByVplsName.containsKey(vplsName)) {
ifaceNames.forEach(ifaceName -> {
- avaliableInterfaces.forEach(intf -> {
- if (intf.name().equals(ifaceName)) {
- vplsNetworks.put(name, intf);
+ availableInterfaces.forEach(iface -> {
+ if (iface.name().equals(ifaceName)) {
+ ifacesByVplsName.put(vplsName, iface);
}
});
});
@@ -429,87 +440,77 @@
}
@Override
- public void removeVpls(String name) {
- if (vplsNetworks.containsKey(name)) {
- vplsNetworks.removeAll(name);
+ public void removeVpls(String vplsName) {
+ if (ifacesByVplsName.containsKey(vplsName)) {
+ ifacesByVplsName.removeAll(vplsName);
}
}
@Override
- public void addInterfaceToVpls(String name, String ifaceName) {
- avaliableInterfaces.forEach(intf -> {
+ public void addIface(String vplsName, String ifaceName) {
+ availableInterfaces.forEach(intf -> {
if (intf.name().equals(ifaceName)) {
- vplsNetworks.put(name, intf);
+ ifacesByVplsName.put(vplsName, intf);
}
});
}
@Override
- public void removeInterfaceFromVpls(String ifaceName) {
+ public void removeIface(String ifaceName) {
SetMultimap<String, Interface> toBeRemoved = HashMultimap.create();
- vplsNetworks.entries().forEach(e -> {
+ ifacesByVplsName.entries().forEach(e -> {
if (e.getValue().name().equals(ifaceName)) {
toBeRemoved.put(e.getKey(), e.getValue());
}
});
toBeRemoved.entries()
- .forEach(e -> vplsNetworks.remove(e.getKey(),
- e.getValue()));
+ .forEach(e -> ifacesByVplsName.remove(e.getKey(),
+ e.getValue()));
}
@Override
- public void cleanVpls() {
- vplsNetworks.clear();
+ public void cleanVplsConfig() {
+ ifacesByVplsName.clear();
}
@Override
- public Set<String> getVplsAffectedByApi() {
- return null;
+ public Set<Interface> allIfaces() {
+ return ImmutableSet.copyOf(ifacesByVplsName.values());
}
@Override
- public Set<Interface> getAllInterfaces() {
- return ImmutableSet.copyOf(vplsNetworks.values());
- }
-
- @Override
- public Set<Interface> getVplsInterfaces(String name) {
- return vplsNetworks.get(name)
+ public Set<Interface> ifaces(String name) {
+ return ifacesByVplsName.get(name)
.stream()
.collect(Collectors.toSet());
}
@Override
- public Set<String> getAllVpls() {
- return vplsNetworks.keySet();
+ public Set<String> vplsNames() {
+ return ifacesByVplsName.keySet();
}
@Override
- public Set<String> getOldVpls() {
- return null;
+ public SetMultimap<String, Interface> ifacesByVplsName() {
+ return ImmutableSetMultimap.copyOf(ifacesByVplsName);
}
@Override
- public SetMultimap<String, Interface> getVplsNetworks() {
- return ImmutableSetMultimap.copyOf(vplsNetworks);
- }
-
- @Override
- public SetMultimap<String, Interface> getVplsNetwork(VlanId vlan,
- ConnectPoint connectPoint) {
- String vplsNetworkName =
- vplsNetworks.entries().stream()
+ public SetMultimap<String, Interface> ifacesByVplsName(VlanId vlan,
+ ConnectPoint connectPoint) {
+ String vplsName =
+ ifacesByVplsName.entries().stream()
.filter(e -> e.getValue().connectPoint().equals(connectPoint))
.filter(e -> e.getValue().vlan().equals(vlan))
.map(e -> e.getKey())
.findFirst()
.orElse(null);
SetMultimap<String, Interface> result = HashMultimap.create();
- if (vplsNetworkName != null &&
- vplsNetworks.containsKey(vplsNetworkName)) {
- vplsNetworks.get(vplsNetworkName)
- .forEach(intf -> result.put(vplsNetworkName, intf));
+ if (vplsName != null &&
+ ifacesByVplsName.containsKey(vplsName)) {
+ ifacesByVplsName.get(vplsName)
+ .forEach(intf -> result.put(vplsName, intf));
return result;
}
return null;
@@ -654,13 +655,13 @@
@Override
public Set<Interface> getInterfaces() {
- return avaliableInterfaces;
+ return availableInterfaces;
}
@Override
public Interface getInterfaceByName(ConnectPoint connectPoint,
String name) {
- return avaliableInterfaces.stream()
+ return availableInterfaces.stream()
.filter(intf -> intf.name().equals(name))
.findFirst()
.orElse(null);
@@ -669,28 +670,28 @@
@Override
public Set<Interface> getInterfacesByPort(ConnectPoint port) {
- return avaliableInterfaces.stream()
+ return availableInterfaces.stream()
.filter(intf -> intf.connectPoint().equals(port))
.collect(Collectors.toSet());
}
@Override
public Set<Interface> getInterfacesByIp(IpAddress ip) {
- return avaliableInterfaces.stream()
+ return availableInterfaces.stream()
.filter(intf -> intf.ipAddressesList().contains(ip))
.collect(Collectors.toSet());
}
@Override
public Set<Interface> getInterfacesByVlan(VlanId vlan) {
- return avaliableInterfaces.stream()
+ return availableInterfaces.stream()
.filter(intf -> intf.vlan().equals(vlan))
.collect(Collectors.toSet());
}
@Override
public Interface getMatchingInterface(IpAddress ip) {
- return avaliableInterfaces.stream()
+ return availableInterfaces.stream()
.filter(intf -> intf.ipAddressesList().contains(ip))
.findFirst()
.orElse(null);
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
index 178e1a8..a7585da 100644
--- a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
@@ -16,6 +16,7 @@
package org.onosproject.vpls;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -23,6 +24,7 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.SetMultimap;
@@ -47,6 +49,7 @@
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultHost;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
@@ -61,6 +64,7 @@
import org.onosproject.net.host.HostListener;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.HostServiceAdapter;
+import org.onosproject.net.intent.ConnectivityIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentServiceAdapter;
@@ -68,6 +72,7 @@
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
+import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.routing.IntentSynchronizationAdminService;
import org.onosproject.routing.IntentSynchronizationService;
@@ -82,6 +87,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.onosproject.net.EncapsulationType.*;
import static org.onosproject.vpls.IntentInstaller.PREFIX_BROADCAST;
import static org.onosproject.vpls.IntentInstaller.PREFIX_UNICAST;
@@ -93,9 +99,8 @@
private static final ApplicationId APPID = TestApplicationId.create(APP_NAME);
private static final String DASH = "-";
private static final int PRIORITY_OFFSET = 1000;
- private static final String NET1 = "net1";
- private static final String NET2 = "net2";
- private static final String COMPARE = "Comparing %s to %s";
+ private static final String VPLS1 = "vpls1";
+ private static final String VPLS2 = "vpls2";
private static final PortNumber P1 = PortNumber.portNumber(1);
@@ -147,47 +152,47 @@
private static IdGenerator idGenerator;
- private final Interface v100h1 =
+ private static final Interface V100H1 =
new Interface("v100h1", CP1, null, null, VLAN100);
- private final Interface v100h2 =
+ private static final Interface V100H2 =
new Interface("v100h2", CP2, null, null, VLAN100);
- private final Interface v200h1 =
+ private static final Interface V200H1 =
new Interface("v200h1", CP3, null, null, VLAN200);
- private final Interface v200h2 =
+ private static final Interface V200H2 =
new Interface("v200h2", CP4, null, null, VLAN200);
- private final Interface v300h1 =
+ private static final Interface V300H1 =
new Interface("v300h1", CP5, null, null, VLAN300);
- private final Interface v300h2 =
+ private static final Interface V300H2 =
new Interface("v300h2", CP6, null, null, VLAN300);
- private final Host v100host1 =
+ private static final Host V100HOST1 =
new DefaultHost(PID, HID1, MAC1, VLAN100,
getLocation(1), Collections.singleton(IP1));
- private final Host v100host2 =
+ private static final Host V100HOST2 =
new DefaultHost(PID, HID2, MAC2, VLAN100,
getLocation(2), Sets.newHashSet());
- private final Host v200host1 =
+ private static final Host V200HOST1 =
new DefaultHost(PID, HID3, MAC3, VLAN200,
getLocation(3), Collections.singleton(IP2));
- private final Host v200host2 =
+ private static final Host V200HOST2 =
new DefaultHost(PID, HID4, MAC4, VLAN200,
getLocation(4), Sets.newHashSet());
- private final Host v300host1 =
+ private static final Host V300HOST1 =
new DefaultHost(PID, HID5, MAC5, VLAN300,
getLocation(5), Sets.newHashSet());
- private final Host v300host2 =
+ private static final Host V300HOST2 =
new DefaultHost(PID, HID6, MAC6, VLAN300,
getLocation(6), Sets.newHashSet());
- private final Host v300host3 =
+ private static final Host V300HOST3 =
new DefaultHost(PID, HID7, MAC7, VLAN300,
getLocation(7), Sets.newHashSet());
- private final Set<Interface> avaliableInterfaces =
- ImmutableSet.of(v100h1, v100h2, v200h1, v200h2, v300h1, v300h2);
+ private static final Set<Interface> AVALIABLE_INTERFACES =
+ ImmutableSet.of(V100H1, V100H2, V200H1, V200H2, V300H1, V300H2);
- private final Set<Host> avaliableHosts =
- ImmutableSet.of(v100host1, v100host2, v200host1,
- v200host2, v300host1, v300host2, v300host3);
+ private static final Set<Host> AVALIABLE_HOSTS =
+ ImmutableSet.of(V100HOST1, V100HOST2, V200HOST1,
+ V200HOST2, V300HOST1, V300HOST2, V300HOST3);
private ApplicationService applicationService;
private CoreService coreService;
@@ -225,18 +230,22 @@
interfaceService = createMock(InterfaceService.class);
interfaceService.addListener(anyObject(InterfaceListener.class));
expectLastCall().anyTimes();
- addIntfConfig();
+ addIfaceConfig();
- SetMultimap<String, Interface> vplsNetworks =
+ SetMultimap<String, Interface> interfacesByVpls =
HashMultimap.create();
- vplsNetworks.put(NET1, v100h1);
- vplsNetworks.put(NET1, v200h1);
- vplsNetworks.put(NET1, v300h1);
- vplsNetworks.put(NET2, v100h2);
- vplsNetworks.put(NET2, v200h2);
- vplsNetworks.put(NET2, v300h2);
+ interfacesByVpls.put(VPLS1, V100H1);
+ interfacesByVpls.put(VPLS1, V200H1);
+ interfacesByVpls.put(VPLS1, V300H1);
+ interfacesByVpls.put(VPLS2, V100H2);
+ interfacesByVpls.put(VPLS2, V200H2);
+ interfacesByVpls.put(VPLS2, V300H2);
- vplsConfigService = new TestVplsConfigService(vplsNetworks);
+ Map<String, EncapsulationType> encapByVpls = new HashMap<>();
+ encapByVpls.put(VPLS1, VLAN);
+ encapByVpls.put(VPLS2, NONE);
+
+ vplsConfigService = new TestVplsConfigService(interfacesByVpls, encapByVpls);
vpls = new Vpls();
vpls.applicationService = applicationService;
@@ -261,13 +270,13 @@
* an interface on port 1 with vlan 200. On device 5 and 6 is configured
* an interface on port 1 with vlan 300.
*/
- private void addIntfConfig() {
- Set<Interface> interfaces = ImmutableSet.copyOf(avaliableInterfaces);
- Set<Interface> vlanOneSet = ImmutableSet.of(v100h1, v100h2);
- Set<Interface> vlanTwoSet = ImmutableSet.of(v200h1, v200h2);
- Set<Interface> vlanThreeSet = ImmutableSet.of(v300h1, v300h2);
+ private void addIfaceConfig() {
+ Set<Interface> interfaces = ImmutableSet.copyOf(AVALIABLE_INTERFACES);
+ Set<Interface> vlanOneSet = ImmutableSet.of(V100H1, V100H2);
+ Set<Interface> vlanTwoSet = ImmutableSet.of(V200H1, V200H2);
+ Set<Interface> vlanThreeSet = ImmutableSet.of(V300H1, V300H2);
- avaliableInterfaces.forEach(intf -> {
+ AVALIABLE_INTERFACES.forEach(intf -> {
expect(interfaceService.getInterfacesByPort(intf.connectPoint()))
.andReturn(Sets.newHashSet(intf)).anyTimes();
});
@@ -284,41 +293,41 @@
/**
* Six ports are configured with VLANs but no hosts are registered by the
- * HostService. The first three ports have an interface configured on NET1,
- * the other three on NET2. The number of intents expected is six: three for
- * NET1, three for NET2. Six mp2sp intents. Checks if the number of intents
+ * HostService. The first three ports have an interface configured on VPLS 1,
+ * the other three on VPLS 2. The number of intents expected is six: three for
+ * VPLS 1, three for VPLS 2. Six MP2SP intents. Checks if the number of intents
* submitted to the intent framework is equal to the number of intents
* expected and if all intents are equivalent.
*/
@Test
- public void testActivateNoHosts() {
+ public void activateNoHosts() {
vpls.activate();
List<Intent> expectedIntents = Lists.newArrayList();
Set<FilteredConnectPoint> fcPoints;
- fcPoints = buildFCPoints(ImmutableSet.of(v100h1, v200h1, v300h1));
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET1));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H1, V200H1, V300H1));
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS1, VLAN));
- fcPoints = buildFCPoints(ImmutableSet.of(v100h2, v200h2, v300h2));
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET2));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H2, V200H2, V300H2));
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS2, NONE));
checkIntents(expectedIntents);
}
/**
* Six ports are configured with VLANs and six hosts are registered by the
- * HostService. The first three ports have an interface configured on NET1,
- * the other three on NET2. The number of intents expected is twelve: six
- * for VLAN1, six for NET2. six sp2mp intents, six mp2sp intents. For NET1
+ * HostService. The first three ports have an interface configured on VPLS 1,
+ * the other three on VPLS 2. The number of intents expected is twelve: six
+ * for VLAN 1, six for VPLS 2. six sp2mp intents, six mp2sp intents. For VPLS 1
* IPs are added to demonstrate this doesn't influence the number of intents
* created. Checks if the number of intents submitted to the intent
* framework is equal to the number of intents expected and if all intents
* are equivalent.
*/
@Test
- public void testSixInterfacesConfiguredHostsPresent() {
- hostsAvailable.addAll(avaliableHosts);
+ public void sixInterfacesConfiguredHostsPresent() {
+ hostsAvailable.addAll(AVALIABLE_HOSTS);
vpls.activate();
@@ -326,15 +335,15 @@
Set<FilteredConnectPoint> fcPoints;
Set<Host> hosts;
- fcPoints = buildFCPoints(ImmutableSet.of(v100h1, v200h1, v300h1));
- hosts = ImmutableSet.of(v100host1, v200host1, v300host1);
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET1));
- expectedIntents.addAll(generateVplsUni(fcPoints, hosts, NET1));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H1, V200H1, V300H1));
+ hosts = ImmutableSet.of(V100HOST1, V200HOST1, V300HOST1);
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS1, VLAN));
+ expectedIntents.addAll(generateVplsUni(fcPoints, hosts, VPLS1, VLAN));
- fcPoints = buildFCPoints(ImmutableSet.of(v100h2, v200h2, v300h2));
- hosts = ImmutableSet.of(v100host2, v200host2, v300host2);
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET2));
- expectedIntents.addAll(generateVplsUni(fcPoints, hosts, NET2));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H2, V200H2, V300H2));
+ hosts = ImmutableSet.of(V100HOST2, V200HOST2, V300HOST2);
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS2, NONE));
+ expectedIntents.addAll(generateVplsUni(fcPoints, hosts, VPLS2, NONE));
checkIntents(expectedIntents);
}
@@ -342,12 +351,12 @@
/**
* Six ports are configured with VLANs and initially no hosts are registered
* by the HostService. The first three ports have an interface configured on
- * NET1, the other three have an interface configured on NET2. When the
+ * VPLS 1, the other three have an interface configured on VPLS 2. When the
* module starts up, three hosts attached to device one, two and three -
* port 1, are registered by the HostService and events are sent to the
* application. sp2mp intents are created for all interfaces configured and
* mp2sp intents are created only for the hosts attached.
- * The number of intents expected is nine: six for NET1, three for NET2.
+ * The number of intents expected is nine: six for VPLS 1, three for VPLS 2.
* Six sp2mp intents, three mp2sp intents. IPs are added on the first two
* hosts only to demonstrate this doesn't influence the number of intents
* created.
@@ -358,25 +367,25 @@
* to the number of intents expected and if all intents are equivalent.
*/
@Test
- public void testSixInterfacesThreeHostEventsSameVpls() {
+ public void sixInterfacesThreeHostEventsSameVpls() {
vpls.activate();
List<Intent> expectedIntents = Lists.newArrayList();
Set<FilteredConnectPoint> fcPoints;
Set<Host> hosts;
- hostsAvailable.addAll(Sets.newHashSet(v100host1, v200host1, v300host1, v300host3));
+ hostsAvailable.addAll(Sets.newHashSet(V100HOST1, V200HOST1, V300HOST1, V300HOST3));
hostsAvailable.forEach(host ->
hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host)));
- fcPoints = buildFCPoints(ImmutableSet.of(v100h1, v200h1, v300h1));
- hosts = ImmutableSet.of(v100host1, v200host1, v300host1);
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET1));
- expectedIntents.addAll(generateVplsUni(fcPoints, hosts, NET1));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H1, V200H1, V300H1));
+ hosts = ImmutableSet.of(V100HOST1, V200HOST1, V300HOST1);
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS1, VLAN));
+ expectedIntents.addAll(generateVplsUni(fcPoints, hosts, VPLS1, VLAN));
- fcPoints = buildFCPoints(ImmutableSet.of(v100h2, v200h2, v300h2));
- expectedIntents.addAll(generateVplsBrc(fcPoints, NET2));
+ fcPoints = buildFCPoints(ImmutableSet.of(V100H2, V200H2, V300H2));
+ expectedIntents.addAll(generateVplsBrc(fcPoints, VPLS2, NONE));
checkIntents(expectedIntents);
}
@@ -386,10 +395,11 @@
*
* @param fcPoints the filtered connect point
* @param name the name of the VPLS
+ * @param encap the encapsulation type
* @return the list of expected sp2mp intents for the given VPLS
*/
private List<SinglePointToMultiPointIntent>
- generateVplsBrc(Set<FilteredConnectPoint> fcPoints, String name) {
+ generateVplsBrc(Set<FilteredConnectPoint> fcPoints, String name, EncapsulationType encap) {
List<SinglePointToMultiPointIntent> intents = Lists.newArrayList();
fcPoints.forEach(point -> {
@@ -401,7 +411,7 @@
Key brckey = buildKey(PREFIX_BROADCAST,
point.connectPoint(), name, MacAddress.BROADCAST);
- intents.add(buildBrcIntent(brckey, point, otherPoints));
+ intents.add(buildBrcIntent(brckey, point, otherPoints, encap));
});
return intents;
@@ -413,10 +423,12 @@
* @param fcPoints the filtered connect point
* @param hosts the hosts
* @param name the name of the VPLS
+ * @param encap the encapsulation type
* @return the list of expected mp2sp intents for the given VPLS
*/
private List<MultiPointToSinglePointIntent>
- generateVplsUni(Set<FilteredConnectPoint> fcPoints, Set<Host> hosts, String name) {
+ generateVplsUni(Set<FilteredConnectPoint> fcPoints, Set<Host> hosts,
+ String name, EncapsulationType encap) {
List<MultiPointToSinglePointIntent> intents = Lists.newArrayList();
hosts.forEach(host -> {
@@ -430,7 +442,7 @@
Key uniKey = buildKey(PREFIX_UNICAST,
host.location(), name, host.mac());
- intents.add(buildUniIntent(uniKey, otherPoints, hostPoint, host));
+ intents.add(buildUniIntent(uniKey, otherPoints, hostPoint, host, encap));
});
return intents;
@@ -443,19 +455,24 @@
* @param intents the list of intents expected
*/
private void checkIntents(List<Intent> intents) {
- assertEquals(intents.size(), intentService.getIntentCount());
+ assertEquals("The number of intents submitted differs from the number" +
+ "of intents expected",
+ intents.size(), intentService.getIntentCount());
for (Intent intentOne : intents) {
boolean found = false;
for (Intent intentTwo : intentService.getIntents()) {
if (intentOne.key().equals(intentTwo.key())) {
found = true;
- assertTrue(format(COMPARE, intentOne, intentTwo),
+ assertTrue(format("The intent submitted is different from" +
+ "the intent expected",
+ intentOne, intentTwo),
IntentUtils.intentsAreEqual(intentOne, intentTwo));
break;
}
}
- assertTrue(found);
+ assertTrue("The intent submitted is not equal to any of the expected" +
+ "intents", found);
}
}
@@ -468,23 +485,26 @@
* @return the generated single-point to multi-point intent
*/
private SinglePointToMultiPointIntent buildBrcIntent(Key key,
- FilteredConnectPoint src,
- Set<FilteredConnectPoint> dsts) {
- SinglePointToMultiPointIntent intent;
+ FilteredConnectPoint src,
+ Set<FilteredConnectPoint> dsts,
+ EncapsulationType encap) {
+ SinglePointToMultiPointIntent.Builder intentBuilder;
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(MacAddress.BROADCAST)
.build();
- intent = SinglePointToMultiPointIntent.builder()
+ intentBuilder = SinglePointToMultiPointIntent.builder()
.appId(APPID)
.key(key)
.selector(selector)
.filteredIngressPoint(src)
.filteredEgressPoints(dsts)
- .priority(PRIORITY_OFFSET)
- .build();
- return intent;
+ .priority(PRIORITY_OFFSET);
+
+ encap(intentBuilder, encap);
+
+ return intentBuilder.build();
}
/**
@@ -497,22 +517,27 @@
* @return the generated multi-point to single-point intent
*/
private MultiPointToSinglePointIntent buildUniIntent(Key key,
- Set<FilteredConnectPoint> srcs,
- FilteredConnectPoint dst,
- Host host) {
+ Set<FilteredConnectPoint> srcs,
+ FilteredConnectPoint dst,
+ Host host,
+ EncapsulationType encap) {
+ MultiPointToSinglePointIntent.Builder intentBuilder;
+
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(host.mac())
.build();
- return MultiPointToSinglePointIntent.builder()
+ intentBuilder = MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(key)
.selector(selector)
.filteredIngressPoints(srcs)
.filteredEgressPoint(dst)
- .priority(PRIORITY_OFFSET)
- .build();
+ .priority(PRIORITY_OFFSET);
+ encap(intentBuilder, encap);
+
+ return intentBuilder.build();
}
/**
@@ -546,7 +571,7 @@
* @return the set of filtered connect points
*/
private Set<FilteredConnectPoint> buildFCPoints(Set<Interface> interfaces) {
- // Build all filtered connected point in the network
+ // Build all filtered connected point for the VPLS
return interfaces
.stream()
.map(intf -> {
@@ -567,19 +592,19 @@
* Builds an intent Key either for a single-point to multi-point or
* multi-point to single-point intent, based on a prefix that defines
* the intent type, the connection point representing the source or the
- * destination and the VLAN Id representing the network.
+ * destination and the VLAN Id representing the VPLS.
*
* @param prefix the key prefix
* @param cPoint the ingress/egress connect point
- * @param networkName the VPLS name
+ * @param vplsName the VPLS name
* @param hostMac the ingress/egress MAC address
* @return the key to identify the intent
*/
private Key buildKey(String prefix,
ConnectPoint cPoint,
- String networkName,
+ String vplsName,
MacAddress hostMac) {
- String keyString = networkName +
+ String keyString = vplsName +
DASH +
prefix +
DASH +
@@ -593,6 +618,21 @@
}
/**
+ * Adds an encapsulation constraint to the builder given, if encap is not
+ * equal to NONE.
+ *
+ * @param builder the intent builder
+ * @param encap the encapsulation type
+ */
+ private static void encap(ConnectivityIntent.Builder builder,
+ EncapsulationType encap) {
+ if (!encap.equals(NONE)) {
+ builder.constraints(ImmutableList.of(
+ new EncapsulationConstraint(encap)));
+ }
+ }
+
+ /**
* Returns the device Id of the ith device.
*
* @param i the device to get the Id of
@@ -728,63 +768,82 @@
/**
* Represents a fake VplsConfigService class which is needed for testing.
*/
- private class TestVplsConfigService implements VplsConfigurationService {
+ private class TestVplsConfigService extends VplsConfigurationServiceAdapter {
- private final SetMultimap<String, Interface> vplsNetworks;
+ private final SetMultimap<String, Interface> ifacesByVplsName;
+ private final Map<String, EncapsulationType> encapsByVplsName;
+
private Set<String> vplsAffectByApi = new HashSet<>();
- TestVplsConfigService(SetMultimap<String, Interface> vplsNetworks) {
- this.vplsNetworks = vplsNetworks;
+ TestVplsConfigService(SetMultimap<String, Interface> ifacesByVplsName,
+ Map<String, EncapsulationType> encapsByVplsName) {
+ this.ifacesByVplsName = ifacesByVplsName;
+ this.encapsByVplsName = encapsByVplsName;
}
@Override
- public void addVpls(String name, Set<String> ifaces) {
- if (!vplsNetworks.containsKey(name)) {
- ifaces.forEach(iface -> {
- avaliableInterfaces.forEach(intf -> {
- if (intf.name().equals(iface)) {
- vplsNetworks.put(name, intf);
+ public void addVpls(String vplsName, Set<String> ifaceNames, String encap) {
+ if (!ifacesByVplsName.containsKey(vplsName)) {
+ ifaceNames.forEach(ifaceName -> {
+ AVALIABLE_INTERFACES.forEach(iface -> {
+ if (iface.name().equals(ifaceName)) {
+ ifacesByVplsName.put(vplsName, iface);
}
});
});
+ encapsByVplsName.put(vplsName, valueOf(encap));
}
}
@Override
- public void removeVpls(String name) {
- if (vplsNetworks.containsKey(name)) {
- vplsNetworks.removeAll(name);
+ public void removeVpls(String vplsName) {
+ if (ifacesByVplsName.containsKey(vplsName)) {
+ ifacesByVplsName.removeAll(vplsName);
}
}
@Override
- public void addInterfaceToVpls(String name, String iface) {
- if (!vplsNetworks.containsKey(name)) {
- avaliableInterfaces.forEach(intf -> {
+ public void addIface(String vplsName, String iface) {
+ if (!ifacesByVplsName.containsKey(vplsName)) {
+ AVALIABLE_INTERFACES.forEach(intf -> {
if (intf.name().equals(iface)) {
- vplsNetworks.put(name, intf);
+ ifacesByVplsName.put(vplsName, intf);
}
});
}
}
@Override
- public void removeInterfaceFromVpls(String iface) {
- SetMultimap<String, Interface> search = HashMultimap.create(vplsNetworks);
+ public void setEncap(String vplsName, String encap) {
+ encapsByVplsName.put(vplsName, EncapsulationType.enumFromString(encap));
+ }
+
+ @Override
+ public void removeIface(String iface) {
+ SetMultimap<String, Interface> search = HashMultimap.create(ifacesByVplsName);
search.entries().forEach(e -> {
if (e.getValue().name().equals(iface)) {
- vplsNetworks.remove(e.getKey(), iface);
+ ifacesByVplsName.remove(e.getKey(), iface);
}
});
}
@Override
- public void cleanVpls() {
- vplsNetworks.clear();
+ public void cleanVplsConfig() {
+ ifacesByVplsName.clear();
}
@Override
- public Set<String> getVplsAffectedByApi() {
+ public EncapsulationType encap(String vplsName) {
+ EncapsulationType encap = null;
+ if (encapsByVplsName.containsKey(vplsName)) {
+ encap = encapsByVplsName.get(vplsName);
+ }
+ return encap;
+ }
+
+ @Override
+ public Set<String> vplsAffectedByApi() {
Set<String> vplsNames = ImmutableSet.copyOf(vplsAffectByApi);
vplsAffectByApi.clear();
@@ -793,52 +852,50 @@
}
@Override
- public Set<Interface> getAllInterfaces() {
- return vplsNetworks.values()
+ public Set<Interface> allIfaces() {
+ return ifacesByVplsName.values()
.stream()
.collect(Collectors.toSet());
}
@Override
- public Set<Interface> getVplsInterfaces(String name) {
- return vplsNetworks.get(name)
+ public Set<Interface> ifaces(String name) {
+ return ifacesByVplsName.get(name)
.stream()
.collect(Collectors.toSet());
}
@Override
- public Set<String> getAllVpls() {
- return vplsNetworks.keySet();
+ public Set<String> vplsNames() {
+ return ifacesByVplsName.keySet();
}
@Override
- public Set<String> getOldVpls() {
- return vplsNetworks.keySet();
+ public Set<String> vplsNamesOld() {
+ return ifacesByVplsName.keySet();
+ }
+
+ public SetMultimap<String, Interface> ifacesByVplsName() {
+ return ImmutableSetMultimap.copyOf(ifacesByVplsName);
}
@Override
- public SetMultimap<String, Interface> getVplsNetworks() {
- return ImmutableSetMultimap.copyOf(vplsNetworks);
- }
-
- @Override
- public SetMultimap<String, Interface> getVplsNetwork(VlanId vlan,
+ public SetMultimap<String, Interface> ifacesByVplsName(VlanId vlan,
ConnectPoint connectPoint) {
- String vplsNetworkName =
- vplsNetworks.entries().stream()
+ String vplsName =
+ ifacesByVplsName.entries().stream()
.filter(e -> e.getValue().connectPoint().equals(connectPoint))
.filter(e -> e.getValue().vlan().equals(vlan))
.map(e -> e.getKey())
.findFirst()
.orElse(null);
SetMultimap<String, Interface> result = HashMultimap.create();
- if (vplsNetworkName != null && vplsNetworks.containsKey(vplsNetworkName)) {
- vplsNetworks.get(vplsNetworkName)
- .forEach(intf -> result.put(vplsNetworkName, intf));
+ if (vplsName != null && ifacesByVplsName.containsKey(vplsName)) {
+ ifacesByVplsName.get(vplsName)
+ .forEach(intf -> result.put(vplsName, intf));
return result;
}
return null;
}
-
}
}
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsAppConfigTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsAppConfigTest.java
new file mode 100644
index 0000000..d7098e7
--- /dev/null
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsAppConfigTest.java
@@ -0,0 +1,271 @@
+/*
+ * 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.onosproject.vpls.config;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigApplyDelegate;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for the {@link VplsAppConfig} class.
+ */
+public class VplsAppConfigTest {
+ private static final String APP_NAME = "org.onosproject.vpls";
+ private static final ApplicationId APP_ID = new TestApplicationId(APP_NAME);
+ private static final String VPLS = "vplsList";
+ private static final String NAME = "name";
+ private static final String INTERFACE = "interfaces";
+ private static final String ENCAPSULATION = "encapsulation";
+ private static final String VPLS1 = "vpls1";
+ private static final String VPLS2 = "vpls2";
+ private static final String NEWVPLS = "newvpls";
+
+ private static final String IF1 = "sw5-4-100";
+ private static final String IF2 = "sw5-4-200";
+ private static final String IF3 = "sw5-5-100";
+ private static final String IF4 = "sw6-5-100";
+ private static final String IF5 = "sw6-5-400";
+ private static final String IF_NON_EXIST = "sw7-5-100";
+
+ private static final String JSON_TREE = "{\"" + VPLS + "\" : [{\"" + NAME +
+ "\" : \"" + VPLS1 + "\"," + "\"" + INTERFACE + "\" : [" + "\"" +
+ IF1 + "\",\"" + IF2 + "\",\"" + IF3 + "\"]" + ",\"" +
+ ENCAPSULATION + "\" : \"none\"}]}";
+
+ private static final String EMPTY_JSON_TREE = "{}";
+
+ private final ObjectMapper mapper = new ObjectMapper();
+ private final ConfigApplyDelegate delegate = new MockCfgDelegate();
+ private final VplsConfig initialVpls = createInitialVpls();
+
+ private Set<VplsConfig> vplss = new HashSet<>();
+ private VplsAppConfig vplsAppConfig = new VplsAppConfig();
+ private VplsAppConfig emptyVplsAppConfig = new VplsAppConfig();
+
+ @Before
+ public void setUp() throws Exception {
+ JsonNode tree = new ObjectMapper().readTree(JSON_TREE);
+ vplsAppConfig.init(APP_ID, APP_NAME, tree, mapper, delegate);
+ JsonNode emptyTree = new ObjectMapper().readTree(EMPTY_JSON_TREE);
+ emptyVplsAppConfig.init(APP_ID, APP_NAME, emptyTree, mapper, delegate);
+ vplss.add(initialVpls);
+ }
+
+ /**
+ * Tests if a VPLS configuration can be retrieved from JSON.
+ */
+ @Test
+ public void vplss() {
+ assertEquals("Cannot load VPLS configuration or unexpected configuration" +
+ "loaded", vplss, vplsAppConfig.vplss());
+ }
+
+ /**
+ * Tests an empty VPLS application configuration is retrieved from JSON.
+ */
+ @Test
+ public void emptyVplss() {
+ assertTrue("Configuration retrieved from JSON was not empty",
+ emptyVplsAppConfig.vplss().isEmpty());
+ }
+
+ /**
+ * Tests if a VPLS can be found by name. Tries also to find a VPLS that
+ * does not exist in the configuration.
+ */
+ @Test
+ public void getVplsWithName() {
+ assertNotNull("Configuration for VPLS not found",
+ vplsAppConfig.getVplsWithName(VPLS1));
+ assertNull("Unexpected configuration for VPLS found",
+ vplsAppConfig.getVplsWithName(VPLS2));
+ }
+
+ /**
+ * Tests the addition of a new VPLS.
+ */
+ @Test
+ public void addVpls() {
+ int initialSize = vplsAppConfig.vplss().size();
+ VplsConfig newVpls = createNewVpls();
+ vplsAppConfig.addVpls(newVpls);
+ assertEquals("The new VPLS has not been added correctly to the list of" +
+ "existing VPLSs",
+ initialSize + 1,
+ vplsAppConfig.vplss().size());
+ vplss.add(newVpls);
+ }
+
+ /**
+ * Tests the addition of new VPLS to an empty configuration.
+ */
+ @Test
+ public void addVplsToEmpty() {
+ VplsConfig newVpls = createNewVpls();
+ emptyVplsAppConfig.addVpls(newVpls);
+
+ assertFalse("The new VPLS has not been added correctly",
+ emptyVplsAppConfig.vplss().isEmpty());
+ }
+
+ /**
+ * Tests the removal of an existing VPLS from the configuration.
+ */
+ @Test
+ public void removeExistingVpls() {
+ int initialSize = vplsAppConfig.vplss().size();
+ vplsAppConfig.removeVpls(VPLS1);
+
+ assertEquals("The VPLS has not been removed correctly",
+ initialSize - 1, vplsAppConfig.vplss().size());
+ }
+
+ /**
+ * Tests the removal of a non-existing VPLS from the configuration.
+ */
+ @Test
+ public void removeInexistingVpls() {
+ int initialSize = vplsAppConfig.vplss().size();
+ vplsAppConfig.removeVpls(VPLS2);
+
+ assertEquals("Non-configured VPLS has been unexpectedly removed",
+ initialSize, vplsAppConfig.vplss().size());
+ }
+
+ /**
+ * Tests the addition of a new interface.
+ */
+ @Test
+ public void addInterfaceToVpls() {
+ int initialSize = vplsAppConfig.getVplsWithName(VPLS1).ifaces().size();
+ vplsAppConfig.addIface(VPLS1, IF4);
+
+ assertEquals("The interface has not been added to the VPLS",
+ initialSize + 1,
+ vplsAppConfig.getVplsWithName(VPLS1).ifaces().size());
+ }
+
+ /**
+ * Tests the addition of a new interface when it already exists.
+ */
+ @Test
+ public void addExistingInterfaceToVpls() {
+ int initialSize = vplsAppConfig.getVplsWithName(VPLS1).ifaces().size();
+ vplsAppConfig.addIface(VPLS1, IF1);
+
+ assertEquals("The interface has been unexpectedly added twice to the" +
+ "same VPLS",
+ initialSize,
+ vplsAppConfig.getVplsWithName(VPLS1).ifaces().size());
+ }
+
+ /**
+ * Tests the retrieval of a VPLS, given an interface name.
+ */
+ @Test
+ public void getVplsFromInterface() {
+ assertNotNull("VPLS not found", vplsAppConfig.vplsFromIface(IF1));
+ assertNull("VPLS unexpectedly found",
+ vplsAppConfig.vplsFromIface(IF_NON_EXIST));
+ }
+
+ /**
+ * Tests the removal of an interface.
+ */
+ @Test
+ public void removeExistingInterfaceFromVpls() {
+ int initialSize = vplsAppConfig.getVplsWithName(VPLS1).ifaces().size();
+ vplsAppConfig.removeIface(initialVpls, IF1);
+
+ assertEquals("Interface has not been removed correctly from the VPLS",
+ initialSize - 1,
+ vplsAppConfig.getVplsWithName(VPLS1).ifaces().size());
+ }
+
+ /**
+ * Tests the removal of an interface from a VPLS when it does not exist.
+ */
+ @Test
+ public void removeNonExistingInterfaceFromVpls() {
+ int initialSize = vplsAppConfig.getVplsWithName(VPLS1).ifaces().size();
+ vplsAppConfig.removeIface(initialVpls, IF_NON_EXIST);
+
+ assertEquals("Interface unexpectedly removed from the VPLS",
+ initialSize, vplsAppConfig.getVplsWithName(VPLS1).ifaces().size());
+ }
+
+ /**
+ * Tests if the two interfaces are attached to the VPLS, while one of them
+ * is also attached and another.
+ */
+ @Test
+ public void isAttached() {
+ VplsConfig vpls = createNewVpls();
+
+ assertTrue("Interface not correctly attached to the VPLS",
+ vpls.isAttached(IF4));
+ assertFalse("Unexpected interface attached to the VPLS",
+ vpls.isAttached(IF_NON_EXIST));
+ }
+
+ /**
+ * Tests if encapsulation is set correctly.
+ */
+ @Test
+ public void encap() {
+ vplsAppConfig.setEncap(VPLS1, EncapsulationType.VLAN);
+ assertEquals("Wrong encapsulation type found",
+ EncapsulationType.VLAN,
+ vplsAppConfig.getVplsWithName(VPLS1).encap());
+ }
+
+ private class MockCfgDelegate implements ConfigApplyDelegate {
+
+ @Override
+ public void onApply(@SuppressWarnings("rawtypes") Config config) {
+ config.apply();
+ }
+
+ }
+
+ private VplsConfig createInitialVpls() {
+ Set<String> ifaces = new HashSet<>(Arrays.asList(IF1, IF2, IF3));
+
+ return new VplsConfig(VPLS1, ifaces, EncapsulationType.NONE);
+ }
+
+ private VplsConfig createNewVpls() {
+ Set<String> ifaces = new HashSet<>(Arrays.asList(IF4, IF5));
+
+ return new VplsConfig(NEWVPLS, ifaces, EncapsulationType.NONE);
+ }
+}
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsConfigTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsConfigTest.java
deleted file mode 100644
index 6ef0284..0000000
--- a/apps/vpls/src/test/java/org/onosproject/vpls/config/VplsConfigTest.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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.onosproject.vpls.config;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.config.Config;
-import org.onosproject.net.config.ConfigApplyDelegate;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for the {@link VplsConfig} class.
- */
-public class VplsConfigTest {
- private static final String APP_NAME = "org.onosproject.vpls";
- private static final ApplicationId APP_ID = new TestApplicationId(APP_NAME);
- private static final String VPLS = "vplsNetworks";
- private static final String NAME = "name";
- private static final String INTERFACE = "interfaces";
- private static final String NET1 = "net1";
- private static final String NET2 = "net2";
- private static final String NEWNET = "newnet";
-
- private static final String IF1 = "sw5-4-100";
- private static final String IF2 = "sw5-4-200";
- private static final String IF3 = "sw5-5-100";
- private static final String IF4 = "sw6-5-100";
- private static final String IF5 = "sw6-5-400";
- private static final String IF_NON_EXIST = "sw7-5-100";
-
- private static final String JSON_TREE = "{\"" + VPLS +
- "\" : [{\"" + NAME + "\" : \"net1\"," +
- "\"" + INTERFACE + "\" : [" +
- "\"sw5-4-100\",\"sw5-4-200\",\"sw5-5-100\"]}]}";
- private static final String EMPTY_JSON_TREE = "{}";
-
- private final ObjectMapper mapper = new ObjectMapper();
- private final ConfigApplyDelegate delegate = new MockCfgDelegate();
- private final VplsNetworkConfig initialNetwork = createInitialNetwork();
-
- private Set<VplsNetworkConfig> networks = new HashSet<>();
- private VplsConfig vplsConfig = new VplsConfig();
- private VplsConfig emptyVplsConfig = new VplsConfig();
-
- @Before
- public void setUp() throws Exception {
- JsonNode tree = new ObjectMapper().readTree(JSON_TREE);
- vplsConfig.init(APP_ID, APP_NAME, tree, mapper, delegate);
- JsonNode emptyTree = new ObjectMapper().readTree(EMPTY_JSON_TREE);
- emptyVplsConfig.init(APP_ID, APP_NAME, emptyTree, mapper, delegate);
- networks.add(initialNetwork);
- }
-
- /**
- * Tests if a VPLS configuration can be retrieved from JSON.
- */
- @Test
- public void testVplsNetworks() {
- assertEquals(networks, vplsConfig.vplsNetworks());
- }
-
- /**
- * Tests an empty VPLS application configuration is retrieved from JSON.
- */
- @Test
- public void testEmptyVplsNetworks() {
- assertTrue(emptyVplsConfig.vplsNetworks().isEmpty());
- }
-
- /**
- * Tests if a VPLS can be found by name.
- */
- @Test
- public void testGetVplsWithName() {
- assertNotNull(vplsConfig.getVplsWithName(NET1));
- assertNull(vplsConfig.getVplsWithName(NET2));
- }
-
- /**
- * Tests the addition of a new VPLS.
- */
- @Test
- public void testAddNetwork() {
- int initialSize = vplsConfig.vplsNetworks().size();
- VplsNetworkConfig newNetwork = createNewNetwork();
- vplsConfig.addVpls(newNetwork);
- assertEquals(initialSize + 1, vplsConfig.vplsNetworks().size());
- networks.add(newNetwork);
- assertEquals(networks, vplsConfig.vplsNetworks());
- }
-
- /**
- * Tests the addition of new VPLS to an empty configuration.
- */
- @Test
- public void testAddNetworkToEmpty() {
- VplsNetworkConfig newNetwork = createNewNetwork();
- emptyVplsConfig.addVpls(newNetwork);
-
- assertFalse(emptyVplsConfig.vplsNetworks().isEmpty());
- }
-
- /**
- * Tests the removal of an existing VPLS from the configuration.
- */
- @Test
- public void testRemoveExistingNetwork() {
- int initialSize = vplsConfig.vplsNetworks().size();
- vplsConfig.removeVpls(NET1);
-
- assertEquals(initialSize - 1, vplsConfig.vplsNetworks().size());
- }
-
- /**
- * Tests the removal of a non-existing VPLS from the configuration.
- */
- @Test
- public void testRemoveInexistingNetwork() {
- int initialSize = vplsConfig.vplsNetworks().size();
- vplsConfig.removeVpls(NET2);
-
- assertEquals(initialSize, vplsConfig.vplsNetworks().size());
- }
-
- /**
- * Tests the addition of a new interface.
- */
- @Test
- public void testAddInterfaceToNetwork() {
- int initialSize = vplsConfig.getVplsWithName(NET1).ifaces().size();
- vplsConfig.addInterfaceToVpls(NET1, IF4);
-
- assertEquals(initialSize + 1, vplsConfig.getVplsWithName(NET1).ifaces().size());
- }
-
- /**
- * Tests the addition of a new interface when it already exists.
- */
- @Test
- public void testAddExistingInterfaceToNetwork() {
- int initialSize = vplsConfig.getVplsWithName(NET1).ifaces().size();
- vplsConfig.addInterfaceToVpls(NET1, IF1);
-
- assertEquals(initialSize, vplsConfig.getVplsWithName(NET1).ifaces().size());
- }
-
- /**
- * Tests the retrieval of a VPLS, given an interface name.
- */
- @Test
- public void testgetNetworkFromInterface() {
- assertNotNull(vplsConfig.getVplsFromInterface(IF1));
- assertNull(vplsConfig.getVplsFromInterface(IF_NON_EXIST));
- }
-
- /**
- * Tests the removal of an interface.
- */
- @Test
- public void testRemoveExistingInterfaceFromNetwork() {
- int initialSize = vplsConfig.getVplsWithName(NET1).ifaces().size();
- vplsConfig.removeInterfaceFromVpls(initialNetwork, IF1);
-
- assertEquals(initialSize - 1, vplsConfig.getVplsWithName(NET1).ifaces().size());
- }
-
- /**
- * Tests the removal of an interface from a VPLS when it does not exist.
- */
- @Test
- public void testRemoveNonExistingInterfaceFromNetwork() {
- int initialSize = vplsConfig.getVplsWithName(NET1).ifaces().size();
- vplsConfig.removeInterfaceFromVpls(initialNetwork, IF_NON_EXIST);
-
- assertEquals(initialSize, vplsConfig.getVplsWithName(NET1).ifaces().size());
- }
-
- /**
- * Tests if the two interfaces are attached to the network
- * while one of the interface is attached and another one is not.
- */
- @Test
- public void testIsAttached() {
- VplsNetworkConfig network = createNewNetwork();
-
- assertTrue(network.isAttached(IF4));
- assertFalse(network.isAttached(IF_NON_EXIST));
- }
-
- private class MockCfgDelegate implements ConfigApplyDelegate {
-
- @Override
- public void onApply(@SuppressWarnings("rawtypes") Config config) {
- config.apply();
- }
-
- }
-
- private VplsNetworkConfig createInitialNetwork() {
- Set<String> ifaces = new HashSet<>(Arrays.asList(IF1, IF2, IF3));
-
- return new VplsNetworkConfig(NET1, ifaces);
- }
-
- private VplsNetworkConfig createNewNetwork() {
- Set<String> ifaces = new HashSet<>(Arrays.asList(IF4, IF5));
-
- return new VplsNetworkConfig(NEWNET, ifaces);
- }
-}