Java Code Examples for org.onosproject.core.CoreService#registerApplication()
The following examples show how to use
org.onosproject.core.CoreService#registerApplication() .
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: PacketRequestCodec.java From onos with Apache License 2.0 | 6 votes |
@Override public PacketRequest decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); TrafficSelector trafficSelector = trafficSelectorCodec.decode( get(json, TRAFFIC_SELECTOR), context); NodeId nodeId = NodeId.nodeId(extractMember(NODE_ID, json)); PacketPriority priority = PacketPriority.valueOf(extractMember(PRIORITY, json)); CoreService coreService = context.getService(CoreService.class); // TODO check appId (currently hardcoded - should it be read from json node?) ApplicationId appId = coreService.registerApplication(REST_APP_ID); DeviceId deviceId = null; JsonNode node = json.get(DEVICE_ID); if (node != null) { deviceId = DeviceId.deviceId(node.asText()); } return new DefaultPacketRequest(trafficSelector, priority, appId, nodeId, Optional.ofNullable(deviceId)); }
Example 2
Source File: ApplicationsWebResource.java From onos with Apache License 2.0 | 5 votes |
/** * Registers an on or off platform application. * * @param name application name * @return 200 OK; 404; 401 * @onos.rsModel ApplicationId */ @POST @Produces(MediaType.APPLICATION_JSON) @Path("{name}/register") public Response registerAppId(@PathParam("name") String name) { CoreService service = get(CoreService.class); ApplicationId appId = service.registerApplication(name); return response(appId); }
Example 3
Source File: PortWaveLengthCommand.java From onos with Apache License 2.0 | 4 votes |
@Override protected void doExecute() throws Exception { if (operation.equals("edit-config")) { FlowRuleService flowService = get(FlowRuleService.class); DeviceService deviceService = get(DeviceService.class); CoreService coreService = get(CoreService.class); ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString); TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder(); FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); // an empty traffic selector TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(cp.port()).build(); OchSignal ochSignal; if (parameter.contains("/")) { ochSignal = createOchSignal(); } else if (parameter.matches("-?\\d+(\\.\\d+)?")) { ochSignal = createOchSignalFromWavelength(deviceService, cp); } else { print("Signal or wavelength %s are in uncorrect format"); return; } if (ochSignal == null) { print("Error in creating OchSignal"); return; } TrafficTreatment trafficTreatment = trafficTreatmentBuilder .add(Instructions.modL0Lambda(ochSignal)) .add(Instructions.createOutput(deviceService.getPort(cp).number())) .build(); Device device = deviceService.getDevice(cp.deviceId()); int priority = 100; ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model"); log.info(appId.name()); FlowRule addFlow = flowRuleBuilder .withPriority(priority) .fromApp(appId) .withTreatment(trafficTreatment) .withSelector(trafficSelector) .forDevice(device.id()) .makePermanent() .build(); flowService.applyFlowRules(addFlow); String msg = String.format("Setting wavelength %s", ochSignal.centralFrequency().asGHz()); print(msg); } else { print("Operation %s are not supported now.", operation); } }
Example 4
Source File: MeterRequestCodec.java From onos with Apache License 2.0 | 4 votes |
@Override public MeterRequest decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } final JsonCodec<Band> meterBandCodec = context.codec(Band.class); CoreService coreService = context.getService(CoreService.class); // parse device id DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText()); // application id ApplicationId appId = coreService.registerApplication(REST_APP_ID); // parse burst boolean burst = false; JsonNode burstJson = json.get("burst"); if (burstJson != null) { burst = burstJson.asBoolean(); } // parse unit type String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText(); Meter.Unit meterUnit = null; switch (unit) { case "KB_PER_SEC": meterUnit = Meter.Unit.KB_PER_SEC; break; case "PKTS_PER_SEC": meterUnit = Meter.Unit.PKTS_PER_SEC; break; default: nullIsIllegal(meterUnit, "The requested unit " + unit + " is not defined for meter."); } // parse meter bands List<Band> bandList = new ArrayList<>(); JsonNode bandsJson = json.get(BANDS); checkNotNull(bandsJson); if (bandsJson != null) { IntStream.range(0, bandsJson.size()).forEach(i -> { ObjectNode bandJson = get(bandsJson, i); bandList.add(meterBandCodec.decode(bandJson, context)); }); } MeterRequest meterRequest; if (burst) { meterRequest = DefaultMeterRequest.builder() .fromApp(appId) .forDevice(deviceId) .withUnit(meterUnit) .withBands(bandList) .burst().add(); } else { meterRequest = DefaultMeterRequest.builder() .fromApp(appId) .forDevice(deviceId) .withUnit(meterUnit) .withBands(bandList).add(); } return meterRequest; }