use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class DistributedHostStore method createOrUpdateHost.
// TODO No longer need to return HostEvent
@Override
public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, HostDescription hostDescription, boolean replaceIPs) {
hostsConsistentMap.computeIf(hostId, existingHost -> shouldUpdate(existingHost, providerId, hostDescription, replaceIPs), (id, existingHost) -> {
final Set<IpAddress> addresses;
if (existingHost == null || replaceIPs) {
addresses = ImmutableSet.copyOf(hostDescription.ipAddress());
} else {
addresses = Sets.newHashSet(existingHost.ipAddresses());
addresses.addAll(hostDescription.ipAddress());
}
final Annotations annotations;
if (existingHost != null) {
annotations = merge((DefaultAnnotations) existingHost.annotations(), hostDescription.annotations());
} else {
annotations = hostDescription.annotations();
}
return new DefaultHost(providerId, hostId, hostDescription.hwAddress(), hostDescription.vlan(), hostDescription.locations(), hostDescription.auxLocations(), addresses, hostDescription.innerVlan(), hostDescription.tpid(), hostDescription.configured(), false, annotations);
});
return null;
}
use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfigTest method testSetControllers.
/**
* Run to verify handling of valid set operation.
*/
@Test
public void testSetControllers() throws Exception {
List<ControllerInfo> controllers = new ArrayList<>();
for (int i = ZERO; i < SET_CONTROLLERS.length; i++) {
String target = SET_CONTROLLERS[i];
String[] data = target.split(TEST_COLON);
currentKey = i + ONE;
Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
controllers.add(controller);
}
voltConfig.setControllers(controllers);
}
use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfigTest method testGetControllers.
/**
* Run to verify handling of valid get operation.
*/
@Test
public void testGetControllers() throws Exception {
List<ControllerInfo> controllers;
List<ControllerInfo> expectedControllers = new ArrayList<>();
for (int i = ZERO; i < GET_CONTROLLERS.length; i++) {
String target = GET_CONTROLLERS[i];
String[] data = target.split(TEST_COLON);
currentKey = i + ONE;
Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
expectedControllers.add(controller);
}
controllers = voltConfig.getControllers();
assertTrue("Incorrect response", controllers.equals(expectedControllers));
}
use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class OchPortHelper method asOchPort.
public static Optional<OchPort> asOchPort(Port port) {
if (port instanceof OchPort) {
return Optional.of((OchPort) port);
}
try {
Annotations an = port.annotations();
OduSignalType signalType = Enum.valueOf(OduSignalType.class, an.value(SIGNAL_TYPE));
boolean isTunable = Boolean.valueOf(an.value(TUNABLE));
ObjectNode obj = (ObjectNode) MAPPER.readTree(an.value(LAMBDA));
OchSignal lambda = OchSignalCodec.decode(obj);
// DefaultOchPort should filter them, if necessary.
return Optional.of(new DefaultOchPort(port, signalType, isTunable, lambda));
// TODO: it'll be better to verify each inputs properly
// instead of catching all these Exceptions.
} catch (IOException | NullPointerException | IllegalArgumentException | ClassCastException e) {
log.warn("{} was not well-formed OCh port.", port, e);
return Optional.empty();
}
}
use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class OduCltPortHelper method asOduCltPort.
public static Optional<OduCltPort> asOduCltPort(Port port) {
if (port instanceof OduCltPort) {
return Optional.of((OduCltPort) port);
}
try {
Annotations an = port.annotations();
CltSignalType signalType = Enum.valueOf(CltSignalType.class, an.value(SIGNAL_TYPE));
// DefaultOduCltPort should filter them, if necessary.
return Optional.of(new DefaultOduCltPort(port, signalType));
} catch (NullPointerException | IllegalArgumentException e) {
log.warn("{} was not well-formed OduClt port.", port, e);
return Optional.empty();
}
}
Aggregations