use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class RestDeviceProvider method getDesc.
private DeviceDescription getDesc(RestSBDevice restSBDev) {
DeviceId deviceId = restSBDev.deviceId();
Driver driver = getDriver(restSBDev);
if (restSBDev.isProxy()) {
if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
// Creates the driver to communicate with the server
DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
return devicesDiscovery.deviceDetails(deviceId);
} else {
log.warn("Driver not found for {}", restSBDev);
return null;
}
} else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
DriverHandler h = driverService.createHandler(deviceId);
DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
return deviceDiscovery.discoverDeviceDetails();
}
ChassisId cid = new ChassisId();
String ipAddress = restSBDev.ip().toString();
SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
String manufacturer = UNKNOWN;
String hwVersion = UNKNOWN;
String swVersion = UNKNOWN;
String serialNumber = UNKNOWN;
Device device = deviceService.getDevice(deviceId);
if (device != null) {
manufacturer = device.manufacturer();
hwVersion = device.hwVersion();
swVersion = device.swVersion();
serialNumber = device.serialNumber();
}
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class DeviceDescriptions method putPortDesc.
/**
* Puts PortDescription, merging annotations as necessary.
*
* @param newDesc new PortDescription
*/
public void putPortDesc(Timestamped<PortDescription> newDesc) {
Timestamped<PortDescription> oldOne = portDescs.get(newDesc.value().portNumber());
Timestamped<PortDescription> newOne = newDesc;
if (oldOne != null) {
SparseAnnotations merged = union(oldOne.value().annotations(), newDesc.value().annotations());
newOne = new Timestamped<>(DefaultPortDescription.builder(newDesc.value()).annotations(merged).build(), newDesc.timestamp());
}
portDescs.put(newOne.value().portNumber(), newOne);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method discoverDeviceDetails.
/**
* Returns a DeviceDescription with Device info.
*
* @return DeviceDescription or null
*
* //CHECKSTYLE:OFF
* <pre>{@code
* <data>
* <components xmlns="http://openconfig.net/yang/platform">
* <component>
* <state>
* <name>FIRMWARE</name>
* <type>oc-platform-types:OPERATING_SYSTEM</type>
* <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
* <version>0.0.1</version>
* </state>
* </component>
* </components>
* </data>
*}</pre>
* //CHECKSTYLE:ON
*/
@Override
public DeviceDescription discoverDeviceDetails() {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
boolean defaultAvailable = true;
SparseAnnotations annotations = DefaultAnnotations.builder().build();
// Other option "OTHER", we use ROADM for now
org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
// Some defaults
String vendor = "NOVENDOR";
String hwVersion = "0.2.1";
String swVersion = "0.2.1";
String serialNumber = "0xCAFEBEEF";
String chassisId = "128";
// Get the session,
NetconfSession session = getNetconfSession(did());
if (session != null) {
try {
String reply = session.get(getDeviceDetailsBuilder());
// <rpc-reply> as root node
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
// Requires OpenConfig >= 2018
swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
} catch (Exception e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
}
} else {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
}
log.info("VENDOR {}", vendor);
log.info("HWVERSION {}", hwVersion);
log.info("SWVERSION {}", swVersion);
log.info("SERIAL {}", serialNumber);
log.info("CHASSISID {}", chassisId);
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class TunnelCreateCommand method doExecute.
@Override
protected void doExecute() {
TunnelProvider service = get(TunnelProvider.class);
ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
TunnelEndPoint srcPoint = null;
TunnelEndPoint dstPoint = null;
Tunnel.Type trueType = null;
if ("MPLS".equals(type)) {
trueType = Tunnel.Type.MPLS;
srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("VLAN".equals(type)) {
trueType = Tunnel.Type.VLAN;
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, null, OpticalLogicId.logicId(0), true);
dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, null, OpticalLogicId.logicId(0), true);
} else if ("VXLAN".equals(type)) {
trueType = Tunnel.Type.VXLAN;
srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("GRE".equals(type)) {
trueType = Tunnel.Type.GRE;
srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("ODUK".equals(type)) {
trueType = Tunnel.Type.ODUK;
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
} else if ("OCH".equals(type)) {
trueType = Tunnel.Type.OCH;
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
} else {
print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
return;
}
SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth).build();
TunnelDescription tunnel = new DefaultTunnelDescription(null, srcPoint, dstPoint, trueType, new GroupId(Integer.parseInt(groupId)), producerName, TunnelName.tunnelName(tunnelName), null, annotations);
TunnelId tunnelId = service.tunnelAdded(tunnel);
if (tunnelId == null) {
error("Create tunnel failed.");
return;
}
print(FMT, tunnelId.id());
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class TunnelUpdateCommand method doExecute.
@Override
protected void doExecute() {
TunnelProvider service = get(TunnelProvider.class);
TunnelId id = TunnelId.valueOf(tunnelId);
SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", bandwidth).build();
TunnelDescription tunnel = new DefaultTunnelDescription(id, null, null, null, null, null, null, null, annotations);
service.tunnelUpdated(tunnel);
}
Aggregations