use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class PolatisLinkDiscovery method checkPeer.
private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
// check peerCP exists and is available (either via device service or direct from device)
DeviceId peerDeviceID = peerCP.deviceId();
boolean result = false;
DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
if (deviceService.isAvailable(peerDeviceID)) {
log.trace("Peer device {} exists", peerDeviceID.toString());
Device device = deviceService.getDevice(peerDeviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
List<Port> ports = deviceService.getPorts(peerDeviceID);
PortNumber farEndPortNum = peerCP.port();
Port port = deviceService.getPort(peerCP);
if (port != null) {
if (port.isEnabled()) {
log.trace("Peer port {} exists", port.number().toLong());
// check far end peer-port entry (use device service or retrieve direct from switch)
Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
if (direct) {
log.trace("Checking device {} DIRECT", handler.data().deviceId());
// A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
NetconfController controller = checkNotNull(handler.get(NetconfController.class));
NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
farEndPortPeerportData = farEndPortPeerportDataDirect;
}
if (!farEndPortPeerportData.equals("")) {
if (farEndPortPeerportData.charAt(0) == '{') {
log.trace("Far-end peer-port value:" + farEndPortPeerportData);
ObjectMapper mapper = new ObjectMapper();
ConnectPoint checkNearEndCP = null;
try {
checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
} catch (JsonProcessingException jpe) {
log.trace("Error processing peer-port JSON: {}", jpe.toString());
}
if (nearEndCP.equals(checkNearEndCP)) {
log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
result = true;
} else {
log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
}
}
} else {
log.trace("Null peer-port entry for far-end port ({})", peerCP);
}
} else {
log.trace("Peer port {} is DISABLED", port);
}
} else {
log.trace("Peer port {} does not exist", port);
}
} else {
log.trace("Far end device does not exist or is not available");
}
return result;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class ZtePortStatisticsDiscovery method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
DeviceId deviceId = handler().data().deviceId();
LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
NetconfController controller = handler().get(NetconfController.class);
if (null == controller) {
LOG.error("Cannot find NetconfController");
return null;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
if (null == session) {
LOG.error("No session available for device {}", deviceId);
return null;
}
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Collection<PortStatistics> portStatistics = Lists.newArrayList();
ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
return portStatistics;
}
use of org.onosproject.net.device.DeviceService 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.device.DeviceService in project onos by opennetworkinglab.
the class BasicInterpreterImpl method mapOutboundPacket.
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
// basic.p4 supports only OUTPUT instructions.
List<OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (OutputInstruction) i).collect(toList());
if (treatment.allInstructions().size() != outInstructions.size()) {
// There are other instructions that are not of type OUTPUT.
throw new PiInterpreterException("Treatment not supported: " + treatment);
}
ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
for (OutputInstruction outInst : outInstructions) {
if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
} else if (outInst.port().equals(FLOOD)) {
// Since basic.p4 does not support flooding, we create a packet
// operation for each switch port.
final DeviceService deviceService = handler().get(DeviceService.class);
for (Port port : deviceService.getPorts(packet.sendThrough())) {
builder.add(createPiPacketOperation(packet.data(), port.number().toLong()));
}
} else {
builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong()));
}
}
return builder.build();
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class PolatisDeviceDescription method discoverPortDetails.
/**
* Discovers port details, for polatis device.
*
* @return port list
*/
@Override
public List<PortDescription> discoverPortDetails() {
log.debug("Discovering ports on Polatis switch...");
DeviceService deviceService = handler().get(DeviceService.class);
DeviceId deviceID = handler().data().deviceId();
Device device = deviceService.getDevice(deviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
String reply = netconfGet(handler(), getPortsFilter());
List<PortDescription> descriptions = parsePorts(reply, numInputPorts, numOutputPorts);
return ImmutableList.copyOf(descriptions);
}
Aggregations