use of org.onosproject.net.flow.TrafficSelector in project trellis-control by opennetworkinglab.
the class TrafficMatchAddCommand method doExecute.
@Override
protected void doExecute() {
TrafficSelector trafficSelector = parseArguments();
if (trafficSelector.equals(DefaultTrafficSelector.emptySelector())) {
print("Empty traffic selector is not allowed");
return;
}
TrafficMatchPriority trafficMatchPriority;
try {
trafficMatchPriority = new TrafficMatchPriority(priority);
} catch (IllegalArgumentException ex) {
print(ex.getMessage());
return;
}
PolicyService policyService = AbstractShellCommand.get(PolicyService.class);
TrafficMatchId trafficMatchId = policyService.addOrUpdateTrafficMatch(new TrafficMatch(trafficSelector, PolicyId.of(policyId), trafficMatchPriority));
print("Traffic match %s has been submitted", trafficMatchId);
}
use of org.onosproject.net.flow.TrafficSelector in project trellis-control by opennetworkinglab.
the class MockFlowObjectiveService method forward.
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
TrafficSelector selector = forwardingObjective.selector();
TrafficTreatment treatment = nextTable.get(forwardingObjective.nextId());
MacAddress macAddress = ((EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST)).mac();
VlanId vlanId = ((VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID)).vlanId();
boolean popVlan = treatment.allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.L2MODIFICATION)).anyMatch(instruction -> ((L2ModificationInstruction) instruction).subtype().equals(L2ModificationInstruction.L2SubType.VLAN_POP));
PortNumber portNumber = treatment.allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).map(instruction -> ((Instructions.OutputInstruction) instruction).port()).findFirst().orElse(null);
if (portNumber == null) {
throw new IllegalArgumentException();
}
Objective.Operation op = forwardingObjective.op();
MockBridgingTableKey btKey = new MockBridgingTableKey(deviceId, macAddress, vlanId);
MockBridgingTableValue btValue = new MockBridgingTableValue(popVlan, portNumber);
if (op.equals(Objective.Operation.ADD)) {
bridgingTable.put(btKey, btValue);
forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
} else if (op.equals(Objective.Operation.REMOVE)) {
bridgingTable.remove(btKey, btValue);
forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
} else {
forwardingObjective.context().ifPresent(context -> context.onError(forwardingObjective, ObjectiveError.UNKNOWN));
throw new IllegalArgumentException();
}
}
use of org.onosproject.net.flow.TrafficSelector in project trellis-control by opennetworkinglab.
the class TrafficMatchCodec method decode.
@Override
public TrafficMatch decode(ObjectNode json, CodecContext context) {
final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
ObjectNode selectorJson = nullIsIllegal(get(json, TRAFFIC_SELECTOR), TRAFFIC_SELECTOR + MISSING_MEMBER_MESSAGE);
TrafficSelector trafficSelector = selectorCodec.decode(selectorJson, context);
PolicyId policyId = PolicyId.of(nullIsIllegal(json.get(POLICY_ID), POLICY_ID + MISSING_MEMBER_MESSAGE).asText());
int priority = nullIsIllegal(json.get(TRAFFIC_MATCH_PRIORITY), TRAFFIC_MATCH_PRIORITY + MISSING_MEMBER_MESSAGE).asInt();
TrafficMatchPriority trafficMatchPriority;
try {
trafficMatchPriority = new TrafficMatchPriority(priority);
} catch (IllegalArgumentException ex) {
throw ex;
}
return new TrafficMatch(trafficSelector, policyId, trafficMatchPriority);
}
use of org.onosproject.net.flow.TrafficSelector in project trellis-control by opennetworkinglab.
the class DefaultL2TunnelHandler method deployPseudoWireInit.
/**
* Handles the tunnel establishment which consists in
* create the next objectives related to the initiation.
*
* @param l2Tunnel the tunnel to deploy
* @param ingress the ingress connect point
* @param egress the egress connect point
* @param direction the direction of the pw
* @param nextHop next hop of the initiation point
* @param oneHop if this pseudowire has only one link
* @param termVlanId the termination vlan id
* @return the result of the operation
*/
private Result deployPseudoWireInit(L2Tunnel l2Tunnel, ConnectPoint ingress, ConnectPoint egress, Direction direction, Link nextHop, boolean oneHop, VlanId termVlanId) {
log.debug("Started deploying init next objectives for pseudowire {} for tunnel {} -> {}.", l2Tunnel.tunnelId(), ingress, egress);
if (nextHop == null) {
log.warn("No path between ingress and egress connection points for tunnel {}", l2Tunnel.tunnelId());
return WRONG_PARAMETERS;
}
// We create the next objective without the metadata
// context and id. We check if it already exists in the
// store. If not we store as it is in the store.
NextObjective.Builder nextObjectiveBuilder = createNextObjective(INITIATION, nextHop.src(), nextHop.dst(), l2Tunnel, egress.deviceId(), oneHop, termVlanId);
if (nextObjectiveBuilder == null) {
return INTERNAL_ERROR;
}
// We set the metadata. We will use this metadata
// to inform the driver we are doing a l2 tunnel.
TrafficSelector metadata = DefaultTrafficSelector.builder().matchTunnelId(l2Tunnel.tunnelId()).build();
nextObjectiveBuilder.withMeta(metadata);
int nextId = srManager.flowObjectiveService.allocateNextId();
if (nextId < 0) {
log.warn("Not able to allocate a next id for initiation");
return INTERNAL_ERROR;
}
nextObjectiveBuilder.withId(nextId);
String key = generateKey(l2Tunnel.tunnelId(), direction);
l2InitiationNextObjStore.put(key, nextObjectiveBuilder.add());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Initiation l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
log.warn("Failed to populate Initiation l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjectiveBuilder.add(context);
srManager.flowObjectiveService.next(ingress.deviceId(), nextObjective);
log.debug("Initiation next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
Result result = SUCCESS;
result.setNextId(nextObjective.id());
return result;
}
use of org.onosproject.net.flow.TrafficSelector in project trellis-control by opennetworkinglab.
the class DefaultL2TunnelHandler method deployPseudoWireTerm.
/**
* Handles the tunnel termination, which consists in the creation
* of a forwarding objective and a next objective.
*
* @param l2Tunnel the tunnel to terminate
* @param egress the egress point
* @param egressVlan the expected vlan at egress
* @param direction the direction
* @return the result of the operation
*/
private Result deployPseudoWireTerm(L2Tunnel l2Tunnel, ConnectPoint egress, VlanId egressVlan, Direction direction, boolean oneHop) {
log.debug("Started deploying termination objectives for pseudowire {} , direction {}.", l2Tunnel.tunnelId(), direction == FWD ? "forward" : "reverse");
// We create the group relative to the termination.
NextObjective.Builder nextObjectiveBuilder = createNextObjective(TERMINATION, egress, null, l2Tunnel, egress.deviceId(), oneHop, egressVlan);
if (nextObjectiveBuilder == null) {
return INTERNAL_ERROR;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(egressVlan).build();
nextObjectiveBuilder.withMeta(metadata);
int nextId = srManager.flowObjectiveService.allocateNextId();
if (nextId < 0) {
log.warn("Not able to allocate a next id for initiation");
return INTERNAL_ERROR;
}
nextObjectiveBuilder.withId(nextId);
String key = generateKey(l2Tunnel.tunnelId(), direction);
l2TerminationNextObjStore.put(key, nextObjectiveBuilder.add());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Termination l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
log.warn("Failed to populate termination l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjectiveBuilder.add(context);
srManager.flowObjectiveService.next(egress.deviceId(), nextObjective);
log.debug("Termination next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
// We create the flow relative to the termination.
ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), l2Tunnel.tunnelId(), egress.port(), nextObjective.id());
context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel termination {} populated", l2Tunnel.tunnelId()), (objective, error) -> log.warn("Failed to populate fwdrObj" + " for tunnel termination {} : {}", l2Tunnel.tunnelId(), error));
srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.add(context));
log.debug("Creating new FwdObj for termination NextObj with id={} for tunnel {}", nextId, l2Tunnel.tunnelId());
return SUCCESS;
}
Aggregations