/** * 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); }
/** * Construct a DnatServiceImpl object. * * @param appId the application id of vtn */ public DnatServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); }
@Override public boolean isValid() { this.ospfController = DefaultServiceDirectory.getService(OspfController.class); return true; } }
/** * Construct a SnatServiceImpl object. * * @param appId the application id of vtn */ public SnatServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); }
@Override public boolean isValid() { this.isisController = DefaultServiceDirectory.getService(IsisController.class); return true; } }
/** * Construct a ArpServiceImpl object. * * @param appId the application id of vtn */ public ArpServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); }
@Override public <T> T get(Class<T> serviceClass) { return getService(serviceClass); }
/** * Constructor. * * @param appId the application id of vtn */ public ClassifierServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); }
@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()); }
/** * Construct a L3ForwardServiceImpl object. * * @param appId the application id of vtn */ public L3ForwardServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); }
@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()); } }
/** * Constructor. * * @param appId the application id of vtn */ public L2ForwardServiceImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); this.driverService = serviceDirectory.get(DriverService.class); }
@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()); }
protected void activate() { ServiceDirectory services = new DefaultServiceDirectory(); coreService = services.get(CoreService.class); mastershipService = services.get(MastershipService.class); hostService = services.get(HostService.class); hostService.addListener(hostListener); log.info("Started"); }
@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()); }
/** * Encodes a extension instruction. * * @param result json node that the instruction attributes are added to */ private void encodeExtension(ObjectNode result) { final Instructions.ExtensionInstructionWrapper extensionInstruction = (Instructions.ExtensionInstructionWrapper) instruction; DeviceId deviceId = extensionInstruction.deviceId(); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); DeviceService deviceService = serviceDirectory.get(DeviceService.class); Device device = deviceService.getDevice(deviceId); if (device == null) { throw new IllegalArgumentException("Device not found"); } if (device.is(ExtensionTreatmentCodec.class)) { ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context); result.set(InstructionCodec.EXTENSION, node); } else { throw new IllegalArgumentException( "There is no codec to encode extension for device " + deviceId.toString()); } }
@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; }
/** * Decodes a extension instruction. * * @return extension treatment */ private Instruction decodeExtension() { ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION); if (node != null) { DeviceId deviceId = getDeviceId(); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); DeviceService deviceService = serviceDirectory.get(DeviceService.class); Device device = deviceService.getDevice(deviceId); if (device == null) { throw new IllegalArgumentException("Device not found"); } if (device.is(ExtensionTreatmentCodec.class)) { ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); ExtensionTreatment treatment = treatmentCodec.decode(node, context); return Instructions.extension(treatment, deviceId); } else { throw new IllegalArgumentException( "There is no codec to decode extension for device " + deviceId.toString()); } } return null; }
/** * 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; }
/** * Explicit constructor. * * @param appId application id. */ public SfcFlowRuleInstallerImpl(ApplicationId appId) { this.appId = checkNotNull(appId, "ApplicationId can not be null"); ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); this.driverService = serviceDirectory.get(DriverService.class); this.deviceService = serviceDirectory.get(DeviceService.class); this.hostService = serviceDirectory.get(HostService.class); this.virtualPortService = serviceDirectory.get(VirtualPortService.class); this.vtnRscService = serviceDirectory.get(VtnRscService.class); this.portPairService = serviceDirectory.get(PortPairService.class); this.portPairGroupService = serviceDirectory.get(PortPairGroupService.class); this.flowClassifierService = serviceDirectory.get(FlowClassifierService.class); this.tenantNetworkService = serviceDirectory.get(TenantNetworkService.class); nshSi = 0xff; }