use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class SimpleDeviceStore method composePort.
/**
* Returns a Port, merging description given from multiple Providers.
*
* @param device device the port is on
* @param number port number
* @param descsMap Collection of Descriptions from multiple providers
* @return Port instance
*/
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
ProviderId primary = pickPrimaryPid(descsMap);
DeviceDescriptions primDescs = descsMap.get(primary);
// if no primary, assume not enabled
// TODO: revisit this default port enabled/disabled behavior
boolean isEnabled = false;
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
final PortDescription portDesc = primDescs.getPortDesc(number);
if (portDesc != null) {
isEnabled = portDesc.isEnabled();
annotations = merge(annotations, portDesc.annotations());
}
for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
if (e.getKey().equals(primary)) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
if (otherPortDesc != null) {
annotations = merge(annotations, otherPortDesc.annotations());
}
}
return portDesc == null ? new DefaultPort(device, number, false, annotations) : new DefaultPort(device, number, isEnabled, portDesc.type(), portDesc.portSpeed(), annotations);
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class SimpleDeviceStore method composeDevice.
/**
* Returns a Device, merging description given from multiple Providers.
*
* @param deviceId device identifier
* @param providerDescs Collection of Descriptions from multiple providers
* @return Device instance
*/
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
ProviderId primary = pickPrimaryPid(providerDescs);
DeviceDescriptions desc = providerDescs.get(primary);
final DeviceDescription base = desc.getDeviceDesc();
Type type = base.type();
String manufacturer = base.manufacturer();
String hwVersion = base.hwVersion();
String swVersion = base.swVersion();
String serialNumber = base.serialNumber();
ChassisId chassisId = base.chassisId();
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
annotations = merge(annotations, base.annotations());
for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
if (e.getKey().equals(primary)) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
}
return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class PolatisLinkDiscovery method getLinks.
/**
* Returns the set of LinkDescriptions originating from a Polatis switch.
* <p>
* This is the callback required by the LinkDiscovery behaviour.
* @return Set of outbound unidirectional links as LinkDescriptions
*/
@Override
public Set<LinkDescription> getLinks() {
Set<LinkDescription> links = new HashSet<>();
DeviceId deviceID = handler().data().deviceId();
log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceID) == null) {
log.warn("NETCONF session to device {} not yet established, will try again...", deviceID);
return links;
}
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
Device device = deviceService.getDevice(deviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
log.trace("Talking to device " + handler().data().deviceId().toString());
String reply = netconfGet(handler(), getPortsFilter());
// Get port details from switch as PortDescription objects
List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
int numPeerPortEntries = 0;
int numPortsScanned = 0;
ObjectMapper mapper = new ObjectMapper();
for (PortDescription port : ports) {
numPortsScanned++;
if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
String peerPortData = port.annotations().value(KEY_PORTPEER);
if (!peerPortData.equals("")) {
numPeerPortEntries++;
if (peerPortData.charAt(0) == '{') {
ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
ConnectPoint farEndCP = null;
try {
farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
} catch (JsonProcessingException jpe) {
log.debug("Error processing peer-port JSON: {}", jpe.toString());
}
if (farEndCP != null) {
log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(), farEndCP.toString());
if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
log.trace("Peer {} checks out", farEndCP.toString());
// now add link to Set<LinkDescription>
DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_LINKBIDIR, VALUE_FALSE).set(KEY_LINKALLOWED, VALUE_TRUE).build();
ConnectPoint aEndCP = nearEndCP;
ConnectPoint bEndCP = farEndCP;
// reverse direction of unidirectional link if near-end port is INPUT
if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
aEndCP = farEndCP;
bEndCP = nearEndCP;
}
LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP, Link.Type.OPTICAL, true, annotations);
links.add(newLinkDesc);
log.debug("Adding link {}", newLinkDesc);
}
}
}
}
}
}
log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries, links.size(), links.size() == 1 ? "is" : "are");
log.trace("Links found on this iteration: {}", links);
return links;
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class PolatisUtility method parsePort.
/**
* Returns a single PortDescription from parsing a HierarchicalConfiguration object containing a Polatis switch
* port config.
*
* @param cfg Single port as HierarchicalConfiguration object
* @param numInputPorts Number of input ports
* @param isConfigurable Switch is CC
* @return Single port as PortDescription object
*/
public static PortDescription parsePort(HierarchicalConfiguration cfg, int numInputPorts, boolean isConfigurable) {
PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
String portType = VALUE_UNKNOWN;
if (isConfigurable) {
portType = VALUE_CC;
} else {
portType = portNumber.toLong() > numInputPorts ? VALUE_OUTPUT : VALUE_INPUT;
}
String peerPort = cfg.getString(KEY_PEERPORT);
DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, cfg.getString(KEY_PORTLABEL)).set(KEY_PORTPEER, cfg.getString(KEY_PEERPORT)).set(KEY_PORTDIR, portType).build();
return omsPortDescription(portNumber, cfg.getString(KEY_PORTSTATUS).equals(PORT_ENABLED), Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(6_25), annotations);
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class PolatisDeviceDescription method parseProductInformation.
private DeviceDescription parseProductInformation() {
DeviceService devsvc = checkNotNull(handler().get(DeviceService.class));
DeviceId devID = handler().data().deviceId();
String reply = netconfGet(handler(), getProdInfoFilter());
subscribe(handler());
HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
String hw = cfg.getString(KEY_HWVERSION);
String numInputPorts = "0";
String numOutputPorts = "0";
if (!hw.equals("")) {
Pattern patternSize = Pattern.compile("\\d+x[\\dC]+");
Matcher matcher = patternSize.matcher(hw);
if (matcher.find()) {
String switchSize = matcher.group();
log.debug("Got switch size: " + switchSize);
Pattern patternNumber = Pattern.compile("[\\dC]+");
matcher = patternNumber.matcher(switchSize);
if (matcher.find()) {
numInputPorts = matcher.group();
log.debug("numInputPorts=" + numInputPorts);
if (matcher.find()) {
if (!matcher.group().equals("CC")) {
numOutputPorts = matcher.group();
}
}
log.debug("numOutputPorts=" + numOutputPorts);
}
}
} else {
log.warn("Unable to determine type of Polatis switch " + devID.toString());
}
DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_INPUTPORTS, numInputPorts).set(KEY_OUTPUTPORTS, numOutputPorts).build();
return new DefaultDeviceDescription(devID.uri(), FIBER_SWITCH, cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION), cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER), new ChassisId(cfg.getString(KEY_SERIALNUMBER)), true, annotations);
}
Aggregations