use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class LinkDiscoveryProviderTest method setUp.
@Before
public void setUp() {
coreService = createMock(CoreService.class);
expect(coreService.registerApplication(appId.name())).andReturn(appId).anyTimes();
replay(coreService);
provider.coreService = coreService;
provider.providerRegistry = linkRegistry;
provider.deviceService = deviceService;
provider.mastershipService = mastershipService;
provider.linkService = linkService;
provider.cfgService = new ComponentConfigAdapter();
AbstractProjectableModel.setDriverService(null, new DriverServiceAdapter());
provider.activate(null);
providerService = linkRegistry.registeredProvider();
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class NetconfDeviceProviderTest method setUp.
@Before
public void setUp() throws IOException {
coreService = createMock(CoreService.class);
expect(coreService.registerApplication(APP_NAME)).andReturn(appId).anyTimes();
replay(coreService);
provider.coreService = coreService;
provider.providerRegistry = deviceRegistry;
provider.mastershipService = mastershipService;
provider.deviceService = deviceService;
provider.providerService = providerService;
provider.cfgService = cfgService;
provider.controller = controller;
provider.deviceKeyAdminService = deviceKeyAdminService;
provider.componentConfigService = new ComponentConfigAdapter();
AbstractProjectableModel.setDriverService(null, new DriverServiceAdapter());
provider.activate(null);
devices.clear();
available = false;
firstRequest = true;
DeviceId subject = DeviceId.deviceId(NETCONF_DEVICE_ID_STRING);
DeviceId subjectIpv6 = DeviceId.deviceId(NETCONF_DEVICE_ID_STRING_IPV6);
String key = "netconf";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(jsonStream);
ConfigApplyDelegate delegate = new MockDelegate();
netconfDeviceConfig.init(subject, key, jsonNode, mapper, delegate);
JsonNode jsonNodesshKey = mapper.readTree(jsonStreamSshKey);
netconfDeviceConfigSshKey.init(subject, key, jsonNodesshKey, mapper, delegate);
JsonNode jsonNodeEmpty = mapper.createObjectNode();
netconfDeviceConfigEmptyIpv4.init(subject, key, jsonNodeEmpty, mapper, delegate);
netconfDeviceConfigEmptyIpv6.init(subjectIpv6, key, jsonNodeEmpty, mapper, delegate);
deviceAdded = new CountDownLatch(0);
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class VirtualNetworkMastershipManagerTest method setUp.
@Before
public void setUp() throws Exception {
virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
CoreService coreService = new TestCoreService();
TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
virtualNetworkManagerStore.activate();
manager = new VirtualNetworkManager();
manager.store = virtualNetworkManagerStore;
TestUtils.setField(manager, "coreService", coreService);
eventDeliveryService = new TestEventDispatcher();
NetTestTools.injectEventDispatcher(manager, eventDeliveryService);
SimpleVirtualMastershipStore store = new SimpleVirtualMastershipStore();
TestUtils.setField(store, "coreService", coreService);
store.activate();
testClusterService = new TestClusterService();
ServiceDirectory testDirectory = new TestServiceDirectory().add(VirtualNetworkStore.class, virtualNetworkManagerStore).add(CoreService.class, coreService).add(EventDeliveryService.class, eventDeliveryService).add(ClusterService.class, testClusterService).add(VirtualNetworkMastershipStore.class, store);
TestUtils.setField(manager, "serviceDirectory", testDirectory);
manager.activate();
createVnets();
mastershipMgr1 = new VirtualNetworkMastershipManager(manager, vnet1.id());
mastershipMgr2 = new VirtualNetworkMastershipManager(manager, vnet2.id());
service = mastershipMgr1;
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class FlowRuleCodec method encode.
@Override
public ObjectNode encode(FlowRule flowRule, CodecContext context) {
checkNotNull(flowRule, "Flow rule cannot be null");
CoreService service = context.getService(CoreService.class);
ApplicationId appId = service.getAppId(flowRule.appId());
String strAppId = (appId == null) ? "<none>" : appId.name();
final ObjectNode result = context.mapper().createObjectNode().put(ID, Long.toString(flowRule.id().value())).put(APP_ID, strAppId).put(PRIORITY, flowRule.priority()).put(TIMEOUT, flowRule.timeout()).put(IS_PERMANENT, flowRule.isPermanent()).put(DEVICE_ID, flowRule.deviceId().toString()).put(TABLE_ID, flowRule.tableId()).put(TABLE_NAME, flowRule.table().toString());
if (flowRule.treatment() != null) {
final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
result.set(TREATMENT, treatmentCodec.encode(flowRule.treatment(), context));
}
if (flowRule.selector() != null) {
final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
result.set(SELECTOR, selectorCodec.encode(flowRule.selector(), context));
}
return result;
}
use of org.onosproject.core.CoreService in project onos by opennetworkinglab.
the class ForwardingObjectiveCodec method decode.
@Override
public ForwardingObjective decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
CoreService coreService = context.getService(CoreService.class);
final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);
ObjectiveCodecHelper och = new ObjectiveCodecHelper();
DefaultForwardingObjective.Builder baseBuilder = DefaultForwardingObjective.builder();
final DefaultForwardingObjective.Builder builder = (DefaultForwardingObjective.Builder) och.decode(json, baseBuilder, context);
// application id
JsonNode appIdJson = json.get(APP_ID);
String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
builder.fromApp(coreService.registerApplication(appId));
// decode flag
String flagStr = nullIsIllegal(json.get(FLAG), FLAG + MISSING_MEMBER_MESSAGE).asText();
switch(flagStr) {
case "SPECIFIC":
builder.withFlag(ForwardingObjective.Flag.SPECIFIC);
break;
case "VERSATILE":
builder.withFlag(ForwardingObjective.Flag.VERSATILE);
break;
case "EGRESS":
builder.withFlag(ForwardingObjective.Flag.EGRESS);
break;
default:
throw new IllegalArgumentException("The requested flag " + flagStr + " is not defined for ForwardingObjective.");
}
// decode selector
JsonNode selectorJson = json.get(SELECTOR);
if (selectorJson != null) {
TrafficSelector trafficSelector = trafficSelectorCodec.decode((ObjectNode) selectorJson, context);
builder.withSelector(trafficSelector);
}
// decode treatment
JsonNode treatmentJson = json.get(TREATMENT);
if (treatmentJson != null) {
TrafficTreatment trafficTreatment = trafficTreatmentCodec.decode((ObjectNode) treatmentJson, context);
builder.withTreatment(trafficTreatment);
}
// decode nextId
JsonNode nextIdJson = json.get(NEXT_ID);
if (nextIdJson != null) {
builder.nextStep(nextIdJson.asInt());
}
// decode operation
String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
ForwardingObjective forwardingObjective = null;
switch(opStr) {
case "ADD":
forwardingObjective = builder.add();
break;
case "REMOVE":
forwardingObjective = builder.remove();
break;
default:
throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for FilteringObjective.");
}
return forwardingObjective;
}
Aggregations