Search in sources :

Example 76 with ApplicationId

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

the class ForwardingObjectiveCodecTest method testForwardingObjectiveDecode.

/**
 * Test decoding of a ForwardingObjective object.
 */
@Test
public void testForwardingObjectiveDecode() throws IOException {
    ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
    expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
    replay(mockCoreService);
    ForwardingObjective forwardingObjective = getForwardingObjective("ForwardingObjective.json");
    assertThat(forwardingObjective.flag(), is(ForwardingObjective.Flag.SPECIFIC));
    assertThat(forwardingObjective.priority(), is(60));
    assertThat(forwardingObjective.timeout(), is(1));
    assertThat(forwardingObjective.op(), is(ForwardingObjective.Operation.ADD));
    assertThat(forwardingObjective.permanent(), is(false));
    assertThat(forwardingObjective.appId().name(), is(SAMPLE_APP_ID));
}
Also used : DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ForwardingObjectiveJsonMatcher.matchesForwardingObjective(org.onosproject.codec.impl.ForwardingObjectiveJsonMatcher.matchesForwardingObjective) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 77 with ApplicationId

use of org.onosproject.core.ApplicationId 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 78 with ApplicationId

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

the class ApplicationIdCodecTest method testApplicationIdDecode.

/**
 * 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"));
}
Also used : DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Example 79 with ApplicationId

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

the class ReviewCommand method doExecute.

@Override
protected void doExecute() {
    ApplicationAdminService applicationAdminService = get(ApplicationAdminService.class);
    ApplicationId appId = applicationAdminService.getId(name);
    if (appId == null) {
        print("No such application: %s", name);
        return;
    }
    Application app = applicationAdminService.getApplication(appId);
    SecurityAdminService smService = SecurityUtil.getSecurityService();
    if (smService == null) {
        print("Security Mode is disabled");
        return;
    }
    if (accept == null) {
        smService.review(appId);
        printPolicy(smService, app);
    } else if ("accept".equals(accept.trim())) {
        smService.acceptPolicy(appId);
        printPolicy(smService, app);
    } else {
        print("Unknown command");
    }
}
Also used : SecurityAdminService(org.onosproject.security.SecurityAdminService) ApplicationId(org.onosproject.core.ApplicationId) Application(org.onosproject.core.Application) ApplicationAdminService(org.onosproject.app.ApplicationAdminService)

Example 80 with ApplicationId

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

the class SimpleGroupStoreTest method testGroupOperationFailure.

@Test
public void testGroupOperationFailure() {
    simpleGroupStore.deviceInitialAuditCompleted(D1, true);
    ApplicationId appId = new DefaultApplicationId(2, "org.groupstore.test");
    GroupKey key = new DefaultGroupKey("group1".getBytes());
    PortNumber[] ports = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.add(ports[0]);
    outPorts.add(ports[1]);
    List<GroupBucket> buckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:02")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
        buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    GroupDescription groupDesc = new DefaultGroupDescription(D1, Group.Type.SELECT, groupBuckets, key, null, appId);
    InternalGroupStoreDelegate checkStoreGroupDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_REQUESTED);
    simpleGroupStore.setDelegate(checkStoreGroupDelegate);
    // Testing storeGroup operation
    simpleGroupStore.storeGroupDescription(groupDesc);
    simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
    // Testing Group add operation failure
    Group createdGroup = simpleGroupStore.getGroup(D1, key);
    checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
    GroupOperation groupAddOp = GroupOperation.createAddGroupOperation(createdGroup.id(), createdGroup.type(), createdGroup.buckets());
    InternalGroupStoreDelegate checkGroupAddFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_FAILED);
    simpleGroupStore.setDelegate(checkGroupAddFailureDelegate);
    simpleGroupStore.groupOperationFailed(D1, groupAddOp);
    // Testing Group modify operation failure
    simpleGroupStore.unsetDelegate(checkGroupAddFailureDelegate);
    GroupOperation groupModOp = GroupOperation.createModifyGroupOperation(createdGroup.id(), createdGroup.type(), createdGroup.buckets());
    InternalGroupStoreDelegate checkGroupModFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_UPDATE_FAILED);
    simpleGroupStore.setDelegate(checkGroupModFailureDelegate);
    simpleGroupStore.groupOperationFailed(D1, groupModOp);
    // Testing Group modify operation failure
    simpleGroupStore.unsetDelegate(checkGroupModFailureDelegate);
    GroupOperation groupDelOp = GroupOperation.createDeleteGroupOperation(createdGroup.id(), createdGroup.type());
    InternalGroupStoreDelegate checkGroupDelFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_REMOVE_FAILED);
    simpleGroupStore.setDelegate(checkGroupDelFailureDelegate);
    simpleGroupStore.groupOperationFailed(D1, groupDelOp);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) PortNumber(org.onosproject.net.PortNumber) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupOperation(org.onosproject.net.group.GroupOperation) 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