/** * Returns the reference to the implementation of the specified service. * * @param serviceClass service class * @param <T> type of service * @return service implementation * @throws org.onlab.osgi.ServiceNotFoundException if service is unavailable */ public static <T> T get(Class<T> serviceClass) { return DefaultServiceDirectory.getService(serviceClass); }
@Override public boolean isValid() { this.isisController = DefaultServiceDirectory.getService(IsisController.class); return true; } }
@Override public boolean isValid() { this.ospfController = DefaultServiceDirectory.getService(OspfController.class); return true; } }
@Override public <T> T get(Class<T> serviceClass) { return getService(serviceClass); }
@Override protected List<String> choices() { InterfaceService interfaceService = getService(InterfaceService.class); return interfaceService.getInterfaces().stream() .map(Interface::name) .filter(name -> !name.equals(Interface.NO_INTERFACE_NAME)) .collect(Collectors.toList()); }
@Override protected List<String> choices() { DeviceId deviceId = lookForDeviceId(); if (deviceId == null) { return Collections.emptyList(); } DeviceService deviceService = getService(DeviceService.class); return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false) .map(port -> Long.toString(port.number().toLong())) .collect(Collectors.toList()); } }
@Override protected List<String> choices() { DeviceId deviceId = lookForDeviceId(); if (deviceId == null) { return Collections.emptyList(); } DeviceService deviceService = getService(DeviceService.class); return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false) .map(port -> port.number().toString()) .collect(Collectors.toList()); }
@Override protected List<String> choices() { DeviceService deviceService = getService(DeviceService.class); LinkService linkService = getService(LinkService.class); Optional<ConnectPoint> port = Arrays.asList(commandLine.getArguments()).stream() .filter(s -> s.contains(":") && s.contains("/")) .map(s -> { try { return deviceConnectPoint(s); } catch (IllegalArgumentException e) { // silently ill-formed String return null; } }) .filter(Objects::nonNull) .filter(cp -> deviceService.getPort(cp) != null) .findFirst(); if (!port.isPresent()) { // no candidate return Collections.emptyList(); } final ConnectPoint cp = port.get(); return linkService.getLinks(cp).stream() .flatMap(l -> Stream.of(l.src(), l.dst())) .filter(peer -> !cp.equals(peer)) .distinct() .map(ConnectPoint::toString) .collect(Collectors.toList()); }
@Override public Device delegate() { if (delegate == null) { // dirty work around. // wanted to pass delegate Device at construction, // but was not possible. A Behaviour requires no-arg constructor. checkState(data() != null, "DriverData must exist"); DriverData data = data(); DeviceService service = DefaultServiceDirectory.getService(DeviceService.class); delegate = checkNotNull(service.getDevice(data.deviceId()), "No Device found for %s", data.deviceId()); } return delegate; }
/** * Look for valid DeviceId in arguments passed so far. * * @return DeviceId found or null if not found */ protected DeviceId lookForDeviceId() { //parse argument list for deviceId DeviceService deviceService = getService(DeviceService.class); Device dev = null; for (String str : commandLine.getArguments()) { if (str.contains(":")) { dev = deviceService.getDevice(DeviceId.deviceId(str)); if (dev != null) { return dev.id(); } } } return null; }
/** * Constructs a new MeteringAgent for a given distributed primitive. * Instantiates the metrics service * Initializes all the general metrics for that object * * @param primitiveName Type of primitive to be metered * @param objName Global name of the primitive * @param activated boolean flag for whether metering is enabled or not */ public MeteringAgent(String primitiveName, String objName, boolean activated) { checkNotNull(objName, "Object name cannot be null"); this.activated = activated; nullTimer = new Context(null, ""); if (this.activated) { this.metricsService = DefaultServiceDirectory.getService(MetricsService.class); this.metricsComponent = metricsService.registerComponent(primitiveName); this.metricsFeature = metricsComponent.registerFeature(objName); this.wildcard = metricsComponent.registerFeature("*"); this.perObjTimer = metricsService.createTimer(metricsComponent, metricsFeature, "*"); this.perPrimitiveTimer = metricsService.createTimer(metricsComponent, wildcard, "*"); this.perObjExceptionCounter = metricsService.createCounter(metricsComponent, metricsFeature, "exceptions"); this.exceptionCounter = metricsService.createCounter(metricsComponent, wildcard, "exceptions"); } }
@Override public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) { kryo.writeClassAndObject(output, object.extensionInstruction().type()); kryo.writeClassAndObject(output, object.deviceId()); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); // It raises ItemNotFoundException if it failed to find driver Driver driver = driverService.getDriver(object.deviceId()); kryo.writeClassAndObject(output, driver.name()); kryo.writeClassAndObject(output, object.extensionInstruction().serialize()); }
@Override public ExtensionCriterion read(Kryo kryo, Input input, Class<ExtensionCriterion> type) { ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); byte[] bytes = (byte[]) kryo.readClassAndObject(input); ExtensionSelector selector; try { DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); selector = resolver.getExtensionSelector(exType); selector.deserialize(bytes); } catch (ItemNotFoundException | IllegalArgumentException e) { selector = new UnresolvedExtensionSelector(bytes, exType); } return Criteria.extension(selector, deviceId); } }
@Override public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, Class<Instructions.ExtensionInstructionWrapper> type) { ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); String driverName = (String) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); byte[] bytes = (byte[]) kryo.readClassAndObject(input); ExtensionTreatment instruction; try { DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(driverName), deviceId)); ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); instruction = resolver.getExtensionInstruction(exType); instruction.deserialize(bytes); } catch (ItemNotFoundException | IllegalArgumentException e) { instruction = new UnresolvedExtensionTreatment(bytes, exType); } return Instructions.extension(instruction, deviceId); } }