use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class PortWaveLengthCommand method doExecute.
@Override
protected void doExecute() throws Exception {
if (operation.equals("edit-config") || operation.equals("delete-config")) {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
CoreService coreService = get(CoreService.class);
TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
ConnectPoint inCp, outCp = null;
Device inDevice, outDevice = null;
inCp = ConnectPoint.deviceConnectPoint(inConnectPointString);
inDevice = deviceService.getDevice(inCp.deviceId());
if (outConnectPointString != null) {
outCp = ConnectPoint.deviceConnectPoint(outConnectPointString);
outDevice = deviceService.getDevice(outCp.deviceId());
}
if (inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).build();
// Traffic treatment including ochSignal
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(inCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
}
}
if (inDevice.type().equals(Device.Type.ROADM)) {
if (outConnectPointString == null) {
print("[ERROR] output port is required for ROADM devices");
return;
}
if (!inDevice.equals(outDevice)) {
print("[ERROR] input and output ports must be on the same device");
return;
}
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
// Traffic treatment
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(outCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
}
}
if (!inDevice.type().equals(Device.Type.ROADM) && !inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
print("[ERROR] wrong device type: %s", inDevice.type());
}
} else {
print("[ERROR] operation %s is not yet supported", operation);
}
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class ApplicationIdListCommand method doExecute.
@Override
protected void doExecute() {
CoreService service = get(CoreService.class);
List<ApplicationId> ids = newArrayList(service.getAppIds());
Collections.sort(ids, Comparators.APP_ID_COMPARATOR);
if (outputJson()) {
print("%s", json(ids));
} else {
for (ApplicationId id : ids) {
print("id=%d, name=%s", id.id(), id.name());
}
}
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class FibInstallerTest method setUp.
@Before
public void setUp() throws Exception {
sSfibInstaller = new FibInstaller();
sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
ComponentContext mockContext = createNiceMock(ComponentContext.class);
routerConfig = new TestRouterConfig();
interfaceService = createMock(InterfaceService.class);
networkConfigService = createMock(NetworkConfigService.class);
networkConfigService.addListener(anyObject(NetworkConfigListener.class));
expectLastCall().anyTimes();
networkConfigRegistry = createMock(NetworkConfigRegistry.class);
flowObjectiveService = createMock(FlowObjectiveService.class);
applicationService = createNiceMock(ApplicationService.class);
replay(applicationService);
deviceService = new TestDeviceService();
CoreService coreService = createNiceMock(CoreService.class);
expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
replay(coreService);
sSfibInstaller.networkConfigService = networkConfigService;
sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
sSfibInstaller.interfaceService = interfaceService;
sSfibInstaller.flowObjectiveService = flowObjectiveService;
sSfibInstaller.applicationService = applicationService;
sSfibInstaller.coreService = coreService;
sSfibInstaller.routeService = new TestRouteService();
sSfibInstaller.deviceService = deviceService;
setUpNetworkConfigService();
setUpInterfaceService();
sSfibInstaller.activate(mockContext);
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class AddTestFlowsCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
CoreService coreService = get(CoreService.class);
ApplicationId appId = coreService.registerApplication("onos.test.flow.installer");
int flowsPerDevice = Integer.parseInt(flows);
int num = Integer.parseInt(numOfRuns);
ArrayList<Long> results = Lists.newArrayList();
Iterable<Device> devices = deviceService.getDevices();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(RandomUtils.nextInt(MAX_OUT_PORT))).build();
TrafficSelector.Builder sbuilder;
FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
FlowRuleOperations.Builder remove = FlowRuleOperations.builder();
for (Device d : devices) {
for (long i = 0; i < flowsPerDevice; i++) {
sbuilder = DefaultTrafficSelector.builder();
sbuilder.matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i)).matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));
int randomPriority = RandomUtils.nextInt(FlowRule.MAX_PRIORITY - FlowRule.MIN_PRIORITY + 1) + FlowRule.MIN_PRIORITY;
FlowRule addRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
FlowRule removeRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
rules.add(addRule);
remove.remove(removeRule);
}
}
// close stages
rules.newStage();
remove.newStage();
for (int i = 0; i < num; i++) {
printProgress("Run %d:", i);
latch = new CountDownLatch(2);
final CountDownLatch addSuccess = new CountDownLatch(1);
printProgress("..batch add request");
Stopwatch add = Stopwatch.createStarted();
flowService.apply(rules.build(new FlowRuleOperationsContext() {
private final Stopwatch timer = Stopwatch.createStarted();
@Override
public void onSuccess(FlowRuleOperations ops) {
timer.stop();
printProgress("..add success");
results.add(timer.elapsed(TimeUnit.MILLISECONDS));
if (results.size() == num) {
if (outputJson()) {
print("%s", json(new ObjectMapper(), true, results));
} else {
printTime(true, results);
}
}
latch.countDown();
addSuccess.countDown();
}
}));
try {
addSuccess.await();
// wait until all flows reaches ADDED state
while (!Streams.stream(flowService.getFlowEntriesById(appId)).allMatch(fr -> fr.state() == FlowEntryState.ADDED)) {
Thread.sleep(100);
}
add.stop();
printProgress("..completed %d ± 100 ms", add.elapsed(TimeUnit.MILLISECONDS));
} catch (InterruptedException e1) {
printProgress("Interrupted");
Thread.currentThread().interrupt();
}
printProgress("..cleaning up");
flowService.apply(remove.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
latch.countDown();
}
}));
try {
latch.await();
while (!Iterables.isEmpty(flowService.getFlowEntriesById(appId))) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
printProgress("Interrupted.");
Thread.currentThread().interrupt();
}
}
if (outputJson()) {
print("%s", json(new ObjectMapper(), true, results));
} else {
printTime(true, results);
}
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class PathIntentCompilerTest method setUp.
/**
* Configures mock objects used in all the test cases.
* Creates the intents to test as well.
*/
@Before
public void setUp() {
sut = new PathIntentCompiler();
coreService = createMock(CoreService.class);
expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
sut.coreService = coreService;
sut.resourceService = new MockResourceService();
super.setUp();
intent = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).path(new DefaultPath(pid, links, ScalarWeight.toWeight(hops))).build();
// Intent with VLAN encap without egress VLAN
constraintVlanIntent = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, links, ScalarWeight.toWeight(hops))).build();
// Intent with VLAN encap with ingress and egress VLAN
constrainIngressEgressVlanIntent = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, links, ScalarWeight.toWeight(hops))).build();
constraintMplsIntent = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.MPLS))).path(new DefaultPath(pid, links, ScalarWeight.toWeight(hops))).build();
edgeIntentNoVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, edgeNet, ScalarWeight.toWeight(edgeHops))).build();
edgeIntentIngressVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, edgeNet, ScalarWeight.toWeight(edgeHops))).build();
edgeIntentEgressVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, edgeNet, ScalarWeight.toWeight(edgeHops))).build();
edgeIntentVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, edgeNet, ScalarWeight.toWeight(edgeHops))).build();
singleHopIndirectIntentNoVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopIndirect, ScalarWeight.toWeight(singleHopIndirectHops))).build();
singleHopIndirectIntentIngressVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopIndirect, ScalarWeight.toWeight(singleHopIndirectHops))).build();
singleHopIndirectIntentEgressVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopIndirect, ScalarWeight.toWeight(singleHopIndirectHops))).build();
singleHopIndirectIntentVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopIndirect, ScalarWeight.toWeight(singleHopIndirectHops))).build();
singleHopDirectIntentNoVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopDirect, ScalarWeight.toWeight(singleHopDirectHops))).build();
singleHopDirectIntentIngressVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(treatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopDirect, ScalarWeight.toWeight(singleHopDirectHops))).build();
singleHopDirectIntentEgressVlan = PathIntent.builder().appId(APP_ID).selector(selector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopDirect, ScalarWeight.toWeight(singleHopDirectHops))).build();
singleHopDirectIntentVlan = PathIntent.builder().appId(APP_ID).selector(vlanSelector).treatment(vlanTreatment).priority(PRIORITY).constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN))).path(new DefaultPath(pid, singleHopDirect, ScalarWeight.toWeight(singleHopDirectHops))).build();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(PathIntent.class, sut);
intentExtensionService.unregisterCompiler(PathIntent.class);
registrator = new IntentConfigurableRegistrator();
registrator.extensionService = intentExtensionService;
registrator.cfgService = new ComponentConfigAdapter();
registrator.activate();
sut.registrator = registrator;
replay(coreService, intentExtensionService);
}
Aggregations