org.onosproject.core.ApplicationId Java Examples

The following examples show how to use org.onosproject.core.ApplicationId. 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: PimApplication.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Activate the PIM component.
 */
@Activate
public void activate() {
    // Get our application ID
    ApplicationId appId = coreService.registerApplication("org.onosproject.pim");

    // Build the traffic selector for PIM packets
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchIPProtocol(IPv4.PROTOCOL_PIM);

    // Use the traffic selector to tell the packet service which packets we want.
    packetService.addProcessor(processor, PacketProcessor.director(5));

    packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
            appId, Optional.empty());

    // Get a copy of the PIM Packet Handler
    pimPacketHandler = new PimPacketHandler();

    log.info("Started");
}
 
Example #2
Source File: TunnelManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
                                          TunnelEndPoint src, TunnelEndPoint dst,
                                          Annotations... annotations) {
    Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src,
                                                       dst, annotations);
    if (tunnels == null || tunnels.isEmpty()) {
        Tunnel tunnel = new DefaultTunnel(null, src, dst, null, null, null,
                                          null, null, annotations);
        Set<ProviderId> ids = getProviders();
        for (ProviderId providerId : ids) {
            TunnelProvider provider = getProvider(providerId);
            provider.setupTunnel(tunnel, null);
        }
    }
    return tunnels;
}
 
Example #3
Source File: IntentsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets intent installables by application ID and key.
 * @param appId application identifier
 * @param key   intent key
 *
 * @return 200 OK with array of the intent installables
 * @onos.rsModel Intents
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("installables/{appId}/{key}")
public Response getIntentWithInstallable(@PathParam("appId") String appId,
                                         @PathParam("key") String key) {
    final IntentService intentService = get(IntentService.class);
    final ApplicationId app = get(CoreService.class).getAppId(appId);
    nullIsNotFound(app, APP_ID_NOT_FOUND);

    Intent intent = intentService.getIntent(Key.of(key, app));
    if (intent == null) {
        long numericalKey = Long.decode(key);
        intent = intentService.getIntent(Key.of(numericalKey, app));
    }
    nullIsNotFound(intent, INTENT_NOT_FOUND);

    final Iterable<Intent> installables = intentService.getInstallableIntents(intent.key());
    final ObjectNode root = encodeArray(Intent.class, "installables", installables);
    return ok(root).build();
}
 
Example #4
Source File: ApplicationViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    String action = string(payload, "action");
    String name = string(payload, "name");

    if (action != null && name != null) {
        ApplicationAdminService service = get(ApplicationAdminService.class);
        ApplicationId appId = service.getId(name);
        switch (action) {
            case "activate":
                service.activate(appId);
                break;
            case "deactivate":
                service.deactivate(appId);
                break;
            case "uninstall":
                service.uninstall(appId);
                break;
            default:
                break;
        }
        chain(APP_DATA_REQ, payload);
    }
}
 
Example #5
Source File: FlowsListCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the flows passed as argument after confirmation is provided
 * for each of them.
 * If no explicit confirmation is provided, the flow is not removed.
 *
 * @param flows       list of flows to remove
 * @param flowService FlowRuleService object
 * @param coreService CoreService object
 */
public void removeFlowsInteractive(Iterable<FlowEntry> flows,
                                   FlowRuleService flowService, CoreService coreService) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    flows.forEach(flow -> {
        ApplicationId appId = coreService.getAppId(flow.appId());
        System.out.print(String.format("Id=%s, AppId=%s. Remove? [y/N]: ",
                                       flow.id(), appId != null ? appId.name() : "<none>"));
        String response;
        try {
            response = br.readLine();
            response = response.trim().replace("\n", "");
            if ("y".equals(response)) {
                flowService.removeFlowRules(flow);
            }
        } catch (IOException e) {
            response = "";
        }
        print(response);
    });
}
 
Example #6
Source File: PortLoadBalancerManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean reserve(PortLoadBalancerId portLoadBalancerId, ApplicationId appId) {
    // Check if the resource is available
    ApplicationId reservation = Versioned.valueOrNull(portLoadBalancerResStore.get(portLoadBalancerId));
    PortLoadBalancer portLoadBalancer = Versioned.valueOrNull(portLoadBalancerStore.get(portLoadBalancerId));
    if (reservation == null && portLoadBalancer != null) {
        log.debug("Reserving {} -> {} into port load balancer reservation store", portLoadBalancerId, appId);
        return portLoadBalancerResStore.put(portLoadBalancerId, appId) == null;
    } else if (reservation != null && reservation.equals(appId)) {
        // App try to reserve the resource a second time
        log.debug("Already reserved {} -> {} skip reservation", portLoadBalancerId, appId);
        return true;
    }
    log.warn("Reservation failed {} -> {}", portLoadBalancerId, appId);
    return false;
}
 
Example #7
Source File: DistributedTunnelStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Tunnel borrowTunnel(ApplicationId appId, TunnelId tunnelId,
                           Annotations... annotations) {
    Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
    if (orderSet == null) {
        orderSet = new HashSet<TunnelSubscription>();
    }
    TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
                            annotations);
    Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
    if (result == null || Tunnel.State.INACTIVE.equals(result.state())) {
        return null;
    }

    orderSet.add(order);
    orderRelationship.put(appId, orderSet);
    return result;
}
 
Example #8
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
protected DefaultGroupHandler(DeviceId deviceId, ApplicationId appId,
                              DeviceProperties config,
                              LinkService linkService,
                              FlowObjectiveService flowObjService,
                              SegmentRoutingManager srManager) {
    this.deviceId = checkNotNull(deviceId);
    this.appId = checkNotNull(appId);
    this.deviceConfig = checkNotNull(config);
    this.linkService = checkNotNull(linkService);
    this.allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds());
    try {
        this.ipv4NodeSegmentId = config.getIPv4SegmentId(deviceId);
        this.ipv6NodeSegmentId = config.getIPv6SegmentId(deviceId);
        this.isEdgeRouter = config.isEdgeDevice(deviceId);
        this.nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId));
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage()
                + " Skipping value assignment in DefaultGroupHandler");
    }
    this.flowObjectiveService = flowObjService;
    this.dsNextObjStore = srManager.dsNextObjStore();
    this.vlanNextObjStore = srManager.vlanNextObjStore();
    this.portNextObjStore = srManager.portNextObjStore();
    this.macVlanNextObjStore = srManager.macVlanNextObjStore();
    this.srManager = srManager;
    executorService.scheduleWithFixedDelay(new BucketCorrector(), 10,
                                           VERIFY_INTERVAL,
                                           TimeUnit.SECONDS);
    populateNeighborMaps();
}
 
Example #9
Source File: IntentMonitorAndRerouteManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Map<ApplicationId, Map<Key, Pair<Set<ElementId>, Set<ElementId>>>> getMonitoredIntents() {
    Map<ApplicationId, Map<Key, Pair<Set<ElementId>, Set<ElementId>>>> currentMonitoredIntents
            = new ConcurrentHashMap<>();
    monitoredIntents.forEach((appId, appIntents) -> {
        currentMonitoredIntents.put(appId, new ConcurrentHashMap<>());
        appIntents.forEach((intentKey, intent) -> {
            Pair<Set<ElementId>, Set<ElementId>> endPair = extractEndPoints(intent);
            if (endPair != null) {
                currentMonitoredIntents.get(appId).put(intentKey, endPair);
            }
        });
    });
    return currentMonitoredIntents;
}
 
Example #10
Source File: RemoveSpeakerCommand.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.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }

    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (!speaker.peers().isEmpty()) {
            // Removal not allowed when peer connections exist.
            print(PEERS_EXIST, name);
            return;
        }
    }

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

    print(SPEAKER_REMOVE_SUCCESS);
}
 
Example #11
Source File: VirtualNetworkGroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setBucketsForGroup(DeviceId deviceId,
                               GroupKey oldCookie,
                               GroupBuckets buckets,
                               GroupKey newCookie,
                               ApplicationId appId) {
    store.updateGroupDescription(networkId(),
                                 deviceId,
                                 oldCookie,
                                 VirtualNetworkGroupStore.UpdateType.SET,
                                 buckets,
                                 newCookie);
}
 
Example #12
Source File: Utils.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
public static FlowRule buildFlowRule(DeviceId switchId, ApplicationId appId,
                                     String tableId, PiCriterion piCriterion,
                                     PiTableAction piAction) {
    return DefaultFlowRule.builder()
            .forDevice(switchId)
            .forTable(PiTableId.of(tableId))
            .fromApp(appId)
            .withPriority(DEFAULT_FLOW_RULE_PRIORITY)
            .makePermanent()
            .withSelector(DefaultTrafficSelector.builder()
                                  .matchPi(piCriterion).build())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .build();
}
 
Example #13
Source File: VirtualNetworkGroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void addBucketsToGroup(DeviceId deviceId, GroupKey oldCookie, GroupBuckets buckets,
                              GroupKey newCookie, ApplicationId appId) {
    store.updateGroupDescription(networkId(),
                                 deviceId,
                                 oldCookie,
                                 VirtualNetworkGroupStore.UpdateType.ADD,
                                 buckets,
                                 newCookie);
}
 
Example #14
Source File: ApplicationsWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Uninstall application.
 * Uninstalls the specified application deactivating it first if necessary.
 *
 * @param name application name
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{name}")
public Response uninstallApp(@PathParam("name") String name) {
    ApplicationAdminService service = get(ApplicationAdminService.class);
    ApplicationId appId = service.getId(name);
    if (appId != null) {
        service.uninstall(appId);
    }
    return Response.noContent().build();
}
 
Example #15
Source File: IntentMonitorAndRerouteManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Map<ApplicationId, Map<Key, List<FlowEntry>>> getStats(ApplicationId appId, Key intentKey) {
    checkNotNull(appId);
    checkNotNull(intentKey);
    checkArgument(monitoredIntents.containsKey(appId));
    checkArgument(monitoredIntents.get(appId).containsKey(intentKey));

    Map<ApplicationId, Map<Key, List<FlowEntry>>> currentStatistics = new HashMap<>();
    currentStatistics.put(appId, new HashMap<>());
    List<FlowEntry> flowEntries = getStats(intentKey);
    currentStatistics.get(appId).put(intentKey, flowEntries);
    return currentStatistics;
}
 
Example #16
Source File: SimpleApplicationStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setPermissions(ApplicationId appId, Set<Permission> permissions) {
    Application app = getApplication(appId);
    if (app != null) {
        this.permissions.put(appId, permissions);
        delegate.notify(new ApplicationEvent(APP_PERMISSIONS_CHANGED, app));
    }
}
 
Example #17
Source File: DistributedTunnelStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean returnTunnel(ApplicationId appId, TunnelName tunnelName,
                            Annotations... annotations) {
    TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
                            annotations);
    return deleteOrder(order);
}
 
Example #18
Source File: DistributedApplicationStore.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Produces a registered application from the supplied description.
 */
private Application registerApp(ApplicationDescription appDesc) {
    ApplicationId appId = idStore.registerApplication(appDesc.name());
    return DefaultApplication
            .builder(appDesc)
            .withAppId(appId)
            .build();
}
 
Example #19
Source File: DistributedK8sNetworkPolicyStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate() {
    ApplicationId appId = coreService.registerApplication(APP_ID);
    networkPolicyStore = storageService.<String, NetworkPolicy>consistentMapBuilder()
            .withSerializer(Serializer.using(SERIALIZER_K8S_NETWORK_POLICY))
            .withName("k8s-network-policy-store")
            .withApplicationId(appId)
            .build();

    networkPolicyStore.addListener(networkPolicyMapListener);
    log.info("Started");
}
 
Example #20
Source File: GroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve all groups created by an application in the specified device
 * as seen by current controller instance.
 *
 * @param deviceId device identifier
 * @param appId    application id
 * @return collection of immutable group objects created by the application
 */
@Override
public Iterable<Group> getGroups(DeviceId deviceId,
                                 ApplicationId appId) {
    checkPermission(GROUP_READ);
    return Iterables.filter(
            store.getGroups(deviceId),
            g -> g != null && Objects.equals(g.appId(), appId));
}
 
Example #21
Source File: SimpleFabricManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ApplicationId appId() {
    if (appId == null) {
        appId = coreService.registerApplication(APP_ID);
    }
    return appId;
}
 
Example #22
Source File: ApplicationManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@java.lang.SuppressWarnings("squid:S1217")
// We really do mean to call run()
private void invokeHook(Runnable hook, ApplicationId appId) {
    if (hook != null) {
        try {
            hook.run();
        } catch (Exception e) {
            log.warn("Deactivate hook for application {} encountered an error",
                     appId.name(), e);
        }
    }
}
 
Example #23
Source File: FlowViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private FlowEntry findFlowById(String appIdText, String flowId) {
    String strippedFlowId = flowId.replaceAll(OX, EMPTY);
    FlowRuleService fs = get(FlowRuleService.class);
    int appIdInt = Integer.parseInt(appIdText);
    ApplicationId appId = new DefaultApplicationId(appIdInt, DETAILS);
    Iterable<FlowEntry> entries = fs.getFlowEntriesById(appId);

    for (FlowEntry entry : entries) {
        if (entry.id().toString().equals(strippedFlowId)) {
            return entry;
        }
    }

    return null;
}
 
Example #24
Source File: DomainPointToPointIntent.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new point-to-point domain intent with the supplied ingress/egress
 * ports and domainId.
 *
 * @param appId                application identifier
 * @param key                  explicit key to use for intent
 * @param priority             intent priority
 * @param filteredIngressPoint filtered ingress point
 * @param filteredEgressPoint  filtered egress point
 * @throws NullPointerException if {@code filteredIngressPoint} or
 *                              {@code filteredEgressPoint} or {@code appId}
 *                              or {@code links} or {@code constraints}
 *                              is null.
 */
private DomainPointToPointIntent(ApplicationId appId, Key key,
                                 int priority,
                                 FilteredConnectPoint filteredIngressPoint,
                                 FilteredConnectPoint filteredEgressPoint,
                                 TrafficTreatment treatment,
                                 List<Constraint> constraints,
                                 List<Link> links) {

    super(appId, key, resources(links),
          priority, ImmutableSet.of(filteredIngressPoint),
          ImmutableSet.of(filteredEgressPoint), treatment, constraints);
    this.links = links;

}
 
Example #25
Source File: MockCoreService.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ApplicationId registerApplication(String name) {
    // Check if the app already exists
    ApplicationId appId = getAppId(name);
    if (appId == null) {
        appId = new DefaultApplicationId(nextAppId, name);
        nextAppId += 1;
        appIds.add(appId);
    }
    return appId;
}
 
Example #26
Source File: DefaultMeter.java    From onos with Apache License 2.0 5 votes vote down vote up
private DefaultMeter(DeviceId deviceId, MeterCellId cellId, ApplicationId appId,
                     Unit unit, boolean burst, Collection<Band> bands) {
    this.deviceId = deviceId;
    this.cellId = cellId;
    this.appId = appId;
    this.unit = unit;
    this.burst = burst;
    this.bands = bands;
}
 
Example #27
Source File: ApplicationIdCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests decoding of an application id object.
 */
@Test
public void testApplicationIdDecode() throws IOException {
    ApplicationId appId = getApplicationId("ApplicationId.json");

    assertThat((int) appId.id(), is(1));
    assertThat(appId.name(), is("org.onosproject.foo"));
}
 
Example #28
Source File: DistributedTunnelStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Tunnel> borrowTunnel(ApplicationId appId,
                                       TunnelEndPoint src,
                                       TunnelEndPoint dst, Type type,
                                       Annotations... annotations) {
    Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
    if (orderSet == null) {
        orderSet = new HashSet<TunnelSubscription>();
    }
    TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
    boolean isExist = orderSet.contains(order);
    if (!isExist) {
        orderSet.add(order);
    }
    orderRelationship.put(appId, orderSet);
    TunnelKey key = TunnelKey.tunnelKey(src, dst);
    Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
    if (idSet == null || idSet.isEmpty()) {
        return Collections.emptySet();
    }
    Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
    for (TunnelId tunnelId : idSet) {
        Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
        if (type.equals(result.type())
                && Tunnel.State.ACTIVE.equals(result.state())) {
            tunnelSet.add(result);
        }
    }
    return tunnelSet;
}
 
Example #29
Source File: DistributedApplicationStore.java    From onos with Apache License 2.0 4 votes vote down vote up
private void uninstallDependentApps(ApplicationId appId) {
    getApplications().stream()
            .filter(a -> a.requiredApps().contains(appId.name()))
            .forEach(a -> remove(a.id()));
}
 
Example #30
Source File: DistributedApplicationStore.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void deactivate(ApplicationId appId) {
    deactivateDependentApps(appId);
    deactivate(appId, coreAppId);
}