Search in sources :

Example 31 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class RemovePeerCommand method doExecute.

@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }
    peerAddress = IpAddress.valueOf(ip);
    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerFromPeer(peerAddress);
    if (speaker == null) {
        print(PEER_NOT_FOUND, ip);
        return;
    }
    removePeerFromSpeakerConf(speaker, config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(PEER_REMOVE_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 32 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class TestCodecService method setup.

@Before
public void setup() throws IOException {
    storageService = new TestStorageService();
    mastershipService = createNiceMock(MastershipService.class);
    coreService = createNiceMock(CoreService.class);
    hostService = createNiceMock(HostService.class);
    deviceService = createNiceMock(DeviceService.class);
    expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
    networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
    networkConfigService = createNiceMock(NetworkConfigService.class);
    manager = new SimpleIntManager();
    manager.coreService = coreService;
    manager.deviceService = deviceService;
    manager.storageService = storageService;
    manager.mastershipService = mastershipService;
    manager.hostService = hostService;
    manager.netcfgService = networkConfigService;
    manager.netcfgRegistry = networkConfigRegistry;
    manager.eventExecutor = MoreExecutors.newDirectExecutorService();
    manager.codecService = codecService;
    expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).anyTimes();
    networkConfigRegistry.registerConfigFactory(anyObject());
    expectLastCall().once();
    Capture<NetworkConfigListener> capture = newCapture();
    networkConfigService.addListener(EasyMock.capture(capture));
    expectLastCall().once();
    IntReportConfig config = getIntReportConfig("/report-config.json");
    expect(networkConfigService.getConfig(APP_ID, IntReportConfig.class)).andReturn(config).anyTimes();
    replay(mastershipService, deviceService, coreService, hostService, networkConfigRegistry, networkConfigService);
    manager.activate();
    networkConfigListener = capture.getValue();
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) TestStorageService(org.onosproject.store.service.TestStorageService) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) MastershipService(org.onosproject.mastership.MastershipService) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Before(org.junit.Before)

Example 33 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project trellis-control by opennetworkinglab.

the class BlackHoleCommand method doExecute.

@Override
protected void doExecute() {
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    NetworkConfigService netcfgService = AbstractShellCommand.get(NetworkConfigService.class);
    SegmentRoutingAppConfig appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
    if (appConfig == null) {
        JsonNode jsonNode = new ObjectMapper().createObjectNode();
        netcfgService.applyConfig(srService.appId(), SegmentRoutingAppConfig.class, jsonNode);
        appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
    }
    Set<IpPrefix> blackHoleIps;
    switch(op) {
        case "list":
            appConfig.blackholeIPs().forEach(prefix -> print(prefix.toString()));
            break;
        case "add":
            blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
            blackHoleIps.add(IpPrefix.valueOf(prefix));
            appConfig.setBalckholeIps(blackHoleIps);
            appConfig.apply();
            break;
        case "remove":
            blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
            blackHoleIps.remove(IpPrefix.valueOf(prefix));
            appConfig.setBalckholeIps(blackHoleIps);
            appConfig.apply();
            break;
        default:
            throw new UnsupportedOperationException("Unknown operation " + op);
    }
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) IpPrefix(org.onlab.packet.IpPrefix) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 34 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project fabric-tna by stratum.

the class FabricUpfProgrammableTest method setUp.

@Before
public void setUp() throws Exception {
    FabricCapabilities capabilities = createMock(FabricCapabilities.class);
    expect(capabilities.supportUpf()).andReturn(true).anyTimes();
    replay(capabilities);
    // Services mock
    packetService = new MockPacketService();
    CoreService coreService = createMock(CoreService.class);
    NetworkConfigService netcfgService = createMock(NetworkConfigService.class);
    DeviceService deviceService = createMock(DeviceService.class);
    SlicingService slicingService = createMock(SlicingService.class);
    expect(slicingService.getSlices()).andReturn(Set.of(SliceId.of(SLICE_MOBILE))).anyTimes();
    expect(slicingService.getTrafficClasses(SliceId.of(SLICE_MOBILE))).andReturn(Set.of(TrafficClass.ELASTIC)).anyTimes();
    PiTranslationService piTranslationService = createMock(PiTranslationService.class);
    expect(coreService.getAppId(anyString())).andReturn(APP_ID).anyTimes();
    expect(netcfgService.getConfig(TestUpfConstants.DEVICE_ID, BasicDeviceConfig.class)).andReturn(TestUpfUtils.getBasicConfig(TestUpfConstants.DEVICE_ID, "/basic.json")).anyTimes();
    replay(coreService, netcfgService, slicingService);
    // Mock driverData to get the right device ID
    DriverData driverData = createMock(DriverData.class);
    expect(driverData.deviceId()).andReturn(TestUpfConstants.DEVICE_ID).anyTimes();
    replay(driverData);
    // Mock DriverHandler to get all the required mocked services
    DriverHandler driverHandler = createMock(DriverHandler.class);
    expect(driverHandler.get(FlowRuleService.class)).andReturn(new MockFlowRuleService()).anyTimes();
    expect(driverHandler.get(MeterService.class)).andReturn(new MockMeterService()).anyTimes();
    expect(driverHandler.get(SlicingService.class)).andReturn(slicingService).anyTimes();
    expect(driverHandler.get(PacketService.class)).andReturn(packetService).anyTimes();
    expect(driverHandler.get(NetworkConfigService.class)).andReturn(netcfgService).anyTimes();
    expect(driverHandler.get(CoreService.class)).andReturn(coreService).anyTimes();
    expect(driverHandler.get(DeviceService.class)).andReturn(deviceService).anyTimes();
    expect(driverHandler.get(PiTranslationService.class)).andReturn(piTranslationService).anyTimes();
    expect(driverHandler.get(PiPipeconfService.class)).andReturn(new MockPiPipeconfService(TABLE_MODELS, COUNTER_MODELS, METER_MODELS, TNA)).anyTimes();
    expect(driverHandler.get(P4RuntimeController.class)).andReturn(mockP4RtController).anyTimes();
    expect(driverHandler.data()).andReturn(driverData).anyTimes();
    replay(driverHandler);
    upfProgrammable = new FabricUpfProgrammable();
    TestUtils.setField(upfProgrammable, "handler", driverHandler);
    TestUtils.setField(upfProgrammable, "data", driverData);
    ConcurrentMap<DeviceId, URI> channelUris = TestUtils.getField(upfProgrammable, "CHANNEL_URIS");
    channelUris.put(TestUpfConstants.DEVICE_ID, new URI("grpc://localhost:1234?device_id=1"));
}
Also used : DriverData(org.onosproject.net.driver.DriverData) PacketService(org.onosproject.net.packet.PacketService) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) URI(java.net.URI) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) DriverHandler(org.onosproject.net.driver.DriverHandler) PiTranslationService(org.onosproject.net.pi.service.PiTranslationService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) MeterService(org.onosproject.net.meter.MeterService) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService) Before(org.junit.Before)

Aggregations

NetworkConfigService (org.onosproject.net.config.NetworkConfigService)34 CoreService (org.onosproject.core.CoreService)10 DeviceId (org.onosproject.net.DeviceId)9 ApplicationId (org.onosproject.core.ApplicationId)7 ConnectPoint (org.onosproject.net.ConnectPoint)6 DeviceService (org.onosproject.net.device.DeviceService)6 BgpConfig (org.onosproject.routing.config.BgpConfig)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Before (org.junit.Before)3 NetworkConfigListener (org.onosproject.net.config.NetworkConfigListener)3 SubjectFactory (org.onosproject.net.config.SubjectFactory)3 BasicDeviceConfig (org.onosproject.net.config.basics.BasicDeviceConfig)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2