use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class LinkDiscovery method processLldp.
private boolean processLldp(PacketContext packetContext, Ethernet eth) {
ONOSLLDP onoslldp = ONOSLLDP.parseLLDP(eth);
if (onoslldp != null) {
Type lt = eth.getEtherType() == Ethernet.TYPE_LLDP ? Type.DIRECT : Type.INDIRECT;
DeviceService deviceService = context.deviceService();
MacAddress srcChassisId = onoslldp.getChassisIdByMac();
String srcPortName = onoslldp.getPortNameString();
String srcPortDesc = onoslldp.getPortDescString();
log.debug("srcChassisId:{}, srcPortName:{}, srcPortDesc:{}", srcChassisId, srcPortName, srcPortDesc);
if (srcChassisId == null && srcPortDesc == null) {
log.warn("there are no valid port id");
return false;
}
Optional<Device> srcDevice = findSourceDeviceByChassisId(deviceService, srcChassisId);
if (!srcDevice.isPresent()) {
log.debug("source device not found. srcChassisId value: {}", srcChassisId);
return false;
}
Optional<Port> sourcePort = findSourcePortByName(srcPortName == null ? srcPortDesc : srcPortName, deviceService, srcDevice.get());
if (!sourcePort.isPresent()) {
log.debug("source port not found. sourcePort value: {}", sourcePort);
return false;
}
PortNumber srcPort = sourcePort.get().number();
PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
DeviceId srcDeviceId = srcDevice.get().id();
DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
if (!sourcePort.get().isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", srcDeviceId, sourcePort.get(), dstDeviceId, dstPort);
return false;
}
ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).set(AnnotationKeys.LAYER, ETHERNET).build();
LinkDescription ld = new DefaultLinkDescription(src, dst, lt, true, annotations);
try {
context.providerService().linkDetected(ld);
context.setTtl(LinkKey.linkKey(src, dst), onoslldp.getTtlBySeconds());
} catch (IllegalStateException e) {
log.debug("There is a exception during link creation: {}", e);
return true;
}
return true;
}
return false;
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class NetconfDeviceProvider method getDeviceRepresentation.
private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config, DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
DeviceDescription existingOrEmptyDescription = existingOrEmptyDescription(deviceId, config);
DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
if (newDescription == null) {
return existingOrEmptyDescription;
}
// merging and returning
return new DefaultDeviceDescription(newDescription, true, DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(), existingOrEmptyDescription.annotations()));
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class PolatisDeviceDescription method discoverPortDetails.
/**
* Discovers port details, for Polatis Snmp device.
*
* @return port list
*/
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = Lists.newArrayList();
List<TableEvent> events;
DeviceId deviceId = handler().data().deviceId();
try {
OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
events = getTable(handler(), columnOIDs);
} catch (IOException e) {
log.error("Error reading ports table for device {} exception {}", deviceId, e);
return ports;
}
if (events == null) {
log.error("Error reading ports table for device {}", deviceId);
return ports;
}
for (TableEvent event : events) {
if (event == null) {
log.error("Error reading event for device {}", deviceId);
continue;
}
VariableBinding[] columns = event.getColumns();
if (columns == null) {
log.error("Error reading columns for device {} event {}", deviceId, event);
continue;
}
VariableBinding portColumn = columns[0];
if (portColumn == null) {
continue;
}
int port = event.getIndex().last();
boolean enabled = (portColumn.getVariable().toInt() == 1);
PortNumber portNumber = PortNumber.portNumber(port);
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
ports.add(p);
}
return ports;
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class ECLinkStore method composeLink.
private Link composeLink(LinkKey linkKey) {
ProviderId baseProviderId = getBaseProviderId(linkKey);
if (baseProviderId == null) {
// parent component.
return null;
}
LinkDescription base = linkDescriptions.get(new Provided<>(linkKey, baseProviderId));
// short circuit if link description no longer exists
if (base == null) {
return null;
}
ConnectPoint src = base.src();
ConnectPoint dst = base.dst();
Type type = base.type();
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(base.annotations());
getAllProviders(linkKey).stream().map(p -> new Provided<>(linkKey, p)).forEach(key -> {
LinkDescription linkDescription = linkDescriptions.get(key);
if (linkDescription != null) {
builder.putAll(linkDescription.annotations());
}
});
DefaultAnnotations annotations = builder.build();
Link.State initialLinkState;
boolean isExpected;
if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE) {
initialLinkState = ACTIVE;
isExpected = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
} else {
initialLinkState = base.isExpected() ? ACTIVE : INACTIVE;
isExpected = base.isExpected();
}
return DefaultLink.builder().providerId(baseProviderId).src(src).dst(dst).type(type).state(initialLinkState).isExpected(isExpected).annotations(annotations).build();
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class JuniperUtils method createOneWayLinkDescription.
/**
* Create one way LinkDescriptions.
*
* @param localDevId the identity of the local device
* @param localPort the port of the local device
* @param remoteDevId the identity of the remote device
* @param remotePort the port of the remote device
* @param descs the collection to which the link descriptions
* should be added
*/
public static void createOneWayLinkDescription(DeviceId localDevId, Port localPort, DeviceId remoteDevId, Port remotePort, Set<LinkDescription> descs) {
ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.LAYER, "ETHERNET").build();
descs.add(new DefaultLinkDescription(remote, local, Link.Type.DIRECT, true, annotations));
}
Aggregations