org.onosproject.net.config.NetworkConfigService Java Examples

The following examples show how to use org.onosproject.net.config.NetworkConfigService. 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: AnnotateDeviceCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);

    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    DeviceAnnotationConfig cfg = netcfgService.getConfig(deviceId, DeviceAnnotationConfig.class);
    if (cfg == null) {
        cfg = new DeviceAnnotationConfig(deviceId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(deviceId, DeviceAnnotationConfig.class, cfg.node());
}
 
Example #2
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets all network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @return 200 OK with network configuration JSON
 */
@GET
@Path("{subjectClassKey}/{subjectKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download(@PathParam("subjectClassKey") String subjectClassKey,
                         @PathParam("subjectKey") String subjectKey) {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = mapper().createObjectNode();
    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                           subjectClassNotFoundErrorString(subjectClassKey));
    produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey),
                       true,
                       subjectNotFoundErrorString(subjectClassKey, subjectKey));
    return ok(root).build();
}
 
Example #3
Source File: Srv6SidCompleter.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
    NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);

    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    stream(deviceService.getDevices())
            .map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class))
            .filter(Objects::nonNull)
            .map(Srv6DeviceConfig::mySid)
            .filter(Objects::nonNull)
            .forEach(sid -> strings.add(sid.toString()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #4
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets specific network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param configKey       configuration class key
 * @return 200 OK with network configuration JSON
 */
@GET
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download(@PathParam("subjectClassKey") String subjectClassKey,
                         @PathParam("subjectKey") String subjectKey,
                         @PathParam("configKey") String configKey) {
    NetworkConfigService service = get(NetworkConfigService.class);

    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                    subjectClassNotFoundErrorString(subjectClassKey));
    Object subject =
            nullIsNotFound(subjectFactory.createSubject(subjectKey),
                                    subjectNotFoundErrorString(subjectClassKey, subjectKey));

    Class configClass =
            nullIsNotFound(service.getConfigClass(subjectClassKey, configKey),
                           configKeyNotFoundErrorString(subjectClassKey, subjectKey, configKey));
    Config config = nullIsNotFound((Config) service.getConfig(subject, configClass),
                           configKeyNotFoundErrorString(subjectClassKey,
                                                        subjectKey,
                                                        configKey));
    return ok(config.node()).build();
}
 
Example #5
Source File: PeerConnectivityManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    super.setUp();

    interfaceService = createMock(InterfaceService.class);
    interfaceService.addListener(anyObject(InterfaceListener.class));
    expectLastCall().anyTimes();
    networkConfigService = createMock(NetworkConfigService.class);
    networkConfigService.addListener(anyObject(NetworkConfigListener.class));
    expectLastCall().anyTimes();
    bgpConfig = createMock(BgpConfig.class);
    sdnIpConfig = createMock(SdnIpConfig.class);

    // These will set expectations on routingConfig and interfaceService
    bgpSpeakers = setUpBgpSpeakers();
    interfaces = Collections.unmodifiableMap(setUpInterfaces());

    initPeerConnectivity();
    intentList = setUpIntentList();
}
 
Example #6
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Uploads bulk network configuration.
 *
 * @param request network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = readTreeFromStream(mapper(), request);
    List<String> errorMsgs = new ArrayList<String>();
    root.fieldNames()
            .forEachRemaining(sk -> {
                if (service.getSubjectFactory(sk) == null) {
                    errorMsgs.add(subjectClassNotValidErrorString(sk));
                } else if (!root.path(sk).isObject()) {
                    errorMsgs.add(subjectClassInvalidErrorString(sk));
                } else {
                    errorMsgs.addAll(consumeJson(service, (ObjectNode) root.path(sk),
                            service.getSubjectFactory(sk)));
                }
            });
    if (!errorMsgs.isEmpty()) {
        return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
    }
    return Response.ok().build();
}
 
Example #7
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Upload multiple network configurations for a subject class.
 *
 * @param subjectClassKey subject class key
 * @param request         network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Path("{subjectClassKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
                       InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = readTreeFromStream(mapper(), request);
    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                    subjectClassNotValidErrorString(subjectClassKey));
    List<String> errorMsgs = consumeJson(service, root, subjectFactory);
    if (!errorMsgs.isEmpty()) {
        return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
    }
    return Response.ok().build();
}
 
Example #8
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Upload mutliple network configurations for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param request         network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Path("{subjectClassKey}/{subjectKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
                       @PathParam("subjectKey") String subjectKey,
                       InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = readTreeFromStream(mapper(), request);
    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                    subjectClassNotValidErrorString(subjectClassKey));
    List<String> errorMsgs = consumeSubjectJson(service, root,
            subjectFactory.createSubject(subjectKey),
                             subjectClassKey);
    if (!errorMsgs.isEmpty()) {
        return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
    }
    return Response.ok().build();
}
 
Example #9
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Upload specific network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param configKey       configuration class key
 * @param request         network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
                       @PathParam("subjectKey") String subjectKey,
                       @PathParam("configKey") String configKey,
                       InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    JsonNode root = readTreeFromStream(mapper(), request);
    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                    subjectClassNotValidErrorString(subjectClassKey));
    service.applyConfig(subjectClassKey, subjectFactory.createSubject(subjectKey),
                        configKey, root);
    return Response.ok().build();
}
 
Example #10
Source File: SdnIpCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the encapsulation type for SDN-IP.
 *
 * @param encap the encapsulation type
 */
private void setEncap(String encap) {
    EncapsulationType encapType = EncapsulationType.enumFromString(encap);
    if (encapType.equals(EncapsulationType.NONE) &&
            !encapType.toString().equals(encap)) {
        print(ENCAP_NOT_FOUND, encap);
        return;
    }

    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(SdnIp.SDN_IP_APP);

    SdnIpConfig config = configService.addConfig(appId, SdnIpConfig.class);

    config.setEncap(encapType);
    config.apply();

    //configService.applyConfig(appId, SdnIpConfig.class, config.node());
}
 
Example #11
Source File: TroubleshootLoadSnapshotCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void loadNetworkConfigNib() {
    NetworkConfigService networkConfigService = get(NetworkConfigService.class);
    DeviceService deviceService = get(DeviceService.class);

    // Map of str ConnectPoint : InterfaceConfig
    Map<String, Config> portConfigMap = new HashMap<>();
    Lists.newArrayList(deviceService.getDevices().iterator())
            .forEach(device -> deviceService.getPorts(device.id())
                    .forEach(port -> {
                        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
                        portConfigMap.put(cp.toString(), networkConfigService.getConfig(cp, InterfaceConfig.class));
                    }));

    // Map of str DeviceId : SegmentRoutingDeviceConfig
    Map<String, Config> deviceConfigMap = new HashMap<>();
    Lists.newArrayList(deviceService.getDevices().iterator())
            .forEach(device -> deviceConfigMap.put(device.id().toString(),
                    networkConfigService.getConfig(device.id(), SegmentRoutingDeviceConfig.class)));

    NetworkConfigNib networkConfigNib = NetworkConfigNib.getInstance();
    networkConfigNib.setPortConfigMap(portConfigMap);
    networkConfigNib.setDeviceConfigMap(deviceConfigMap);
}
 
Example #12
Source File: GluonServer.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gluon data updating and deleting into/from NetworkConfig datastore.
 * config.apply will raise GluonConfig.class event for add,
 * get and delete operations.
 *
 * @param gluonConfigMessage Etcdresponse data after parsing
 */
public void processEtcdResponse(GluonConfig gluonConfigMessage) {

    NetworkConfigService configService =
            DefaultServiceDirectory.getService(NetworkConfigService.class);
    if (gluonConfigMessage.action.equals(ACTION_SET) ||
            gluonConfigMessage.action.equals(ACTION_GET)) {
        GluonConfig config = configService
                .addConfig(gluonConfigMessage.key, GluonConfig.class);
        config.setEtcdResponse(gluonConfigMessage);
        config.apply();
        log.info(DATA_UPDATED);
    } else if (gluonConfigMessage.action.equals(ACTION_DEL)) {
        configService.removeConfig(gluonConfigMessage.key,
                                   GluonConfig.class);
        log.info(DATA_REMOVED);
    } else {
        log.info(INVALID_ACTION);
    }
}
 
Example #13
Source File: RoutingConfiguration.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the router configurations.
 *
 * @param configService network config service
 * @param routingAppId routing app ID
 * @return set of router configurations
 */
public static Set<RoutersConfig.Router> getRouterConfigurations(
        NetworkConfigService configService, ApplicationId routingAppId) {

    RouterConfig config = configService.getConfig(
            routingAppId, RoutingService.ROUTER_CONFIG_CLASS);
    RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class);

    if (config != null) {
        log.warn(WARNING);
        log.warn(WARNING2);

        return Collections.singleton(
                new RoutersConfig.Router(config.getControlPlaneConnectPoint(),
                        config.getOspfEnabled(),
                        Sets.newHashSet(config.getInterfaces())));
    } else if (multiConfig != null) {
        return multiConfig.getRouters();
    } else {
        return Collections.emptySet();
    }
}
 
Example #14
Source File: CostConstraint.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the link based on cost type specified.
 *
 * @param link to validate cost type constraint
 * @param netCfgService instance of netCfgService
 * @return true if link satisfies cost constraint otherwise false
 */
public double isValidLink(Link link, NetworkConfigService netCfgService) {
    if (netCfgService == null) {
        return -1;
    }

    TeLinkConfig cfg = netCfgService.getConfig(LinkKey.linkKey(link.src(), link.dst()), TeLinkConfig.class);
    if (cfg == null) {
        //If cost configuration absent return -1[It is not L3 device]
        return -1;
    }

    switch (type) {
        case COST:
            //If IGP cost is zero then IGP cost is not assigned for that link
            return cfg.igpCost() == 0 ? -1 : cfg.igpCost();

        case TE_COST:
            //If TE cost is zero then TE cost is not assigned for that link
            return cfg.teCost() == 0 ? -1 : cfg.teCost();

        default:
            return -1;
    }
}
 
Example #15
Source File: DeviceViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    DeviceId deviceId = deviceId(string(payload, ID, ZERO_URI));
    String name = emptyToNull(string(payload, NAME, null));
    log.debug("Name change request: {} -- '{}'", deviceId, name);

    NetworkConfigService service = get(NetworkConfigService.class);
    BasicDeviceConfig cfg =
            service.addConfig(deviceId, BasicDeviceConfig.class);

    // Name attribute missing from the payload (or empty string)
    // means that the friendly name should be unset.
    cfg.name(name);
    cfg.apply();
    sendMessage(DEV_NAME_CHANGE_RESP, payload);
}
 
Example #16
Source File: HostViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    HostId hostId = hostId(string(payload, ID, ""));
    String name = emptyToNull(string(payload, NAME, null));
    log.debug("Name change request: {} -- '{}'", hostId, name);

    NetworkConfigService service = get(NetworkConfigService.class);
    BasicHostConfig cfg =
            service.addConfig(hostId, BasicHostConfig.class);

    // Name attribute missing from the payload (or empty string)
    // means that the friendly name should be unset.
    cfg.name(name);
    cfg.apply();
    sendMessage(HOST_NAME_CHANGE_RESP, payload);
}
 
Example #17
Source File: AnnotateHostCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    HostId hostId = HostId.hostId(uri);

    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    HostAnnotationConfig cfg = netcfgService.getConfig(hostId, HostAnnotationConfig.class);
    if (cfg == null) {
        cfg = new HostAnnotationConfig(hostId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(hostId, HostAnnotationConfig.class, cfg.node());
}
 
Example #18
Source File: AbstractGrpcHandlerBehaviour.java    From onos with Apache License 2.0 6 votes vote down vote up
protected URI mgmtUriFromNetcfg() {
    deviceId = handler().data().deviceId();

    final BasicDeviceConfig cfg = handler().get(NetworkConfigService.class)
            .getConfig(deviceId, BasicDeviceConfig.class);
    if (cfg == null || Strings.isNullOrEmpty(cfg.managementAddress())) {
        log.error("Missing or invalid config for {}, cannot derive " +
                          "gRPC server endpoints", deviceId);
        return null;
    }

    try {
        return new URI(cfg.managementAddress());
    } catch (URISyntaxException e) {
        log.error("Management address of {} is not a valid URI: {}",
                  deviceId, cfg.managementAddress());
        return null;
    }
}
 
Example #19
Source File: Srv6SidCompleter.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
    NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);

    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    stream(deviceService.getDevices())
            .map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class))
            .filter(Objects::nonNull)
            .map(Srv6DeviceConfig::mySid)
            .filter(Objects::nonNull)
            .forEach(sid -> strings.add(sid.toString()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #20
Source File: CreateNullDevice.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    NullProviders service = get(NullProviders.class);
    NetworkConfigService cfgService = get(NetworkConfigService.class);

    TopologySimulator simulator = service.currentSimulator();
    if (!validateSimulator(simulator) || !validateLocType(locType)) {
        return;
    }

    CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
    DeviceId deviceId = id == null ? sim.nextDeviceId() : DeviceId.deviceId(id);
    BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
    cfg.name(name);
    setUiCoordinates(cfg, locType, latOrY, longOrX);

    Tools.delay(10);
    sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()),
                     hw, sw, portCount);
}
 
Example #21
Source File: CapabilityConstraint.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the link based on capability constraint.
 *
 * @param link to validate source and destination based on capability constraint
 * @param deviceService instance of DeviceService
 * @param netCfgService instance of NetworkConfigService
 * @return true if link satisfies capability constraint otherwise false
 */
public boolean isValidLink(Link link, DeviceService deviceService, NetworkConfigService netCfgService) {
    if (deviceService == null || netCfgService == null) {
        return false;
    }

    Device srcDevice = deviceService.getDevice(link.src().deviceId());
    Device dstDevice = deviceService.getDevice(link.dst().deviceId());

    //TODO: Usage of annotations are for transient solution. In future will be replaced with the
    // network config service / Projection model.
    // L3 device
    if (srcDevice == null || dstDevice == null) {
        return false;
    }

    String srcLsrId = srcDevice.annotations().value(LSRID);
    String dstLsrId = dstDevice.annotations().value(LSRID);

    DeviceCapability srcDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(srcLsrId),
                                                                   DeviceCapability.class);
    DeviceCapability dstDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(dstLsrId),
                                                                   DeviceCapability.class);

    switch (capabilityType) {
    case WITH_SIGNALLING:
        return true;
    case WITHOUT_SIGNALLING_AND_WITHOUT_SR:
        return srcDeviceConfig != null && dstDeviceConfig != null
                && srcDeviceConfig.localLabelCap() && dstDeviceConfig.localLabelCap();
    case SR_WITHOUT_SIGNALLING:
        return srcDeviceConfig != null && dstDeviceConfig != null && srcDeviceConfig.srCap()
                && dstDeviceConfig.srCap() && srcDeviceConfig.labelStackCap() && dstDeviceConfig.labelStackCap();
    default:
        return false;
    }
}
 
Example #22
Source File: AddSpeakerCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);

    BgpConfig config = configService.addConfig(appId, BgpConfig.class);

    if (name != null) {
        BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
        if (speaker != null) {
            log.debug("Speaker already exists: {}", name);
            return;
        }
    }

    if (vlanId == null || vlanId.isEmpty()) {
        vlanIdObj = VlanId.NONE;
    } else {
        vlanIdObj = VlanId.vlanId(Short.valueOf(vlanId));
    }

    addSpeakerToConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());

    print(SPEAKER_ADD_SUCCESS);
}
 
Example #23
Source File: LayoutAlgorithm.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes layout algorithm for operating on device and host inventory.
 *
 * @param deviceService        device service
 * @param hostService          host service
 * @param linkService          link service
 * @param networkConfigService net config service
 */
protected void init(DeviceService deviceService,
                    HostService hostService,
                    LinkService linkService,
                    NetworkConfigService networkConfigService) {
    this.deviceService = deviceService;
    this.hostService = hostService;
    this.linkService = linkService;
    this.netConfigService = networkConfigService;
}
 
Example #24
Source File: AnnotatePortCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netcfgService = get(NetworkConfigService.class);


    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port);
    if (deviceService.getPort(connectPoint) == null) {
        print("Port %s does not exist.", port);
        return;
    }

    if (removeCfg && key == null) {
        // remove whole port annotation config
        netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class);
        print("Annotation Config about %s removed", connectPoint);
        return;
    }

    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }

    PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class);
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    cfg.apply();
}
 
Example #25
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance with the specified ResourceAdminService and ExecutorService.
 *
 * @param adminService instance invoked to register resources
 * @param resourceService {@link ResourceQueryService} to be used
 * @param deviceService {@link DeviceService} to be used
 * @param mastershipService {@link MastershipService} to be used
 * @param driverService {@link DriverService} to be used
 * @param netcfgService {@link NetworkConfigService} to be used.
 * @param executor executor used for processing resource registration
 */
ResourceDeviceListener(ResourceAdminService adminService, ResourceQueryService resourceService,
                       DeviceService deviceService, MastershipService mastershipService,
                       DriverService driverService, NetworkConfigService netcfgService,
                       ExecutorService executor) {
    this.adminService = checkNotNull(adminService);
    this.resourceService = checkNotNull(resourceService);
    this.deviceService = checkNotNull(deviceService);
    this.mastershipService = checkNotNull(mastershipService);
    this.driverService = checkNotNull(driverService);
    this.netcfgService = checkNotNull(netcfgService);
    this.executor = checkNotNull(executor);
}
 
Example #26
Source File: RegionAddCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    RegionAdminService service = get(RegionAdminService.class);
    RegionId regionId = RegionId.regionId(id);

    NetworkConfigService cfgService = get(NetworkConfigService.class);
    BasicRegionConfig cfg = cfgService.addConfig(regionId, BasicRegionConfig.class);
    setConfigurationData(cfg);

    List<Set<NodeId>> masters = parseMasterArgs();
    service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
    print("Region successfully added.");
}
 
Example #27
Source File: ConfigureLinkCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netCfgService = get(NetworkConfigService.class);

    ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src);
    if (deviceService.getPort(srcCp) == null) {
        print("[ERROR] %s does not exist", srcCp);
        return;
    }

    ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst);
    if (deviceService.getPort(dstCp) == null) {
        print("[ERROR] %s does not exist", dstCp);
        return;
    }

    LinkKey link = linkKey(srcCp, dstCp);
    if (remove) {
        netCfgService.removeConfig(link, BasicLinkConfig.class);
        return;
    }

    Long bw = Optional.ofNullable(bandwidth)
                    .map(Long::valueOf)
                    .orElse(null);

    Link.Type linkType = Link.Type.valueOf(type);

    BasicLinkConfig cfg = netCfgService.addConfig(link, BasicLinkConfig.class);
    cfg.isAllowed(!disallow);
    cfg.isBidirectional(!isUniDi);
    cfg.type(linkType);
    if (bw != null) {
        cfg.bandwidth(bw);
    }

    cfg.apply();
}
 
Example #28
Source File: MeterManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
TestDriverManager(DriverRegistry registry, DeviceService deviceService,
                  NetworkConfigService networkConfigService) {
    this.registry = registry;
    this.deviceService = deviceService;
    this.networkConfigService = networkConfigService;
    this.pipeconfService = new PiPipeconfServiceAdapter();
    activate();
}
 
Example #29
Source File: PeerConnectivityManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new PeerConnectivityManager.
 *
 * @param appId              the application ID
 * @param intentSynchronizer the intent synchronizer
 * @param configService      the network config service
 * @param routerAppId        application ID
 * @param interfaceService   the interface service
 */
public PeerConnectivityManager(ApplicationId appId,
                               IntentSynchronizationService intentSynchronizer,
                               NetworkConfigService configService,
                               ApplicationId routerAppId,
                               InterfaceService interfaceService) {
    this.appId = appId;
    this.intentSynchronizer = intentSynchronizer;
    this.configService = configService;
    this.routerAppId = routerAppId;
    this.interfaceService = interfaceService;

    peerIntents = new HashMap<>();
}
 
Example #30
Source File: RegionAddPeerLocCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    RegionId regionId = RegionId.regionId(id);

    NetworkConfigService cfgService = get(NetworkConfigService.class);
    BasicRegionConfig cfg = cfgService.getConfig(regionId, BasicRegionConfig.class);

    cfg.addPeerLocMapping(peerId, locType, latOrY, longOrX)
            .apply();
}