org.onosproject.net.behaviour.NextGroup Java Examples
The following examples show how to use
org.onosproject.net.behaviour.NextGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 6 votes |
private void updateFlowObjectiveStore(Integer nextId, OfdpaNextGroup nextGrp) { synchronized (flowObjectiveStore) { // get fresh copy of what the store holds NextGroup next = flowObjectiveStore.getNextGroup(nextId); if (next == null || nextGrp.nextObjective().op() == Operation.ADD) { flowObjectiveStore.putNextGroup(nextId, nextGrp); return; } if (nextGrp.nextObjective().op() == Operation.ADD_TO_EXISTING) { List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); allActiveKeys = Lists.newArrayList(allActiveKeys); // If active keys shows only the top-level group without a chain of groups, // then it represents an empty group. Update by replacing empty chain. if (allActiveKeys.size() == 1 && allActiveKeys.get(0).size() == 1) { allActiveKeys.clear(); } allActiveKeys.addAll(nextGrp.allKeys()); flowObjectiveStore.putNextGroup(nextId, new OfdpaNextGroup(allActiveKeys, nextGrp.nextObjective())); } } }
Example #2
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 6 votes |
/** * As per the OFDPA 2.0 TTP, packets are sent out of ports by using * a chain of groups. The simple Next Objective passed in by the application * is broken up into a group chain. The following chains can be modified * depending on the parameters in the Next Objective. * 1. L2 Interface group (no chaining) * 2. L3 Unicast group -> L2 Interface group * * @param nextObj the nextObjective of type SIMPLE */ private void modifySimpleNextObjective(NextObjective nextObj, NextGroup nextGroup) { TrafficTreatment treatment = nextObj.next().iterator().next(); // determine if plain L2 or L3->L2 chain boolean plainL2 = true; for (Instruction ins : treatment.allInstructions()) { if (ins.type() == Instruction.Type.L2MODIFICATION) { L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST || l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC || l2ins.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { plainL2 = false; } } } if (plainL2) { modifyBucketInL2Group(nextObj, nextGroup); } else { modifyBucketInL3Group(nextObj, nextGroup); } return; }
Example #3
Source File: OvsOfdpaPipeline.java From onos with Apache License 2.0 | 6 votes |
/** * Determines if the forwarding objective will be used for double-tagged packets. * * @param fwd Forwarding objective * @return True if the objective was created for double-tagged packets, false otherwise. */ private boolean isDoubleTagged(ForwardingObjective fwd) { if (fwd.nextId() != null) { NextGroup next = getGroupForNextObjective(fwd.nextId()); if (next != null) { List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); // we only need the top level group's key Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); if (group != null) { int groupId = group.id().id(); if (((groupId & ~TYPE_MASK) == L3_UNICAST_TYPE) && ((groupId & TYPE_L3UG_DOUBLE_VLAN_MASK) == TYPE_L3UG_DOUBLE_VLAN_MASK)) { return true; } } } } return false; }
Example #4
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 6 votes |
/** * modifies group with next objective. * * @param nextObjective the NextObjective * @param nextGroup the NextGroup */ protected void modifyBucketFromGroup(NextObjective nextObjective, NextGroup nextGroup) { switch (nextObjective.type()) { case SIMPLE: Collection<TrafficTreatment> treatments = nextObjective.next(); if (treatments.size() != 1) { log.error("Next Objectives of type Simple should only have a " + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id()); fail(nextObjective, ObjectiveError.BADPARAMS); return; } modifySimpleNextObjective(nextObjective, nextGroup); break; default: fail(nextObjective, ObjectiveError.UNKNOWN); log.warn("Unknown next objective type {}", nextObjective.type()); } }
Example #5
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 6 votes |
NextGroup getGroupForNextObjective(Integer nextId) { NextGroup next = flowObjectiveStore.getNextGroup(nextId); if (next != null) { List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); if (gkeys != null && !gkeys.isEmpty()) { return next; } else { log.warn("Empty next group found in FlowObjective store for " + "next-id:{} in dev:{}", nextId, deviceId); } } else { log.warn("next-id {} not found in Flow objective store for dev:{}", nextId, deviceId); } return null; }
Example #6
Source File: SpringOpenTTP.java From onos with Apache License 2.0 | 5 votes |
private void removeBucketFromGroup(NextObjective nextObjective) { log.debug("removeBucketFromGroup in {}: for next objective id {}", deviceId, nextObjective.id()); NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); if (nextGroup != null) { Collection<TrafficTreatment> treatments = nextObjective.next(); TrafficTreatment treatment = treatments.iterator().next(); final GroupKey key = new DefaultGroupKey( appKryo.serialize(nextObjective .id())); Group group = groupService.getGroup(deviceId, key); if (group == null) { log.warn("Group is not found in {} for {}", deviceId, key); return; } GroupBucket bucket; if (group.type() == GroupDescription.Type.INDIRECT) { bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.SELECT) { bucket = DefaultGroupBucket.createSelectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.ALL) { bucket = DefaultGroupBucket.createAllGroupBucket(treatment); } else { log.warn("Unsupported Group type {}", group.type()); return; } GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket)); log.debug("Removing buckets from group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId); groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId); } }
Example #7
Source File: FlowObjectiveManager.java From onos with Apache License 2.0 | 5 votes |
@Override public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() { Map<Pair<Integer, DeviceId>, List<String>> nextObjGroupMap = new HashMap<>(); Map<Integer, NextGroup> allnexts = flowObjectiveStore.getAllGroups(); // XXX if the NextGroup after de-serialization actually stored info of the deviceId // then info on any nextObj could be retrieved from one controller instance. // Right now the drivers on one instance can only fetch for next-ids that came // to them. // Also, we still need to send the right next-id to the right driver as potentially // there can be different drivers for different devices. But on that account, // no instance should be decoding for another instance's nextIds. for (Map.Entry<Integer, NextGroup> e : allnexts.entrySet()) { // get the device this next Objective was sent to DeviceId deviceId = nextToDevice.get(e.getKey()); if (deviceId != null) { // this instance of the controller sent the nextObj to a driver Pipeliner pipeliner = getDevicePipeliner(deviceId); List<String> nextMappings = pipeliner.getNextMappings(e.getValue()); if (nextMappings != null) { //mappings.addAll(nextMappings); nextObjGroupMap.put(Pair.of(e.getKey(), deviceId), nextMappings); } } else { nextObjGroupMap.put(Pair.of(e.getKey(), deviceId), ImmutableList.of("nextId not in this onos instance")); } } return nextObjGroupMap; }
Example #8
Source File: FlowObjectiveManagerTest.java From onos with Apache License 2.0 | 5 votes |
@Override public NextGroup getNextGroup(Integer nextId) { if (nextId != 4) { byte[] data = new byte[1]; data[0] = 5; return new DefaultNextGroup(data); } else { return null; } }
Example #9
Source File: FlowObjectiveManager.java From onos with Apache License 2.0 | 5 votes |
@Override public List<String> getNextMappings() { List<String> mappings = new ArrayList<>(); Map<Integer, NextGroup> allnexts = flowObjectiveStore.getAllGroups(); // XXX if the NextGroup after de-serialization actually stored info of the deviceId // then info on any nextObj could be retrieved from one controller instance. // Right now the drivers on one instance can only fetch for next-ids that came // to them. // Also, we still need to send the right next-id to the right driver as potentially // there can be different drivers for different devices. But on that account, // no instance should be decoding for another instance's nextIds. for (Map.Entry<Integer, NextGroup> e : allnexts.entrySet()) { // get the device this next Objective was sent to DeviceId deviceId = nextToDevice.get(e.getKey()); mappings.add("NextId " + e.getKey() + ": " + ((deviceId != null) ? deviceId : "nextId not in this onos instance")); if (deviceId != null) { // this instance of the controller sent the nextObj to a driver Pipeliner pipeliner = getDevicePipeliner(deviceId); List<String> nextMappings = pipeliner.getNextMappings(e.getValue()); if (nextMappings != null) { mappings.addAll(nextMappings); } } } return mappings; }
Example #10
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 5 votes |
@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; }
Example #11
Source File: DistributedFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public NextGroup getNextGroup(Integer nextId) { Versioned<byte[]> versionGroup = nextGroups.get(nextId); if (versionGroup != null) { return new DefaultNextGroup(versionGroup.value()); } return null; }
Example #12
Source File: DistributedFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public NextGroup removeNextGroup(Integer nextId) { Versioned<byte[]> versionGroup = nextGroups.remove(nextId); if (versionGroup != null) { return new DefaultNextGroup(versionGroup.value()); } return null; }
Example #13
Source File: DistributedFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public Map<Integer, NextGroup> getAllGroups() { Map<Integer, NextGroup> nextGroupMappings = new HashMap<>(); for (int key : nextGroups.keySet()) { NextGroup nextGroup = getNextGroup(key); if (nextGroup != null) { nextGroupMappings.put(key, nextGroup); } } return nextGroupMappings; }
Example #14
Source File: SimpleVirtualFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public Map<Integer, NextGroup> getAllGroups(NetworkId networkId) { ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId); Map<Integer, NextGroup> nextGroupMappings = new HashMap<>(); for (int key : nextGroups.keySet()) { NextGroup nextGroup = getNextGroup(networkId, key); if (nextGroup != null) { nextGroupMappings.put(key, nextGroup); } } return nextGroupMappings; }
Example #15
Source File: SimpleVirtualFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public NextGroup removeNextGroup(NetworkId networkId, Integer nextId) { ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId); byte[] nextGroup = nextGroups.remove(nextId); updateNextGroupsMap(networkId, nextGroups); eventQ.add(new VirtualObjectiveEvent(networkId, ObjectiveEvent.Type.REMOVE, nextId)); return new DefaultNextGroup(nextGroup); }
Example #16
Source File: SimpleVirtualFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public NextGroup getNextGroup(NetworkId networkId, Integer nextId) { ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId); byte[] groupData = nextGroups.get(nextId); if (groupData != null) { return new DefaultNextGroup(groupData); } return null; }
Example #17
Source File: SimpleVirtualFlowObjectiveStore.java From onos with Apache License 2.0 | 5 votes |
@Override public void putNextGroup(NetworkId networkId, Integer nextId, NextGroup group) { ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId); nextGroups.put(nextId, group.data()); updateNextGroupsMap(networkId, nextGroups); eventQ.add(new VirtualObjectiveEvent(networkId, ObjectiveEvent.Type.ADD, nextId)); }
Example #18
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 5 votes |
/** * Removes buckets in the top level group of a possible group-chain. Does * not remove the groups in the group-chain pointed to by this bucket, as they * may be in use (referenced by other groups) elsewhere. * * @param nextObjective a next objective that contains information for the * buckets to be removed from the group * @param next the representation of the existing group-chains for this next * objective, from which the top-level buckets to remove are determined */ protected void removeBucketFromGroup(NextObjective nextObjective, NextGroup next) { if (nextObjective.type() != NextObjective.Type.HASHED && nextObjective.type() != NextObjective.Type.BROADCAST) { log.warn("RemoveBuckets not applied to nextType:{} in dev:{} for next:{}", nextObjective.type(), deviceId, nextObjective.id()); fail(nextObjective, ObjectiveError.UNSUPPORTED); return; } List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); List<Integer> indicesToRemove = Lists.newArrayList(); for (TrafficTreatment treatment : nextObjective.next()) { // find the top-level bucket in the group-chain by matching the // outport and label from different groups in the chain PortNumber portToRemove = readOutPortFromTreatment(treatment); int labelToRemove = readLabelFromTreatment(treatment); if (portToRemove == null) { log.warn("treatment {} of next objective {} has no outport.. " + "cannot remove bucket from group in dev: {}", treatment, nextObjective.id(), deviceId); continue; } List<Integer> existing = existingPortAndLabel(allActiveKeys, groupService, deviceId, portToRemove, labelToRemove); indicesToRemove.addAll(existing); } List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList(); indicesToRemove.forEach(index -> chainsToRemove .add(allActiveKeys.get(index))); if (chainsToRemove.isEmpty()) { log.warn("Could not find appropriate group-chain for removing bucket" + " for next id {} in dev:{}", nextObjective.id(), deviceId); fail(nextObjective, ObjectiveError.BADPARAMS); return; } removeBucket(chainsToRemove, nextObjective); }
Example #19
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 5 votes |
/** * Removes all groups in multiple possible group-chains that represent the next-obj. * * @param nextObjective the next objective to remove * @param next the NextGroup that represents the existing group-chain for * this next objective */ protected void removeGroup(NextObjective nextObjective, NextGroup next) { List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); List<GroupKey> groupKeys = allActiveKeys.stream() .map(Deque::getFirst).collect(Collectors.toList()); addPendingRemoveNextObjective(nextObjective, groupKeys); allActiveKeys .forEach(groupChain -> groupChain.forEach(groupKey -> groupService .removeGroup(deviceId, groupKey, nextObjective.appId()))); flowObjectiveStore.removeNextGroup(nextObjective.id()); }
Example #20
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 5 votes |
/** * Modify buckets in the L2 interface group. * * @param nextObjective a next objective that contains information for the * buckets to be modified in the group * @param next the representation of the existing group-chains for this next * objective, from which the innermost group buckets to remove are determined */ protected void modifyBucketInL2Group(NextObjective nextObjective, NextGroup next) { VlanId assignedVlan = readVlanFromSelector(nextObjective.meta()); if (assignedVlan == null) { log.warn("VLAN ID required by simple next obj is missing. Abort."); fail(nextObjective, ObjectiveError.BADPARAMS); return; } List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObjective, assignedVlan); // There is only one L2 interface group in this case GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc(); // Replace group bucket for L2 interface group groupService.setBucketsForGroup(deviceId, l2InterfaceGroupDesc.appCookie(), l2InterfaceGroupDesc.buckets(), l2InterfaceGroupDesc.appCookie(), l2InterfaceGroupDesc.appId()); // update store - synchronize access as there may be multiple threads // trying to remove buckets from the same group, each with its own // potentially stale copy of allActiveKeys synchronized (flowObjectiveStore) { // NOTE: The groupKey is computed by deviceId, VLAN and portNum. It remains the same when we modify L2IG. // Therefore we use the same groupKey of the existing group. List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); flowObjectiveStore.putNextGroup(nextObjective.id(), new OfdpaNextGroup(allActiveKeys, nextObjective)); } }
Example #21
Source File: VirtualNetworkFlowObjectiveManager.java From onos with Apache License 2.0 | 5 votes |
@Override public List<String> getNextMappings() { List<String> mappings = new ArrayList<>(); Map<Integer, NextGroup> allnexts = flowObjectiveStore.getAllGroups(); // XXX if the NextGroup after de-serialization actually stored info of the deviceId // then info on any nextObj could be retrieved from one controller instance. // Right now the drivers on one instance can only fetch for next-ids that came // to them. // Also, we still need to send the right next-id to the right driver as potentially // there can be different drivers for different devices. But on that account, // no instance should be decoding for another instance's nextIds. for (Map.Entry<Integer, NextGroup> e : allnexts.entrySet()) { // get the device this next Objective was sent to DeviceId deviceId = nextToDevice.get(e.getKey()); mappings.add("NextId " + e.getKey() + ": " + ((deviceId != null) ? deviceId : "nextId not in this onos instance")); if (deviceId != null) { // this instance of the controller sent the nextObj to a driver Pipeliner pipeliner = getDevicePipeliner(deviceId); List<String> nextMappings = pipeliner.getNextMappings(e.getValue()); if (nextMappings != null) { mappings.addAll(nextMappings); } } } return mappings; }
Example #22
Source File: FabricPipeliner.java From onos with Apache License 2.0 | 5 votes |
@Override public List<String> getNextMappings(NextGroup nextGroup) { final FabricNextGroup fabricNextGroup = KRYO.deserialize(nextGroup.data()); return fabricNextGroup.nextMappings().stream() .map(m -> format("%s -> %s", fabricNextGroup.type(), m)) .collect(Collectors.toList()); }
Example #23
Source File: DistributedFlowObjectiveStoreTest.java From onos with Apache License 2.0 | 5 votes |
@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)); }
Example #24
Source File: AbstractCorsaPipeline.java From onos with Apache License 2.0 | 4 votes |
private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) { TrafficSelector filteredSelector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst( ((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip()) .build(); TrafficTreatment.Builder tb = processSpecificRoutingTreatment(); if (fwd.nextId() != null) { NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId()); GroupKey key = appKryo.deserialize(next.data()); Group group = groupService.getGroup(deviceId, key); if (group == null) { log.warn("The group left!"); fail(fwd, ObjectiveError.GROUPMISSING); return ImmutableSet.of(); } tb.group(group.id()); } else { log.error("Missing NextObjective ID for ForwardingObjective {}", fwd.id()); fail(fwd, ObjectiveError.BADPARAMS); return ImmutableSet.of(); } Builder ruleBuilder = DefaultFlowRule.builder() .fromApp(fwd.appId()) .withPriority(fwd.priority()) .forDevice(deviceId) .withSelector(filteredSelector) .withTreatment(tb.build()); ruleBuilder = processSpecificRoutingRule(ruleBuilder); if (fwd.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(fwd.timeout()); } return Collections.singletonList(ruleBuilder.build()); }
Example #25
Source File: PicaPipeline.java From onos with Apache License 2.0 | 4 votes |
@Override public List<String> getNextMappings(NextGroup nextGroup) { // TODO Implementation deferred to vendor return null; }
Example #26
Source File: AbstractCorsaPipeline.java From onos with Apache License 2.0 | 4 votes |
@Override public List<String> getNextMappings(NextGroup nextGroup) { //TODO: to be implemented return Collections.emptyList(); }
Example #27
Source File: BasicPipelinerImpl.java From onos with Apache License 2.0 | 4 votes |
@Override public List<String> getNextMappings(NextGroup nextGroup) { // We do not use nextObjectives or groups. return Collections.emptyList(); }
Example #28
Source File: OltPipeline.java From onos with Apache License 2.0 | 4 votes |
@Override public List<String> getNextMappings(NextGroup nextGroup) { // TODO Implementation deferred to vendor return null; }
Example #29
Source File: FabricPipeliner.java From onos with Apache License 2.0 | 4 votes |
private void removeNextGroup(NextObjective obj) { final NextGroup removed = flowObjectiveStore.removeNextGroup(obj.id()); if (removed == null) { log.debug("NextGroup {} was not found in FlowObjectiveStore"); } }
Example #30
Source File: VirtualNetworkFlowObjectiveManager.java From onos with Apache License 2.0 | 4 votes |
@Override public NextGroup getNextGroup(Integer nextId) { return virtualFlowObjectiveStore.getNextGroup(networkId(), nextId); }