use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class SimpleDeviceStore method createOrUpdateDevice.
@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptions(deviceId);
synchronized (providerDescs) {
// locking per device
DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(providerDescs, providerId, deviceDescription);
Device oldDevice = devices.get(deviceId);
// update description
descs.putDeviceDesc(deviceDescription);
Device newDevice = composeDevice(deviceId, providerDescs);
DeviceEvent event = null;
if (oldDevice == null) {
// ADD
event = createDevice(providerId, newDevice);
} else {
// UPDATE or ignore (no change or stale)
event = updateDevice(providerId, oldDevice, newDevice);
}
notifyDelegateIfNotNull(event);
return event;
}
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class SimpleDeviceStore method removeDevice.
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId);
synchronized (descs) {
Device device = devices.remove(deviceId);
// should DEVICE_REMOVED carry removed ports?
Map<PortNumber, Port> ports = devicePorts.get(deviceId);
if (ports != null) {
ports.clear();
}
availableDevices.remove(deviceId);
descs.clear();
return device == null ? null : new DeviceEvent(DEVICE_REMOVED, device, null);
}
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class DefaultTopologyTest method setUp.
@Before
public void setUp() {
long now = System.currentTimeMillis();
Set<Device> devices = of(device("1"), device("2"), device("3"), device("4"), device("5"));
Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1), link("3", 2, "2", 2), link("2", 2, "3", 2), link("1", 3, "4", 3), link("4", 3, "1", 3), link("3", 4, "4", 4), link("4", 4, "3", 4));
GraphDescription graphDescription = new DefaultGraphDescription(now, System.currentTimeMillis(), devices, links);
dt = new DefaultTopology(PID, graphDescription);
assertEquals("incorrect supplier", PID, dt.providerId());
assertEquals("incorrect time", now, dt.time());
assertEquals("incorrect device count", 5, dt.deviceCount());
assertEquals("incorrect link count", 8, dt.linkCount());
assertEquals("incorrect cluster count", 2, dt.clusterCount());
assertEquals("incorrect broadcast set size", 6, dt.broadcastSetSize(C0));
assertEquals("incorrect root node", V1, dt.getCluster(C0).root());
assertEquals("incorrect root node", V5, dt.getCluster(C1).root());
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class CzechLightDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("Cannot request NETCONF session for {}", data().deviceId());
return null;
}
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
try {
Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
if (!data.containsKey(YANGLIB_KEY_REVISION)) {
log.error("Not talking to a supported CzechLight device, is that a teapot?");
return noDevice;
}
final var revision = data.getString(YANGLIB_KEY_REVISION);
if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
return noDevice;
}
final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
if (!isLineDegree && !isAddDrop) {
log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
return noDevice;
}
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
return noDevice;
}
isCoherentAddDrop = true;
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
if (!revision.equals(MOD_INLINE_AMP_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
return noDevice;
}
isInlineAmp = true;
}
if (isLineDegree) {
log.info("Talking to a Line/Degree ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
} else if (isAddDrop) {
log.info("Talking to an Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
} else if (isCoherentAddDrop) {
log.info("Talking to a Coherent Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
} else if (isInlineAmp) {
log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
} else {
log.error("Device type not recognized");
return noDevice;
}
} catch (NetconfException e) {
log.error("Cannot request ietf-yang-library data", e);
return noDevice;
}
// FIXME: initialize these
String vendor = "CzechLight";
String hwVersion = "n/a";
String swVersion = "n/a";
String serialNumber = "n/a";
ChassisId chassisId = null;
return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class LinkDiscoveryCiscoImpl method getLinks.
@Override
public Set<LinkDescription> getLinks() {
String response = retrieveResponse(SHOW_LLDP_NEIGHBOR_DETAIL_CMD);
DeviceId localDeviceId = this.handler().data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
Set<LinkDescription> linkDescriptions = Sets.newHashSet();
List<Port> ports = deviceService.getPorts(localDeviceId);
if (ports.size() == 0 || Objects.isNull(response)) {
return linkDescriptions;
}
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
if (json == null) {
return linkDescriptions;
}
JsonNode res = json.at("/" + JSON_RESULT);
if (res.isMissingNode()) {
return linkDescriptions;
}
JsonNode lldpNeighborsRow = res.at("/" + TABLE_NBOR_DETAIL);
if (lldpNeighborsRow.isMissingNode()) {
return linkDescriptions;
}
JsonNode lldpNeighbors = lldpNeighborsRow.at("/" + ROW_NBOR_DETAIL);
if (lldpNeighbors.isMissingNode()) {
return linkDescriptions;
}
Iterator<JsonNode> iterator = lldpNeighbors.elements();
while (iterator.hasNext()) {
JsonNode neighbors = iterator.next();
String remoteChassisId = neighbors.get(CHASSIS_ID).asText();
String remotePortName = neighbors.get(PORT_ID).asText();
String remotePortDesc = neighbors.get(PORT_DESC).asText();
String lldpLocalPort = neighbors.get(LOCAL_PORT_ID).asText().replaceAll("(Eth.{0,5})(.\\d{0,5}/\\d{0,5})", "Ethernet$2");
Port localPort = findLocalPortByName(ports, lldpLocalPort);
if (localPort == null) {
log.warn("local port not found. LldpLocalPort value: {}", lldpLocalPort);
continue;
}
Device remoteDevice = findRemoteDeviceByChassisId(deviceService, remoteChassisId);
Port remotePort = findDestinationPortByName(remotePortName, remotePortDesc, deviceService, remoteDevice);
if (!localPort.isEnabled() || !remotePort.isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort, remoteDevice.id(), remotePort);
continue;
}
linkDescriptions.addAll(buildLinkPair(localDeviceId, localPort, remoteDevice.id(), remotePort));
}
} catch (IOException e) {
log.error("Failed to get links ", e);
}
log.debug("Returning linkDescriptions: {}", linkDescriptions);
return linkDescriptions;
}
Aggregations