org.onosproject.net.flow.FlowRuleService Java Examples
The following examples show how to use
org.onosproject.net.flow.FlowRuleService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualFlowsListCommand.java From onos with Apache License 2.0 | 6 votes |
@Override protected void doExecute() { CoreService coreService = get(CoreService.class); VirtualNetworkService vnetservice = get(VirtualNetworkService.class); DeviceService deviceService = vnetservice.get(NetworkId.networkId(networkId), DeviceService.class); FlowRuleService service = vnetservice.get(NetworkId.networkId(networkId), FlowRuleService.class); contentFilter = new StringFilter(filter, StringFilter.Strategy.AND); compilePredicate(); SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); if (outputJson()) { print("%s", json(flows.keySet(), flows)); } else { flows.forEach((device, flow) -> printFlows(device, flow, coreService)); } }
Example #2
Source File: StatisticsWebResource.java From onos with Apache License 2.0 | 6 votes |
/** * Gets sum of active entries in all tables for all devices. * * @onos.rsModel StatisticsFlowsActiveEntries * @return 200 OK with JSON encoded array of active entry count per device */ @GET @Path("flows/activeentries") @Produces(MediaType.APPLICATION_JSON) public Response getActiveEntriesCountPerDevice() { final FlowRuleService service = get(FlowRuleService.class); final Iterable<Device> devices = get(DeviceService.class).getDevices(); final ObjectNode root = mapper().createObjectNode(); final ArrayNode rootArrayNode = root.putArray("statistics"); for (final Device device : devices) { int activeEntries = service.getFlowRuleCount(device.id(), FlowEntry.FlowEntryState.ADDED); final ObjectNode entry = mapper().createObjectNode(); entry.put("device", device.id().toString()); entry.put("activeEntries", activeEntries); rootArrayNode.add(entry); } return ok(root).build(); }
Example #3
Source File: FlowsWebResource.java From onos with Apache License 2.0 | 6 votes |
/** * Gets all pending flow entries. Returns array of all pending flow rules in the system. * * @return 200 OK with a collection of flows * @onos.rsModel FlowEntries */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("pending") public Response getPendingFlows() { ObjectNode root = mapper().createObjectNode(); ArrayNode flowsNode = root.putArray(FLOWS); FlowRuleService service = get(FlowRuleService.class); Iterable<Device> devices = get(DeviceService.class).getDevices(); for (Device device : devices) { Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id()); if (flowEntries != null) { for (FlowEntry entry : flowEntries) { if ((entry.state() == FlowEntry.FlowEntryState.PENDING_ADD) || (entry.state() == FlowEntry.FlowEntryState.PENDING_REMOVE)) { flowsNode.add(codec(FlowEntry.class).encode(entry, this)); } } } } return ok(root).build(); }
Example #4
Source File: StatisticsWebResource.java From onos with Apache License 2.0 | 6 votes |
/** * Gets table statistics for all tables of all devices. * * @onos.rsModel StatisticsFlowsTables * @return 200 OK with JSON encoded array of table statistics */ @GET @Path("flows/tables") @Produces(MediaType.APPLICATION_JSON) public Response getTableStatistics() { final FlowRuleService service = get(FlowRuleService.class); final Iterable<Device> devices = get(DeviceService.class).getDevices(); final ObjectNode root = mapper().createObjectNode(); final ArrayNode rootArrayNode = root.putArray("statistics"); for (final Device device : devices) { final ObjectNode deviceStatsNode = mapper().createObjectNode(); deviceStatsNode.put("device", device.id().toString()); final ArrayNode statisticsNode = deviceStatsNode.putArray("table"); final Iterable<TableStatisticsEntry> tableStatsEntries = service.getFlowTableStatistics(device.id()); if (tableStatsEntries != null) { for (final TableStatisticsEntry entry : tableStatsEntries) { statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this)); } } rootArrayNode.add(deviceStatsNode); } return ok(root).build(); }
Example #5
Source File: OFSwitchManager.java From onos with Apache License 2.0 | 6 votes |
private void processOFAgentStopped(OFAgent ofAgent) { devices(ofAgent.networkId()).forEach(deviceId -> { OFSwitch ofSwitch = ofSwitchMap.get(deviceId); if (ofSwitch != null) { disconnectController(ofSwitch, ofAgent.controllers()); } }); DeviceService deviceService = virtualNetService.get( ofAgent.networkId(), DeviceService.class); deviceService.removeListener(deviceListener); PacketService packetService = virtualNetService.get( ofAgent.networkId(), PacketService.class); packetService.removeProcessor(packetProcessor); FlowRuleService flowRuleService = virtualNetService.get( ofAgent.networkId(), FlowRuleService.class); flowRuleService.removeListener(flowRuleListener); }
Example #6
Source File: OFSwitchManager.java From onos with Apache License 2.0 | 6 votes |
private void processOFAgentStarted(OFAgent ofAgent) { devices(ofAgent.networkId()).forEach(deviceId -> { OFSwitch ofSwitch = ofSwitchMap.get(deviceId); if (ofSwitch != null) { connectController(ofSwitch, ofAgent.controllers()); } }); DeviceService deviceService = virtualNetService.get( ofAgent.networkId(), DeviceService.class); deviceService.addListener(deviceListener); PacketService packetService = virtualNetService.get( ofAgent.networkId(), PacketService.class); packetService.addProcessor(packetProcessor, PacketProcessor.director(0)); FlowRuleService flowRuleService = virtualNetService.get( ofAgent.networkId(), FlowRuleService.class); flowRuleService.addListener(flowRuleListener); }
Example #7
Source File: DefaultOFSwitch.java From onos with Apache License 2.0 | 6 votes |
private DefaultOFSwitch(DatapathId dpid, OFSwitchCapabilities capabilities, NetworkId networkId, DeviceId deviceId, ServiceDirectory serviceDirectory) { this.dpId = dpid; this.capabilities = capabilities; this.networkId = networkId; this.deviceId = deviceId; this.ofSwitchService = serviceDirectory.get(OFSwitchService.class); this.driverService = serviceDirectory.get(DriverService.class); this.virtualNetworkAdminService = serviceDirectory.get(VirtualNetworkAdminService.class); VirtualNetworkService virtualNetworkService = serviceDirectory.get(VirtualNetworkService.class); this.flowRuleService = virtualNetworkService.get(networkId, FlowRuleService.class); this.groupService = virtualNetworkService.get(networkId, GroupService.class); this.meterService = virtualNetworkService.get(networkId, MeterService.class); log = LoggerFactory.getLogger(OFAgent.TRACER_LOG_TENANT_ID_PREFIX + virtualNetworkService.getTenantId(networkId) + " " + getClass().getSimpleName() + " : " + dpid); }
Example #8
Source File: FlowsWebResource.java From onos with Apache License 2.0 | 6 votes |
/** * Gets flow entries of a device. Returns array of all flow rules for the * specified device. * * @param deviceId device identifier * @return 200 OK with a collection of flows of given device * @onos.rsModel FlowEntries */ @GET @Produces(MediaType.APPLICATION_JSON) // TODO: we need to add "/device" suffix to the path to differentiate with appId @Path("{deviceId}") public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) { FlowRuleService service = get(FlowRuleService.class); ObjectNode root = mapper().createObjectNode(); ArrayNode flowsNode = root.putArray(FLOWS); Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId)); if (flowEntries == null || !flowEntries.iterator().hasNext()) { throw new ItemNotFoundException(DEVICE_NOT_FOUND); } for (FlowEntry entry : flowEntries) { flowsNode.add(codec(FlowEntry.class).encode(entry, this)); } return ok(root).build(); }
Example #9
Source File: FlowsWebResource.java From onos with Apache License 2.0 | 6 votes |
/** * Removes flow rule. Removes the specified flow rule. * * @param deviceId device identifier * @param flowId flow rule identifier * @return 204 NO CONTENT */ @DELETE @Path("{deviceId}/{flowId}") public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, @PathParam("flowId") long flowId) { FlowRuleService service = get(FlowRuleService.class); Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId)); if (!flowEntries.iterator().hasNext()) { throw new ItemNotFoundException(DEVICE_NOT_FOUND); } StreamSupport.stream(flowEntries.spliterator(), false) .filter(entry -> entry.id().value() == flowId) .forEach(service::removeFlowRules); return Response.noContent().build(); }
Example #10
Source File: IntentsResourceTest.java From onos with Apache License 2.0 | 6 votes |
/** * Initializes test mocks and environment. */ @Before public void setUpTest() { expect(mockIntentService.getIntents()).andReturn(intents).anyTimes(); expect(mockIntentService.getIntentState(anyObject())) .andReturn(IntentState.INSTALLED) .anyTimes(); // Register the services needed for the test final CodecManager codecService = new CodecManager(); codecService.activate(); ServiceDirectory testDirectory = new TestServiceDirectory() .add(IntentService.class, mockIntentService) .add(FlowRuleService.class, mockFlowService) .add(CodecService.class, codecService) .add(CoreService.class, mockCoreService); setServiceDirectory(testDirectory); MockIdGenerator.cleanBind(); }
Example #11
Source File: FlowsListCommand.java From onos with Apache License 2.0 | 6 votes |
/** * Removes the flows passed as argument after confirmation is provided * for each of them. * If no explicit confirmation is provided, the flow is not removed. * * @param flows list of flows to remove * @param flowService FlowRuleService object * @param coreService CoreService object */ public void removeFlowsInteractive(Iterable<FlowEntry> flows, FlowRuleService flowService, CoreService coreService) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); flows.forEach(flow -> { ApplicationId appId = coreService.getAppId(flow.appId()); System.out.print(String.format("Id=%s, AppId=%s. Remove? [y/N]: ", flow.id(), appId != null ? appId.name() : "<none>")); String response; try { response = br.readLine(); response = response.trim().replace("\n", ""); if ("y".equals(response)) { flowService.removeFlowRules(flow); } } catch (IOException e) { response = ""; } print(response); }); }
Example #12
Source File: ServicesBundle.java From onos with Apache License 2.0 | 6 votes |
/** * Creates the services bundle, from the given directly. * * @param directory service directory */ public ServicesBundle(ServiceDirectory directory) { checkNotNull(directory, "Directory cannot be null"); clusterService = directory.get(ClusterService.class); topologyService = directory.get(TopologyService.class); deviceService = directory.get(DeviceService.class); driverService = directory.get(DriverService.class); hostService = directory.get(HostService.class); linkService = directory.get(LinkService.class); mastershipService = directory.get(MastershipService.class); mastershipAdminService = directory.get(MastershipAdminService.class); intentService = directory.get(IntentService.class); flowService = directory.get(FlowRuleService.class); flowStatsService = directory.get(StatisticService.class); portStatsService = directory.get(PortStatisticsService.class); }
Example #13
Source File: Topo2Jsonifier.java From onos with Apache License 2.0 | 6 votes |
/** * Creates an instance with a reference to the services directory, so that * additional information about network elements may be looked up on * on the fly. * * @param directory service directory * @param userName logged in user name */ public Topo2Jsonifier(ServiceDirectory directory, String userName) { this.directory = checkNotNull(directory, "Directory cannot be null"); this.userName = checkNotNull(userName, "User name cannot be null"); clusterService = directory.get(ClusterService.class); deviceService = directory.get(DeviceService.class); linkService = directory.get(LinkService.class); hostService = directory.get(HostService.class); mastershipService = directory.get(MastershipService.class); intentService = directory.get(IntentService.class); flowService = directory.get(FlowRuleService.class); flowStatsService = directory.get(StatisticService.class); portStatsService = directory.get(PortStatisticsService.class); topologyService = directory.get(TopologyService.class); uiextService = directory.get(UiExtensionService.class); prefService = directory.get(UiPreferencesService.class); }
Example #14
Source File: P4RuntimeTableStatisticsDiscovery.java From onos with Apache License 2.0 | 6 votes |
@Override public List<TableStatisticsEntry> getTableStatistics() { if (!setupBehaviour("getTableStatistics()")) { return Collections.emptyList(); } FlowRuleService flowService = handler().get(FlowRuleService.class); PiPipelineInterpreter interpreter = getInterpreter(handler()); PiPipelineModel model = pipeconf.pipelineModel(); List<TableStatisticsEntry> tableStatsList; List<FlowEntry> rules = newArrayList(flowService.getFlowEntries(deviceId)); Map<PiTableId, Integer> piTableFlowCount = piFlowRuleCounting(model, interpreter, rules); Map<PiTableId, Long> piTableMatchCount = piMatchedCounting(model, interpreter, rules); tableStatsList = generatePiFlowTableStatistics(piTableFlowCount, piTableMatchCount, model, deviceId); return tableStatsList; }
Example #15
Source File: OplinkSwitchProtection.java From onos with Apache License 2.0 | 6 votes |
private void addFlow(PortNumber workingPort) { // set working port as flow's input port TrafficSelector selector = DefaultTrafficSelector.builder() .matchInPort(workingPort) .build(); // the flow's output port is always the clinet port TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setOutput(PortNumber.portNumber(CLIENT_PORT)) .build(); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(data().deviceId()) .fromApp(handler().get(CoreService.class).getAppId(APP_ID)) .withPriority(FLOWRULE_PRIORITY) .withSelector(selector) .withTreatment(treatment) .makePermanent() .build(); // install flow rule handler().get(FlowRuleService.class).applyFlowRules(flowRule); }
Example #16
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 6 votes |
@Override public void init(DeviceId deviceId, PipelinerContext context) { this.deviceId = deviceId; serviceDirectory = context.directory(); coreService = serviceDirectory.get(CoreService.class); flowRuleService = serviceDirectory.get(FlowRuleService.class); groupService = serviceDirectory.get(GroupService.class); flowObjectiveStore = context.store(); deviceService = serviceDirectory.get(DeviceService.class); // Init the accumulator, if enabled if (isAccumulatorEnabled(this)) { accumulator = new ForwardingObjectiveAccumulator(context.accumulatorMaxObjectives(), context.accumulatorMaxBatchMillis(), context.accumulatorMaxIdleMillis()); } initDriverId(); initGroupHander(context); initializePipeline(); }
Example #17
Source File: OplinkPowerConfigUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics. * * @param flowEntry flow entry * @param power power value */ private void addAttenuation(FlowEntry flowEntry, long power) { FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder() .withCookie(flowEntry.id().value()) .withPriority(flowEntry.priority()) .forDevice(flowEntry.deviceId()) .forTable(flowEntry.tableId()); if (flowEntry.isPermanent()) { flowBuilder.makePermanent(); } else { flowBuilder.makeTemporary(flowEntry.timeout()); } flowBuilder.withSelector(flowEntry.selector()); // Copy original instructions and add attenuation instruction TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins)); final DriverHandler handler = behaviour.handler(); treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId())); flowBuilder.withTreatment(treatmentBuilder.build()); FlowRuleService service = handler.get(FlowRuleService.class); service.applyFlowRules(flowBuilder.build()); }
Example #18
Source File: OplinkPowerConfigUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Sets specified channle attenuation. * * @param portNum the port number * @param och channel signal * @param power attenuation in 0.01 dB */ private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) { FlowEntry flowEntry = findFlow(portNum, och); if (flowEntry == null) { log.warn("Target channel power not set"); return; } final DriverHandler handler = behaviour.handler(); for (Instruction ins : flowEntry.treatment().allInstructions()) { if (ins.type() != Instruction.Type.EXTENSION) { continue; } ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction(); if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) { ((OplinkAttenuation) ext).setAttenuation((int) power); FlowRuleService service = handler.get(FlowRuleService.class); service.applyFlowRules(flowEntry); return; } } addAttenuation(flowEntry, power); }
Example #19
Source File: PicaPipeline.java From onos with Apache License 2.0 | 6 votes |
@Override public void init(DeviceId deviceId, PipelinerContext context) { this.serviceDirectory = context.directory(); this.deviceId = deviceId; coreService = serviceDirectory.get(CoreService.class); flowRuleService = serviceDirectory.get(FlowRuleService.class); flowObjectiveStore = context.store(); filters = Collections.newSetFromMap(new ConcurrentHashMap<Filter, Boolean>()); pendingVersatiles = Collections.newSetFromMap( new ConcurrentHashMap<ForwardingObjective, Boolean>()); appId = coreService.registerApplication( "org.onosproject.driver.OVSPicaPipeline"); initializePipeline(); }
Example #20
Source File: IntentsDiagnosisCommand.java From onos with Apache License 2.0 | 5 votes |
private ServiceRefs( IntentService intentsService, DeviceService deviceService, FlowRuleService flowService, WorkPartitionService workPartitionService, ObjectiveTrackerService objectiveTrackerService ) { this.intentsService = intentsService; this.deviceService = deviceService; this.flowService = flowService; this.workPartitionService = workPartitionService; this.objectiveTrackerService = objectiveTrackerService; }
Example #21
Source File: TableStatisticsCommand.java From onos with Apache License 2.0 | 5 votes |
/** * Returns the list of table statistics sorted using the device ID URIs and table IDs. * * @param deviceService device service * @param flowService flow rule service * @return sorted table statistics list */ protected SortedMap<Device, List<TableStatisticsEntry>> getSortedTableStats(DeviceService deviceService, FlowRuleService flowService) { SortedMap<Device, List<TableStatisticsEntry>> deviceTableStats = new TreeMap<>(Comparators.ELEMENT_COMPARATOR); List<TableStatisticsEntry> tableStatsList; Iterable<Device> devices = uri == null ? deviceService.getDevices() : Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); for (Device d : devices) { tableStatsList = newArrayList(flowService.getFlowTableStatistics(d.id())); tableStatsList.sort((p1, p2) -> Integer.valueOf(p1.tableId()).compareTo(Integer.valueOf(p2.tableId()))); deviceTableStats.put(d, tableStatsList); } return deviceTableStats; }
Example #22
Source File: NewAdaptiveFlowStatsCollector.java From onos with Apache License 2.0 | 5 votes |
/** * Creates a new adaptive collector for the given switch and default cal_and_poll frequency. * * @param driverService driver service reference * @param sw switch to pull * @param pollInterval cal and immediate poll frequency in seconds */ NewAdaptiveFlowStatsCollector(DriverService driverService, OpenFlowSwitch sw, int pollInterval) { this.driverService = driverService; this.sw = sw; this.did = DeviceId.deviceId(Dpid.uri(sw.getId())); flowRuleService = get(FlowRuleService.class); initMemberVars(pollInterval); if (pollInterval == -1) { pollPeriodically = false; } }
Example #23
Source File: OpenstackConfigArpModeCommand.java From onos with Apache License 2.0 | 5 votes |
private void purgeRules() { FlowRuleService flowRuleService = get(FlowRuleService.class); CoreService coreService = get(CoreService.class); ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID); if (appId == null) { error("Failed to purge OpenStack networking flow rules."); return; } flowRuleService.removeFlowRulesById(appId); }
Example #24
Source File: OplinkOpticalPowerConfig.java From onos with Apache License 2.0 | 5 votes |
private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) { log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing()); FlowRuleService service = handler().get(FlowRuleService.class); Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId()); for (FlowEntry entry : entries) { OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry); // The channel port might be input port or output port. if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) { log.debug("Flow is found, modify the flow with attenuation."); // Modify attenuation in treatment TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setOutput(crossConnect.getOutPort()) .extension(new OplinkAttenuation((int) power), data().deviceId()) .build(); // Apply the new flow rule service.applyFlowRules(DefaultFlowRule.builder() .forDevice(data().deviceId()) .makePermanent() .withSelector(entry.selector()) .withTreatment(treatment) .withPriority(entry.priority()) .withCookie(entry.id().value()) .build()); return true; } } return false; }
Example #25
Source File: VirtualNetworkFlowObjectiveManager.java From onos with Apache License 2.0 | 5 votes |
public VirtualNetworkFlowObjectiveManager(VirtualNetworkService manager, NetworkId networkId) { super(manager, networkId); deviceService = manager.get(networkId(), DeviceService.class); flowRuleService = manager.get(networkId(), FlowRuleService.class); executorService = newFixedThreadPool(4, groupedThreads("onos/virtual/objective-installer", "%d", log)); virtualFlowObjectiveStore = serviceDirectory.get(VirtualNetworkFlowObjectiveStore.class); delegate = new InternalStoreDelegate(); virtualFlowObjectiveStore.setDelegate(networkId(), delegate); flowObjectiveStore = new StoreConvertor(); }
Example #26
Source File: OplinkPowerConfigUtil.java From onos with Apache License 2.0 | 5 votes |
/** * Find matching flow on device. * * @param portNum the port number * @param och channel signal * @return flow entry */ private FlowEntry findFlow(PortNumber portNum, OchSignal och) { final DriverHandler handler = behaviour.handler(); FlowRuleService service = handler.get(FlowRuleService.class); Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId()); // Return first matching flow for (FlowEntry entry : flowEntries) { TrafficSelector selector = entry.selector(); OchSignalCriterion entrySigid = (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID); // Check channel if (entrySigid != null && och.equals(entrySigid.lambda())) { // Check input port PortCriterion entryPort = (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT); if (entryPort != null && portNum.equals(entryPort.port())) { return entry; } // Check output port TrafficTreatment treatment = entry.treatment(); for (Instruction instruction : treatment.allInstructions()) { if (instruction.type() == Instruction.Type.OUTPUT && ((Instructions.OutputInstruction) instruction).port().equals(portNum)) { return entry; } } } } log.warn("No matching flow found"); return null; }
Example #27
Source File: VirtualNetworkManager.java From onos with Apache License 2.0 | 5 votes |
/** * Create a new vnet service instance. * * @param serviceKey service key * @return vnet service */ private VnetService create(ServiceKey serviceKey) { VirtualNetwork network = getVirtualNetwork(serviceKey.networkId()); checkNotNull(network, NETWORK_NULL); VnetService service; if (serviceKey.serviceClass.equals(DeviceService.class)) { service = new VirtualNetworkDeviceManager(this, network.id()); } else if (serviceKey.serviceClass.equals(LinkService.class)) { service = new VirtualNetworkLinkManager(this, network.id()); } else if (serviceKey.serviceClass.equals(TopologyService.class)) { service = new VirtualNetworkTopologyManager(this, network.id()); } else if (serviceKey.serviceClass.equals(IntentService.class)) { service = new VirtualNetworkIntentManager(this, network.id()); } else if (serviceKey.serviceClass.equals(HostService.class)) { service = new VirtualNetworkHostManager(this, network.id()); } else if (serviceKey.serviceClass.equals(PathService.class)) { service = new VirtualNetworkPathManager(this, network.id()); } else if (serviceKey.serviceClass.equals(FlowRuleService.class)) { service = new VirtualNetworkFlowRuleManager(this, network.id()); } else if (serviceKey.serviceClass.equals(PacketService.class)) { service = new VirtualNetworkPacketManager(this, network.id()); } else if (serviceKey.serviceClass.equals(GroupService.class)) { service = new VirtualNetworkGroupManager(this, network.id()); } else if (serviceKey.serviceClass.equals(MeterService.class)) { service = new VirtualNetworkMeterManager(this, network.id()); } else if (serviceKey.serviceClass.equals(FlowObjectiveService.class)) { service = new VirtualNetworkFlowObjectiveManager(this, network.id()); } else if (serviceKey.serviceClass.equals(MastershipService.class) || serviceKey.serviceClass.equals(MastershipAdminService.class) || serviceKey.serviceClass.equals(MastershipTermService.class)) { service = new VirtualNetworkMastershipManager(this, network.id()); } else { return null; } networkServices.put(serviceKey, service); return service; }
Example #28
Source File: ServerHandshaker.java From onos with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Boolean> probeReachability() { // Retrieve the device ID from the handler DeviceId deviceId = super.getDeviceId(); checkNotNull(deviceId, MSG_DEVICE_ID_NULL); // Probe the driver to ask for flow rule service FlowRuleService flowService = getHandler().get(FlowRuleService.class); List<TableStatisticsEntry> tableStats = Lists.newArrayList( flowService.getFlowTableStatistics(deviceId)); // If no statistics fetched, the server is not reachable return completedFuture(tableStats.isEmpty() ? false : true); }
Example #29
Source File: VirtualFlowsListCommand.java From onos with Apache License 2.0 | 5 votes |
/** * Returns the list of devices sorted using the device ID URIs. * * @param deviceService device service * @param service flow rule service * @return sorted device list */ protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, FlowRuleService service) { SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR); List<FlowEntry> rules; Iterable<Device> devices = null; if (uri == null) { devices = deviceService.getDevices(); } else { Device dev = deviceService.getDevice(DeviceId.deviceId(uri)); devices = (dev == null) ? deviceService.getDevices() : Collections.singletonList(dev); } for (Device d : devices) { if (predicate.equals(TRUE_PREDICATE)) { rules = newArrayList(service.getFlowEntries(d.id())); } else { rules = newArrayList(); for (FlowEntry f : service.getFlowEntries(d.id())) { if (predicate.test(f)) { rules.add(f); } } } rules.sort(Comparators.FLOW_RULE_COMPARATOR); flows.put(d, rules); } return flows; }
Example #30
Source File: OltPipeline.java From onos with Apache License 2.0 | 5 votes |
@Override public void init(DeviceId deviceId, PipelinerContext context) { log.debug("Initiate OLT pipeline"); this.serviceDirectory = context.directory(); this.deviceId = deviceId; flowRuleService = serviceDirectory.get(FlowRuleService.class); coreService = serviceDirectory.get(CoreService.class); groupService = serviceDirectory.get(GroupService.class); flowObjectiveStore = context.store(); storageService = serviceDirectory.get(StorageService.class); appId = coreService.registerApplication( "org.onosproject.driver.OLTPipeline"); pendingGroups = CacheBuilder.newBuilder() .expireAfterWrite(20, TimeUnit.SECONDS) .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> { if (notification.getCause() == RemovalCause.EXPIRED) { fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED); } }).build(); groupService.addListener(new InnerGroupListener()); }