use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsCommand method removeIface.
/**
* Removes an interface from a VPLS.
*
* @param vplsName the name of the VLPS
* @param ifaceName the name of the interface to remove
*/
protected void removeIface(String vplsName, String ifaceName) {
if (vplsName == null) {
print(INSERT_VPLS_NAME);
return;
}
if (ifaceName == null) {
print(INSERT_INTERFACE);
return;
}
VplsData vplsData = vpls.getVpls(vplsName);
Interface iface = getInterface(ifaceName);
if (vplsData == null) {
print(VPLS_NOT_FOUND, vplsName);
return;
}
if (CHANGING_STATE.contains(vplsData.state())) {
// when a VPLS is updating, we shouldn't try modify it.
print("VPLS %s still updating, please wait it finished", vplsData.name());
return;
}
if (iface == null) {
print(IFACE_NOT_FOUND, ifaceName);
return;
}
if (!vplsData.interfaces().contains(iface)) {
print(IFACE_NOT_ASSOCIATED, ifaceName, vplsName);
return;
}
vpls.removeInterface(vplsData, iface);
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class InterfaceConfigTest method testAddRemoveInterface.
@Test
public void testAddRemoveInterface() throws Exception {
InterfaceConfig config = new InterfaceConfig();
config.init(cp1, "KEY", data, mapper, delegate);
Set<VlanId> vlanTagged = ImmutableSet.of(VlanId.vlanId((short) 33), VlanId.vlanId((short) 44));
String newName = "interface5";
Interface toAdd1 = new Interface(newName, cp1, ImmutableList.of(getIp(5, 1), getIp(5, 2)), getMac(5), vl1, null, vlanTagged, vl1);
config.addInterface(toAdd1);
assertThat(config.isValid(), is(true));
assertThat(config.getInterfaces(), allOf(notNullValue(), hasSize(5)));
assertThat(findInterface(config.getInterfaces(), name1), notNullValue());
assertThat(findInterface(config.getInterfaces(), name2), notNullValue());
assertThat(findInterface(config.getInterfaces(), name3), notNullValue());
Interface addedInterface1 = findInterface(config.getInterfaces(), newName);
checkInterface(addedInterface1, 5);
assertThat(addedInterface1.vlan(), is(vl1));
assertThat(addedInterface1.vlanTagged(), allOf(notNullValue(), hasSize(2)));
config.removeInterface(newName);
assertThat(config.getInterfaces(), allOf(notNullValue(), hasSize(4)));
assertThat(findInterface(config.getInterfaces(), newName), nullValue());
newName = getName(6);
Interface toAdd2 = new Interface(newName, cp1, ImmutableList.of(getIp(6, 1), getIp(6, 2)), getMac(6), vl1, VlanId.vlanId((short) 77), null, vl1);
config.addInterface(toAdd2);
Interface addedInterface2 = findInterface(config.getInterfaces(), newName);
checkInterface(addedInterface2, 6);
assertThat(addedInterface2.vlan(), is(vl1));
assertThat(addedInterface2.vlanUntagged().toShort(), is((short) 77));
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsIntentUtility method buildUniIntents.
/**
* Builds unicast Intents for a VPLS.
*
* @param vplsData the VPLS
* @param hosts the hosts of the VPLS
* @param appId application ID for Intents
* @return unicast Intents for the VPLS
*/
public static Set<Intent> buildUniIntents(VplsData vplsData, Set<Host> hosts, ApplicationId appId) {
Set<Interface> interfaces = vplsData.interfaces();
if (interfaces.size() < 2) {
return ImmutableSet.of();
}
Set<Intent> uniIntents = Sets.newHashSet();
ResourceGroup resourceGroup = ResourceGroup.of(vplsData.name());
hosts.forEach(host -> {
FilteredConnectPoint hostFcp = buildFilteredConnectedPoint(host);
Set<FilteredConnectPoint> srcFcps = interfaces.stream().map(VplsIntentUtility::buildFilteredConnectedPoint).filter(fcp -> !fcp.equals(hostFcp)).collect(Collectors.toSet());
Key key = buildKey(PREFIX_UNICAST, hostFcp.connectPoint(), vplsData.name(), host.mac(), appId);
Intent uniIntent = buildUniIntent(key, appId, srcFcps, hostFcp, host, vplsData.encapsulationType(), resourceGroup);
uniIntents.add(uniIntent);
});
return uniIntents;
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsIntentUtility method buildBrcIntents.
/**
* Builds broadcast Intents for a VPLS.
*
* @param vplsData the VPLS
* @param appId the application id for Intents
* @return broadcast Intents for the VPLS
*/
public static Set<Intent> buildBrcIntents(VplsData vplsData, ApplicationId appId) {
Set<Interface> interfaces = vplsData.interfaces();
// At least two or more network interfaces to build broadcast Intents
if (interfaces.size() < 2) {
return ImmutableSet.of();
}
Set<Intent> brcIntents = Sets.newHashSet();
ResourceGroup resourceGroup = ResourceGroup.of(vplsData.name());
// Generates broadcast Intents from any network interface to other
// network interface from the VPLS.
interfaces.forEach(src -> {
FilteredConnectPoint srcFcp = VplsIntentUtility.buildFilteredConnectedPoint(src);
Set<FilteredConnectPoint> dstFcps = interfaces.stream().filter(iface -> !iface.equals(src)).map(VplsIntentUtility::buildFilteredConnectedPoint).collect(Collectors.toSet());
Key key = VplsIntentUtility.buildKey(PREFIX_BROADCAST, srcFcp.connectPoint(), vplsData.name(), MacAddress.BROADCAST, appId);
Intent brcIntent = buildBrcIntent(key, appId, srcFcp, dstFcps, vplsData.encapsulationType(), resourceGroup);
brcIntents.add(brcIntent);
});
return brcIntents;
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsCodec method decode.
@Override
public VplsData decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
List<String> names = new ArrayList<>();
json.findValues(NAME).forEach(jsonNode -> {
names.add(jsonNode.asText());
});
Collection<Interface> interfaceList = new ArrayList<>();
JsonNode interfacesJeson = json.findValue(INTERFACES);
JsonCodec<Interface> interfaceCodec = context.codec(Interface.class);
if (interfacesJeson != null) {
IntStream.range(0, interfacesJeson.size()).forEach(i -> interfaceList.add(interfaceCodec.decode(get(interfacesJeson, i), context)));
}
interfaceList.forEach(interf -> {
names.remove(interf.name());
});
String vplsName = names.get(0);
EncapsulationType encap = json.findValue(ENCAPSULATION_TYPE) == null ? null : EncapsulationType.enumFromString(json.findValue(ENCAPSULATION_TYPE).asText());
VplsData vplsData = VplsData.of(vplsName, encap);
vplsData.addInterfaces(interfaceList);
return vplsData;
}
Aggregations