use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class OpenstackGroupRuleManager method setRule.
@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId, GroupDescription.Type type, List<GroupBucket> buckets, boolean install) {
Group group = groupService.getGroup(deviceId, getGroupKey(groupId));
if (install) {
if (group == null) {
GroupDescription groupDesc = new DefaultGroupDescription(deviceId, type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
groupService.addGroup(groupDesc);
log.debug("Adding group table rule {}", groupId);
}
} else {
if (group != null) {
groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
log.debug("Removing group table rule {}", groupId);
}
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class K8sPurgeRulesCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowRuleService = get(FlowRuleService.class);
GroupService groupService = get(GroupService.class);
CoreService coreService = get(CoreService.class);
K8sNodeService k8sNodeService = get(K8sNodeService.class);
ApplicationId appId = coreService.getAppId(K8S_NETWORKING_APP_ID);
if (appId == null) {
error("Failed to purge kubernetes networking flow rules.");
return;
}
flowRuleService.removeFlowRulesById(appId);
print("Successfully purged flow rules installed by kubernetes networking app.");
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
// we make sure all flow rules are removed from the store
while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during rule purging...");
}
if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
break;
} else {
flowRuleService.removeFlowRulesById(appId);
print("Failed to purging flow rules, retrying rule purging...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
for (K8sNode node : k8sNodeService.completeNodes()) {
for (Group group : groupService.getGroups(node.intgBridge(), appId)) {
groupService.removeGroup(node.intgBridge(), group.appCookie(), appId);
}
}
if (result) {
print("Successfully purged flow rules!");
} else {
error("Failed to purge flow rules.");
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testRemoveGroupDescription.
/**
* Tests adding and removing a group.
*/
@Test
public void testRemoveGroupDescription() throws Exception {
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
groupStore.deleteGroupDescription(deviceId1, groupKey1);
// Group should still be there, marked for removal
assertThat(groupStore.getGroupCount(deviceId1), is(1));
Group queriedGroup = groupStore.getGroup(deviceId1, groupId1);
assertThat(queriedGroup.state(), is(Group.GroupState.PENDING_DELETE));
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testGroupOperationFailedWithErrorCode.
/**
* Tests group operation failed interface, with error codes for failures.
*/
@Test
public void testGroupOperationFailedWithErrorCode() {
TestDelegate delegate = new TestDelegate();
groupStore.setDelegate(delegate);
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
groupStore.storeGroupDescription(groupDescription2);
List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
assertThat(eventsAfterAdds, hasSize(2));
eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
delegate.resetEvents();
// test group exists
GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, ALL, allGroupBuckets);
GroupOperation addFailedExists = GroupOperation.createFailedGroupOperation(opAdd, GroupMsgErrorCode.GROUP_EXISTS);
groupStore.groupOperationFailed(deviceId1, addFailedExists);
List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
assertThat(eventsAfterAddFailed, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADDED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_ADDED));
Group g1 = groupStore.getGroup(deviceId1, groupId1);
assertEquals(0, g1.failedRetryCount());
delegate.resetEvents();
// test invalid group
Group g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(0, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD, g2.state());
GroupOperation opAdd1 = GroupOperation.createAddGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
GroupOperation addFailedInvalid = GroupOperation.createFailedGroupOperation(opAdd1, GroupMsgErrorCode.INVALID_GROUP);
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed1 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed1, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(1, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed2 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed2, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(2, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed3 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed3, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(null, g2);
delegate.resetEvents();
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class HPPipelineV3800 method tableIdForForwardingObjective.
@Override
protected int tableIdForForwardingObjective(TrafficSelector selector, TrafficTreatment treatment) {
boolean hardwareProcess = true;
log.debug("HP V3800 Driver - Evaluating the ForwardingObjective for proper TableID");
// Check criteria supported in hardware
for (Criterion criterion : selector.criteria()) {
if (!this.hardwareCriteria.contains(criterion.type())) {
log.warn("HP V3800 Driver - criterion {} only supported in SOFTWARE", criterion.type());
hardwareProcess = false;
break;
}
// HP3800 does not support hardware match on ETH_TYPE of value TYPE_VLAN
if (criterion.type() == Criterion.Type.ETH_TYPE) {
if (((EthTypeCriterion) criterion).ethType().toShort() == Ethernet.TYPE_VLAN) {
log.warn("HP V3800 Driver - ETH_TYPE == VLAN (0x8100) is only supported in software");
hardwareProcess = false;
break;
}
}
}
// Check if a CLEAR action is included
if (treatment.clearedDeferred()) {
log.warn("HP V3800 Driver - CLEAR action only supported in SOFTWARE");
hardwareProcess = false;
}
// If criteria can be processed in hardware, then check treatment
if (hardwareProcess) {
for (Instruction instruction : treatment.allInstructions()) {
// Check if the instruction type is contained in the hardware instruction
if (!this.hardwareInstructions.contains(instruction.type())) {
log.warn("HP V3800 Driver - instruction {} only supported in SOFTWARE", instruction.type());
hardwareProcess = false;
break;
}
/**
* If output is CONTROLLER_PORT the flow entry could be installed in hardware
* but is anyway processed in software because OPENFLOW header has to be added
*/
if (instruction.type() == Instruction.Type.OUTPUT) {
if (((Instructions.OutputInstruction) instruction).port() == PortNumber.CONTROLLER) {
log.warn("HP V3800 Driver - Forwarding to CONTROLLER only supported in software");
hardwareProcess = false;
break;
}
}
// Check if the specific L2MODIFICATION.subtype is supported in hardware
if (instruction.type() == Instruction.Type.L2MODIFICATION) {
if (!this.hardwareInstructionsL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
log.warn("HP V3800 Driver - L2MODIFICATION.subtype {} only supported in SOFTWARE", ((L2ModificationInstruction) instruction).subtype());
hardwareProcess = false;
break;
}
}
// TODO --- check if all the buckets contains one and only one output action
if (instruction.type() == Instruction.Type.GROUP) {
boolean groupInstalled = false;
GroupId groupId = ((Instructions.GroupInstruction) instruction).groupId();
Iterable<Group> groupsOnDevice = groupService.getGroups(deviceId);
for (Group group : groupsOnDevice) {
if ((group.state() == Group.GroupState.ADDED) && (group.id().equals(groupId))) {
groupInstalled = true;
if (group.type() != Group.Type.ALL) {
log.warn("HP V3800 Driver - group type {} only supported in SOFTWARE", group.type().toString());
hardwareProcess = false;
}
break;
}
}
if (!groupInstalled) {
log.warn("HP V3800 Driver - referenced group is not installed on the device.");
hardwareProcess = false;
}
}
}
}
if (hardwareProcess) {
log.warn("HP V3800 Driver - This flow rule is supported in HARDWARE");
return HP_HARDWARE_TABLE;
} else {
// TODO: create a specific flow in table 100 to redirect selected traffic on table 200
log.warn("HP V3800 Driver - This flow rule is only supported in SOFTWARE");
return HP_SOFTWARE_TABLE;
}
}
Aggregations