Search in sources :

Example 36 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class DistributedFlowObjectiveStoreTest method testFlowObjectiveStore.

@Test
public void testFlowObjectiveStore() {
    NextGroup group1 = new DefaultNextGroup("1".getBytes(Charsets.US_ASCII));
    NextGroup group2 = new DefaultNextGroup("2".getBytes(Charsets.US_ASCII));
    NextGroup group3 = new DefaultNextGroup("3".getBytes(Charsets.US_ASCII));
    int group1Id = store.allocateNextId();
    int group2Id = store.allocateNextId();
    int group3Id = store.allocateNextId();
    NextGroup group1add = store.getNextGroup(group1Id);
    assertThat(group1add, nullValue());
    NextGroup dif = store.getNextGroup(3);
    assertThat(dif, is(nullValue()));
    store.putNextGroup(group1Id, group1);
    store.putNextGroup(group2Id, group2);
    NextGroup group2Query = store.getNextGroup(group2Id);
    assertThat(group2Query.data(), is(group2.data()));
    assertTrue(store.getAllGroups().containsKey(group2Id));
    assertTrue(store.getAllGroups().containsKey(group1Id));
    store.removeNextGroup(group2Id);
    assertTrue(store.getAllGroups().containsKey(group1Id));
    assertFalse(store.getAllGroups().containsKey(group2Id));
    store.removeNextGroup(group1Id);
    assertEquals(store.getAllGroups(), Collections.emptyMap());
    store.putNextGroup(group3Id, group3);
    store.removeNextGroup(group2Id);
    NextGroup nullGroup = store.getNextGroup(group2Id);
    assertThat(nullGroup, nullValue());
    assertThat(store.getAllGroups().size(), is(1));
    assertThat(store.getAllGroups(), IsMapContaining.hasKey(group3Id));
}
Also used : DefaultNextGroup(org.onosproject.net.behaviour.DefaultNextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) DefaultNextGroup(org.onosproject.net.behaviour.DefaultNextGroup) Test(org.junit.Test)

Example 37 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class Ofdpa3Pipeline method processTermPwVersatile.

private Collection<FlowRule> processTermPwVersatile(ForwardingObjective forwardingObjective, ModTunnelIdInstruction modTunnelIdInstruction, OutputInstruction outputInstruction) {
    TrafficTreatment.Builder flowTreatment;
    TrafficSelector.Builder flowSelector;
    // We divide the mpls actions from the tunnel actions. We need
    // this to order the actions in the final treatment.
    TrafficTreatment.Builder mplsTreatment = DefaultTrafficTreatment.builder();
    createMplsTreatment(forwardingObjective.treatment(), mplsTreatment);
    // The match of the forwarding objective is ready to go.
    flowSelector = DefaultTrafficSelector.builder(forwardingObjective.selector());
    // We verify the tunnel id and mpls port are correct.
    long tunnelId = MPLS_TUNNEL_ID_BASE | modTunnelIdInstruction.tunnelId();
    if (tunnelId > MPLS_TUNNEL_ID_MAX) {
        log.error("Pw Versatile Forwarding Objective must include tunnel id < {}", MPLS_TUNNEL_ID_MAX);
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // 0x0002XXXX is NNI interface.
    int mplsLogicalPort = ((int) outputInstruction.port().toLong()) | MPLS_NNI_PORT_BASE;
    if (mplsLogicalPort > MPLS_NNI_PORT_MAX) {
        log.error("Pw Versatile Forwarding Objective invalid logical port {}", mplsLogicalPort);
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // Next id cannot be null.
    if (forwardingObjective.nextId() == null) {
        log.error("Pw Versatile Forwarding Objective must contain nextId ", forwardingObjective.nextId());
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // We retrieve the l2 interface group and point the mpls
    // flow to this.
    NextGroup next = getGroupForNextObjective(forwardingObjective.nextId());
    if (next == null) {
        log.warn("next-id:{} not found in dev:{}", forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
    Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
    if (group == null) {
        log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    // We prepare the treatment for the mpls flow table.
    // The order of the actions has to be strictly this
    // according to the OFDPA 2.0 specification.
    flowTreatment = DefaultTrafficTreatment.builder(mplsTreatment.build());
    flowTreatment.extension(new Ofdpa3PopCw(), deviceId);
    // Even though the specification and the xml/json files
    // specify is allowed, the switch rejects the flow. In the
    // OFDPA 3.0 EA0 version was necessary
    // flowTreatment.popVlan();
    flowTreatment.extension(new Ofdpa3PopL2Header(), deviceId);
    flowTreatment.setTunnelId(tunnelId);
    flowTreatment.extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId);
    flowTreatment.extension(new Ofdpa3SetMplsType(VPWS), deviceId);
    flowTreatment.transition(MPLS_TYPE_TABLE);
    flowTreatment.deferred().group(group.id());
    // We prepare the flow rule for the mpls table.
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(forwardingObjective.appId()).withPriority(forwardingObjective.priority()).forDevice(deviceId).withSelector(flowSelector.build()).withTreatment(flowTreatment.build()).makePermanent().forTable(MPLS_TABLE_1);
    return Collections.singletonList(ruleBuilder.build());
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) Ofdpa3PopCw(org.onosproject.driver.extensions.Ofdpa3PopCw) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Deque(java.util.Deque) Ofdpa3SetMplsL2Port(org.onosproject.driver.extensions.Ofdpa3SetMplsL2Port) Ofdpa3PopL2Header(org.onosproject.driver.extensions.Ofdpa3PopL2Header) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Ofdpa3SetMplsType(org.onosproject.driver.extensions.Ofdpa3SetMplsType)

Example 38 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method getNextMappings.

@Override
public List<String> getNextMappings(NextGroup nextGroup) {
    List<String> mappings = new ArrayList<>();
    List<Deque<GroupKey>> gkeys = appKryo.deserialize(nextGroup.data());
    for (Deque<GroupKey> gkd : gkeys) {
        Group lastGroup = null;
        StringBuilder gchain = new StringBuilder();
        for (GroupKey gk : gkd) {
            Group g = groupService.getGroup(deviceId, gk);
            if (g == null) {
                gchain.append("  NoGrp").append(" -->");
                continue;
            }
            gchain.append("  0x").append(Integer.toHexString(g.id().id())).append(" -->");
            lastGroup = g;
        }
        // add port information for last group in group-chain
        List<Instruction> lastGroupIns = new ArrayList<>();
        if (lastGroup != null && !lastGroup.buckets().buckets().isEmpty()) {
            lastGroupIns = lastGroup.buckets().buckets().get(0).treatment().allInstructions();
        }
        for (Instruction i : lastGroupIns) {
            if (i instanceof OutputInstruction) {
                gchain.append(" port:").append(((OutputInstruction) i).port());
            }
        }
        mappings.add(gchain.toString());
    }
    return mappings;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque)

Aggregations

NextGroup (org.onosproject.net.behaviour.NextGroup)38 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)25 Group (org.onosproject.net.group.Group)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)18 Deque (java.util.Deque)17 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)17 FlowRule (org.onosproject.net.flow.FlowRule)17 ArrayList (java.util.ArrayList)16 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)12 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)12 GroupKey (org.onosproject.net.group.GroupKey)12 ArrayDeque (java.util.ArrayDeque)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)10 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)9 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)9 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)8 IpPrefix (org.onlab.packet.IpPrefix)6 DeviceId (org.onosproject.net.DeviceId)6