Search in sources :

Example 86 with Group

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);
        }
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Group(org.onosproject.net.group.Group) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 87 with Group

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.");
    }
}
Also used : Group(org.onosproject.net.group.Group) K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) GroupService(org.onosproject.net.group.GroupService)

Example 88 with Group

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));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) Test(org.junit.Test)

Example 89 with Group

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();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupEvent(org.onosproject.net.group.GroupEvent) GroupOperation(org.onosproject.net.group.GroupOperation) Test(org.junit.Test)

Example 90 with Group

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;
    }
}
Also used : Group(org.onosproject.net.group.Group) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) GroupId(org.onosproject.core.GroupId)

Aggregations

Group (org.onosproject.net.group.Group)120 DefaultGroup (org.onosproject.net.group.DefaultGroup)57 GroupKey (org.onosproject.net.group.GroupKey)56 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)45 GroupBucket (org.onosproject.net.group.GroupBucket)44 GroupBuckets (org.onosproject.net.group.GroupBuckets)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)38 NextGroup (org.onosproject.net.behaviour.NextGroup)37 ArrayList (java.util.ArrayList)36 GroupDescription (org.onosproject.net.group.GroupDescription)36 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)30 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)26 DeviceId (org.onosproject.net.DeviceId)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 GroupId (org.onosproject.core.GroupId)23 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 FlowRule (org.onosproject.net.flow.FlowRule)20 Instruction (org.onosproject.net.flow.instructions.Instruction)20