Search in sources :

Example 46 with CoreService

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();
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) DriverServiceAdapter(org.onosproject.net.driver.DriverServiceAdapter) CoreService(org.onosproject.core.CoreService) Before(org.junit.Before)

Example 47 with CoreService

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);
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) DriverServiceAdapter(org.onosproject.net.driver.DriverServiceAdapter) DeviceId(org.onosproject.net.DeviceId) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Before(org.junit.Before)

Example 48 with CoreService

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;
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) SimpleVirtualMastershipStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualMastershipStore) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) ClusterService(org.onosproject.cluster.ClusterService) TestStorageService(org.onosproject.store.service.TestStorageService) ServiceDirectory(org.onlab.osgi.ServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) CoreService(org.onosproject.core.CoreService) Before(org.junit.Before)

Example 49 with CoreService

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ApplicationId(org.onosproject.core.ApplicationId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 50 with CoreService

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;
}
Also used : CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Aggregations

CoreService (org.onosproject.core.CoreService)71 Before (org.junit.Before)31 ApplicationId (org.onosproject.core.ApplicationId)30 FlowRuleService (org.onosproject.net.flow.FlowRuleService)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)12 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)12 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 DeviceId (org.onosproject.net.DeviceId)10 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)10 TestServiceDirectory (org.onlab.osgi.TestServiceDirectory)9 MockResourceService (org.onosproject.net.resource.MockResourceService)9 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)8 DistributedVirtualNetworkStore (org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore)8 DeviceService (org.onosproject.net.device.DeviceService)8 TestStorageService (org.onosproject.store.service.TestStorageService)8 ArrayList (java.util.ArrayList)7 DomainService (org.onosproject.net.domain.DomainService)6