/* * Copyright 2016-present Open Networking Laboratory * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.test; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; import org.onosproject.net.Device; import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.FlowRuleService; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flowobjective.DefaultForwardingObjective; import org.onosproject.net.flowobjective.FlowObjectiveService; import org.onosproject.net.flowobjective.ForwardingObjective; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.onosproject.net.device.DeviceService; import java.util.ArrayList; import java.util.List; import java.util.Map; import static org.onosproject.net.PortNumber.portNumber; /** * Skeletal ONOS application component. */ @Component(immediate = true) public class AppComponent { private final Logger log = LoggerFactory.getLogger(getClass()); private static final int DEFAULT_TIMEOUT = 10; private static final int DEFAULT_PRIORITY = 10; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected DeviceService deviceService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected CoreService coreService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected FlowRuleService flowRuleService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected FlowObjectiveService flowObjectiveService; private ApplicationId appId; private List<FlowPusherTask> flows; @Activate protected void activate() { flows = new ArrayList<FlowPusherTask>(); appId = coreService.registerApplication("org.test.app"); log.info("Started " + appId.name()); Iterable<Device> devices = deviceService.getDevices(); for(Device d : devices) { log.info("Device id" + d.id()); FlowPusherTask task = new FlowPusherTask(); task.setFlowObjectiveService(this.flowObjectiveService); task.setFlowRuleService(this.flowRuleService); task.init(100); task.setAppId(appId); task.setDevice(d); //task.setnWorkers(100); task.schedule(); flows.add(task); } } @Deactivate protected void deactivate() { for(FlowPusherTask fp : flows) { fp.cancel(); } log.info("Stopped"); } }