use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method removePortNextObjective.
/**
* Removes simple next objective for a single port.
*
* @param deviceId device id that has the port to deal with
* @param portNum the outgoing port on the device
* @param vlanId vlan id associated with the port
* @param popVlan true if POP_VLAN action is applied on the packets, false otherwise
*/
public void removePortNextObjective(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
mbuilder.matchVlanId(vlanId);
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
tbuilder.immediate().setOutput(portNum);
if (popVlan) {
tbuilder.immediate().popVlan();
}
int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum, tbuilder.build(), mbuilder.build(), false);
PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(deviceId, portNum, tbuilder.build(), mbuilder.build());
if (portNextObjId != -1 && portNextObjStore.containsKey(key)) {
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(portNextObjId).withType(NextObjective.Type.SIMPLE).addTreatment(tbuilder.build()).fromApp(appId).withMeta(mbuilder.build());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("removePortNextObjective removes NextObj {} on {}", portNextObjId, deviceId), (objective, error) -> {
log.warn("removePortNextObjective failed to remove NextObj {} on {}: {}", portNextObjId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjBuilder.remove(context);
log.info("**removePortNextObjective: Submitted " + "next objective {} in device {}", portNextObjId, deviceId);
flowObjectiveService.next(deviceId, nextObjective);
portNextObjStore.remove(key);
}
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method addToHashedNextObjective.
/**
* Makes a call to the FlowObjective service to add buckets to
* a hashed group. User must ensure that all the ports & labels are meant
* same neighbor (ie. dstMac).
*
* @param portLabels a collection of port & label combinations to add
* to the hash group identified by the nextId
* @param dstMac destination mac address of next-hop
* @param nextId id for next-objective to which buckets will be added
*/
private void addToHashedNextObjective(Collection<PortLabel> portLabels, MacAddress dstMac, Integer nextId) {
// setup metadata to pass to nextObjective - indicate the vlan on egress
// if needed by the switch pipeline. Since hashed next-hops are always to
// other neighboring routers, there is no subnet assigned on those ports.
TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).withMeta(metabuilder.build()).fromApp(appId);
// Create the new buckets to be updated
portLabels.forEach(pl -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(pl.port).setEthDst(dstMac).setEthSrc(nodeMacAddr);
if (pl.popVlan) {
tBuilder.popVlan();
}
if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) {
tBuilder.pushMpls().copyTtlOut().setMpls(MplsLabel.mplsLabel(pl.edgeLabel));
}
nextObjBuilder.addTreatment(tBuilder.build());
});
log.debug("addToHash in device {}: Adding Bucket with port/label {} " + "to nextId {}", deviceId, portLabels, nextId);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("addToHash port/label {} addedTo " + "NextObj {} on {}", portLabels, nextId, deviceId), (objective, error) -> {
log.warn("addToHash failed to add port/label {} to NextObj {} on {}: {}", portLabels, nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjBuilder.addToExisting(context);
flowObjectiveService.next(deviceId, nextObjective);
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method createBcastGroupFromVlan.
/**
* Creates a single broadcast group from a given vlan id and list of ports.
*
* @param vlanId vlan id
* @param ports list of ports in the subnet
*/
public void createBcastGroupFromVlan(VlanId vlanId, Collection<PortNumber> ports) {
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
if (vlanNextObjStore.containsKey(key)) {
log.debug("Broadcast group for device {} and subnet {} exists", deviceId, vlanId);
return;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
int nextId = flowObjectiveService.allocateNextId();
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
ports.forEach(port -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (toPopVlan(port, vlanId)) {
tBuilder.popVlan();
}
tBuilder.setOutput(port);
nextObjBuilder.addTreatment(tBuilder.build());
});
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("createBroadcastGroupFromVlan installed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
log.warn("createBroadcastGroupFromVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = nextObjBuilder.add(context);
flowObjectiveService.next(deviceId, nextObj);
log.debug("createBcastGroupFromVlan: Submitted next objective {} " + "for vlan: {} in device {}", nextId, vlanId, deviceId);
vlanNextObjStore.put(key, nextId);
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method removeGroup.
/**
* Removes groups for the next objective ID given.
*
* @param objectiveId next objective ID to remove
* @return true if succeeds, false otherwise
*/
public boolean removeGroup(int objectiveId) {
for (Map.Entry<DestinationSetNextObjectiveStoreKey, NextNeighbors> e : dsNextObjStore.entrySet()) {
if (e.getValue().nextId() != objectiveId) {
continue;
}
// Right now it is just used in TunnelHandler
// remember in future that PW transit groups could
// be Indirect groups
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(objectiveId).withType(NextObjective.Type.HASHED).fromApp(appId);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("RemoveGroup removes NextObj {} on {}", objectiveId, deviceId), (objective, error) -> {
log.warn("RemoveGroup failed to remove NextObj {} on {}: {}", objectiveId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjBuilder.remove(context);
log.info("**removeGroup: Submited " + "next objective {} in device {}", objectiveId, deviceId);
flowObjectiveService.next(deviceId, nextObjective);
dsNextObjStore.remove(e.getKey());
return true;
}
return false;
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method removeBcastGroupFromVlan.
/**
* Removes a single broadcast group from a given vlan id.
* The group should be empty.
* @param deviceId device Id to remove the group
* @param portNum port number related to the group
* @param vlanId vlan id of the broadcast group to remove
* @param popVlan true if the TrafficTreatment involves pop vlan tag action
*/
public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
if (!vlanNextObjStore.containsKey(key)) {
log.debug("Broadcast group for device {} and subnet {} does not exist", deviceId, vlanId);
return;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
int nextId = vlanNextObjStore.get(key);
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (popVlan) {
tBuilder.popVlan();
}
tBuilder.setOutput(portNum);
nextObjBuilder.addTreatment(tBuilder.build());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("removeBroadcastGroupFromVlan removed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = nextObjBuilder.remove(context);
flowObjectiveService.next(deviceId, nextObj);
log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}", nextId, deviceId);
vlanNextObjStore.remove(key, nextId);
}
Aggregations