use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class InterfaceConfigTest method testConstruction.
/**
* Tests construction, setters and getters of an InterfaceConfig object.
*/
@Test
public void testConstruction() throws Exception {
InterfaceConfig config = new InterfaceConfig();
config.init(cp1, "KEY", data, mapper, delegate);
assertThat(config.isValid(), is(true));
assertThat(config.getInterfaces(), hasSize(4));
Interface fetchedInterface1 = findInterface(config.getInterfaces(), name1);
checkInterface(fetchedInterface1, 1);
assertThat(fetchedInterface1.vlan(), is(vl1));
Interface fetchedInterface2 = findInterface(config.getInterfaces(), name2);
checkInterface(fetchedInterface2, 2);
assertThat(fetchedInterface2.vlanUntagged().toShort(), is((short) 22));
assertThat(fetchedInterface2.vlan().toShort(), is((short) 2));
Interface fetchedInterface3 = findInterface(config.getInterfaces(), name3);
checkInterface(fetchedInterface3, 3);
assertThat(fetchedInterface3.vlanTagged(), is(allOf(notNullValue(), hasSize(1))));
assertThat(fetchedInterface3.vlan().toShort(), is((short) 3));
assertThat(fetchedInterface3.vlanTagged(), contains(VlanId.vlanId((short) 33)));
Interface fetchedInterface4 = findInterface(config.getInterfaces(), name4);
checkInterface(fetchedInterface4, 4);
assertThat(fetchedInterface4.vlanTagged(), is(allOf(notNullValue(), hasSize(1))));
assertThat(fetchedInterface4.vlanTagged(), contains(VlanId.vlanId((short) 44)));
assertThat(fetchedInterface4.vlanNative().toShort(), is((short) 4));
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsWebResource method addInterfaces.
/**
* Add new interfaces. Add new interfaces to a Vpls.<br>
*
* @param stream interfaces JSON
* @param vplsName Vpls name
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel InterfacesPost
*/
@POST
@Path("interfaces/{vplsName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addInterfaces(@PathParam("vplsName") String vplsName, InputStream stream) {
Vpls service = get(Vpls.class);
DeviceService deviceService = get(DeviceService.class);
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName), VPLS_NOT_FOUND + vplsName);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(INTERFACES), INTERFACES_KEY_ERROR);
Collection<Interface> interfaceList = new ArrayList<>();
routesArray.forEach(interfJson -> {
Interface inter = codec(Interface.class).decode((ObjectNode) interfJson, this);
nullIsNotFound(deviceService.getDevice(inter.connectPoint().deviceId()), DEVICE_NOT_FOUND + inter.connectPoint().deviceId());
nullIsNotFound(deviceService.getPort(inter.connectPoint()), PORT_NOT_FOUND + inter.connectPoint().port());
interfaceList.add(inter);
interfaceService.add(inter);
});
service.addInterfaces(vplsData, interfaceList);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(INTERFACES).path(vplsName);
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsCommand method addIface.
/**
* Adds an inteterface to a VPLS.
*
* @param vplsName the name of the VLPS
* @param ifaceName the name of the interface to add
*/
protected void addIface(String vplsName, String ifaceName) {
if (vplsName == null) {
print(INSERT_VPLS_NAME);
return;
}
if (ifaceName == null) {
print(INSERT_INTERFACE);
return;
}
Interface iface = getInterface(ifaceName);
VplsData vplsData = vpls.getVpls(vplsName);
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 (isIfaceAssociated(iface)) {
print(IFACE_ALREADY_ASSOCIATED, ifaceName, getVplsByInterface(iface).name());
return;
}
vpls.addInterface(vplsData, iface);
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsConfigManager method reloadConfiguration.
/**
* Retrieves the VPLS configuration from network configuration.
* Checks difference between new configuration and old configuration.
*/
private synchronized void reloadConfiguration() {
VplsAppConfig vplsAppConfig = configService.getConfig(appId, VplsAppConfig.class);
if (vplsAppConfig == null) {
log.warn(CONFIG_NULL);
// If the config is null, removes all VPLS.
vpls.removeAllVpls();
return;
}
// If there exists a update time in the configuration; it means the
// configuration was pushed by VPLS store; ignore this configuration.
long updateTime = vplsAppConfig.updateTime();
if (updateTime != -1L) {
return;
}
Collection<VplsData> oldVplses = vpls.getAllVpls();
Collection<VplsData> newVplses;
// Generates collection of new VPLSs
newVplses = vplsAppConfig.vplss().stream().map(vplsConfig -> {
Set<Interface> interfaces = vplsConfig.ifaces().stream().map(this::getInterfaceByName).filter(Objects::nonNull).collect(Collectors.toSet());
VplsData vplsData = VplsData.of(vplsConfig.name(), vplsConfig.encap());
vplsData.addInterfaces(interfaces);
return vplsData;
}).collect(Collectors.toSet());
if (newVplses.containsAll(oldVplses) && oldVplses.containsAll(newVplses)) {
// no update, ignore
return;
}
// To add or update
newVplses.forEach(newVplsData -> {
boolean vplsExists = false;
for (VplsData oldVplsData : oldVplses) {
if (oldVplsData.name().equals(newVplsData.name())) {
vplsExists = true;
// VPLS exists; but need to be updated.
if (!oldVplsData.equals(newVplsData)) {
// Update VPLS
Set<Interface> newInterfaces = newVplsData.interfaces();
Set<Interface> oldInterfaces = oldVplsData.interfaces();
Set<Interface> ifaceToAdd = newInterfaces.stream().filter(iface -> !oldInterfaces.contains(iface)).collect(Collectors.toSet());
Set<Interface> ifaceToRem = oldInterfaces.stream().filter(iface -> !newInterfaces.contains(iface)).collect(Collectors.toSet());
vpls.addInterfaces(oldVplsData, ifaceToAdd);
vpls.removeInterfaces(oldVplsData, ifaceToRem);
vpls.setEncapsulationType(oldVplsData, newVplsData.encapsulationType());
}
}
}
// VPLS not exist; add new VPLS
if (!vplsExists) {
vpls.createVpls(newVplsData.name(), newVplsData.encapsulationType());
vpls.addInterfaces(newVplsData, newVplsData.interfaces());
}
});
// VPLS not exists in old VPLS configuration; remove it.
Set<VplsData> vplsToRemove = Sets.newHashSet();
oldVplses.forEach(oldVpls -> {
Set<String> newVplsNames = newVplses.stream().map(VplsData::name).collect(Collectors.toSet());
if (!newVplsNames.contains(oldVpls.name())) {
// To avoid ConcurrentModificationException; do remove after this
// iteration.
vplsToRemove.add(oldVpls);
}
});
vplsToRemove.forEach(vpls::removeVpls);
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class VplsNeighbourHandler method findVpls.
/**
* Finds the VPLS with given neighbour message context.
*
* @param context the neighbour message context
* @return the VPLS for specific neighbour message context
*/
private VplsData findVpls(NeighbourMessageContext context) {
Collection<VplsData> vplses = vplsStore.getAllVpls();
for (VplsData vplsData : vplses) {
Set<Interface> interfaces = vplsData.interfaces();
ConnectPoint port = context.inPort();
VlanId vlanId = context.vlan();
boolean match = interfaces.stream().anyMatch(iface -> iface.connectPoint().equals(port) && iface.vlan().equals(vlanId));
if (match) {
return vplsData;
}
}
return null;
}
Aggregations