Search in sources :

Example 31 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class PimApplication method activate.

/**
 * 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");
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate)

Example 32 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class ApplicationCommand method manageApp.

// Manages the specified application.
private boolean manageApp(ApplicationAdminService service, String name) {
    ApplicationId appId = service.getId(name);
    if (appId == null) {
        List<Application> matches = service.getApplications().stream().filter(app -> app.id().name().matches(".*\\." + name + "$")).collect(Collectors.toList());
        if (matches.size() == 1) {
            // Found match
            appId = matches.iterator().next().id();
        } else if (!matches.isEmpty()) {
            print("Did you mean one of: %s", matches.stream().map(Application::id).map(ApplicationId::name).collect(Collectors.toList()));
            return false;
        }
    }
    if (appId == null) {
        print("No such application: %s", name);
        return false;
    }
    String action;
    if (command.equals(UNINSTALL)) {
        service.uninstall(appId);
        action = "Uninstalled";
    } else if (command.equals(ACTIVATE)) {
        service.activate(appId);
        action = "Activated";
    } else if (command.equals(DEACTIVATE)) {
        service.deactivate(appId);
        action = "Deactivated";
    } else {
        print("Unsupported command: %s", command);
        return false;
    }
    print("%s %s", action, appId.name());
    return true;
}
Also used : URL(java.net.URL) Argument(org.apache.karaf.shell.api.action.Argument) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) ByteStreams(com.google.common.io.ByteStreams) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ApplicationId(org.onosproject.core.ApplicationId) Completion(org.apache.karaf.shell.api.action.Completion) Application(org.onosproject.core.Application) ApplicationId(org.onosproject.core.ApplicationId) Application(org.onosproject.core.Application)

Example 33 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class ApplicationIdListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService service = get(CoreService.class);
    List<ApplicationId> ids = newArrayList(service.getAppIds());
    Collections.sort(ids, Comparators.APP_ID_COMPARATOR);
    if (outputJson()) {
        print("%s", json(ids));
    } else {
        for (ApplicationId id : ids) {
            print("id=%d, name=%s", id.id(), id.name());
        }
    }
}
Also used : CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 34 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class YangCompileCommand method doExecute.

@Override
protected void doExecute() {
    try {
        InputStream yangJar = new URL(url).openStream();
        YangLiveCompilerService compiler = get(YangLiveCompilerService.class);
        if (compileOnly) {
            ByteStreams.copy(compiler.compileYangFiles(modelId, yangJar), System.out);
        } else {
            ApplicationAdminService appService = get(ApplicationAdminService.class);
            if (forceReinstall) {
                ApplicationId appId = appService.getId(modelId);
                if (appId != null && appService.getApplication(appId) != null) {
                    appService.uninstall(appId);
                }
            }
            appService.install(compiler.compileYangFiles(modelId, yangJar));
            appService.activate(appService.getId(modelId));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : YangLiveCompilerService(org.onosproject.yang.YangLiveCompilerService) InputStream(java.io.InputStream) IOException(java.io.IOException) ApplicationId(org.onosproject.core.ApplicationId) URL(java.net.URL) ApplicationAdminService(org.onosproject.app.ApplicationAdminService)

Example 35 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class PiFlowRuleTranslatorImplTest method testTranslateFlowRules.

@Test
public void testTranslateFlowRules() throws Exception {
    ApplicationId appId = new DefaultApplicationId(1, "test");
    MacAddress ethDstMac = MacAddress.valueOf(random.nextLong());
    MacAddress ethSrcMac = MacAddress.valueOf(random.nextLong());
    short ethType = (short) (0x0000FFFF & random.nextInt());
    short outPort = (short) random.nextInt(65);
    short inPort = (short) random.nextInt(65);
    int timeout = random.nextInt(100);
    int priority = random.nextInt(100);
    TrafficSelector matchInPort1 = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(inPort)).matchEthDst(ethDstMac).matchEthSrc(ethSrcMac).matchEthType(ethType).build();
    TrafficSelector emptySelector = DefaultTrafficSelector.builder().build();
    TrafficTreatment outPort2 = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(outPort)).build();
    FlowRule rule1 = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(matchInPort1).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    FlowRule rule2 = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(matchInPort1).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    FlowRule defActionRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(emptySelector).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    PiTableEntry entry1 = PiFlowRuleTranslatorImpl.translate(rule1, pipeconf, null);
    PiTableEntry entry2 = PiFlowRuleTranslatorImpl.translate(rule2, pipeconf, null);
    PiTableEntry defActionEntry = PiFlowRuleTranslatorImpl.translate(defActionRule, pipeconf, null);
    // check equality, i.e. same rules must produce same entries
    new EqualsTester().addEqualityGroup(rule1, rule2).addEqualityGroup(entry1, entry2).testEquals();
    // parse values stored in entry1
    PiTernaryFieldMatch inPortParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_STANDARD_METADATA_INGRESS_PORT).get();
    PiTernaryFieldMatch ethDstParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_DST_ADDR).get();
    PiTernaryFieldMatch ethSrcParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_SRC_ADDR).get();
    PiTernaryFieldMatch ethTypeParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_ETHER_TYPE).get();
    Optional<Double> expectedTimeout = pipeconf.pipelineModel().table(INGRESS_TABLE0_CONTROL_TABLE0).get().supportsAging() ? Optional.of((double) rule1.timeout()) : Optional.empty();
    // check that values stored in entry are the same used for the flow rule
    assertThat("Incorrect inPort match param value", inPortParam.value().asReadOnlyBuffer().getShort(), is(equalTo(inPort)));
    assertThat("Incorrect inPort match param mask", inPortParam.mask().asReadOnlyBuffer().getShort(), is(equalTo(IN_PORT_MASK)));
    assertThat("Incorrect ethDestMac match param value", ethDstParam.value().asArray(), is(equalTo(ethDstMac.toBytes())));
    assertThat("Incorrect ethDestMac match param mask", ethDstParam.mask().asArray(), is(equalTo(MacAddress.BROADCAST.toBytes())));
    assertThat("Incorrect ethSrcMac match param value", ethSrcParam.value().asArray(), is(equalTo(ethSrcMac.toBytes())));
    assertThat("Incorrect ethSrcMac match param mask", ethSrcParam.mask().asArray(), is(equalTo(MacAddress.BROADCAST.toBytes())));
    assertThat("Incorrect ethType match param value", ethTypeParam.value().asReadOnlyBuffer().getShort(), is(equalTo(ethType)));
    assertThat("Incorrect ethType match param mask", ethTypeParam.mask().asReadOnlyBuffer().getShort(), is(equalTo(ETH_TYPE_MASK)));
    // FIXME: re-enable when P4Runtime priority handling will be moved out of transltion service
    // see PiFlowRuleTranslatorImpl
    // assertThat("Incorrect priority value",
    // entry1.priority().get(), is(equalTo(MAX_PI_PRIORITY - rule1.priority())));
    assertThat("Incorrect timeout value", entry1.timeout(), is(equalTo(expectedTimeout)));
    assertThat("Match key should be empty", defActionEntry.matchKey(), is(equalTo(PiMatchKey.EMPTY)));
    assertThat("Priority should not be set", !defActionEntry.priority().isPresent());
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationId (org.onosproject.core.ApplicationId)138 CoreService (org.onosproject.core.CoreService)36 Activate (org.osgi.service.component.annotations.Activate)36 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)25 Path (javax.ws.rs.Path)21 Produces (javax.ws.rs.Produces)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 GET (javax.ws.rs.GET)14 Test (org.junit.Test)13 ApplicationAdminService (org.onosproject.app.ApplicationAdminService)11 FlowRuleService (org.onosproject.net.flow.FlowRuleService)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Intent (org.onosproject.net.intent.Intent)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 InputStream (java.io.InputStream)9 DeviceId (org.onosproject.net.DeviceId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 IntentService (org.onosproject.net.intent.IntentService)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8