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));
}
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;
}
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"));
}
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");
}
}
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);
}
Aggregations