use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.
the class McastUtils method getRouterMac.
/**
* Get router mac using application config and the connect point.
*
* @param deviceId the device id
* @param port the port number
* @return the router mac if the port is configured, otherwise null
*/
private MacAddress getRouterMac(DeviceId deviceId, PortNumber port) {
// Do nothing if the port is configured as suppressed
ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
SegmentRoutingAppConfig appConfig = srManager.cfgService.getConfig(srManager.appId(), SegmentRoutingAppConfig.class);
if (appConfig != null && appConfig.suppressSubnet().contains(connectPoint)) {
log.info("Ignore suppressed port {}", connectPoint);
return MacAddress.NONE;
}
// Get the router mac using the device configuration
MacAddress routerMac;
try {
routerMac = srManager.deviceConfiguration().getDeviceMac(deviceId);
} catch (DeviceConfigNotFoundException dcnfe) {
log.warn("Failed to get device MAC since the device {} is not configured", deviceId);
return null;
}
return routerMac;
}
use of org.onlab.packet.MacAddress 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.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.
the class PolicyManager method redirectPolicyNextObjective.
private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
List<DeviceId> edgeDevices = getEdgeDeviceIds();
egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
// No ports no friend
if (egressPortsToEnforce.isEmpty()) {
log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
// We need to add a treatment for each valid egress port. The treatment
// requires to set src and dst mac address and set the egress port. We are
// deliberately not providing the metadata to prevent the programming of
// some tables which are already controlled by SegmentRouting or are unnecessary
int nextId = flowObjectiveService.allocateNextId();
DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
MacAddress srcDeviceMac;
try {
srcDeviceMac = getDeviceMacAddress(srcDevice);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
MacAddress neigborDeviceMac;
TrafficTreatment.Builder tBuilder;
for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
try {
neigborDeviceMac = getDeviceMacAddress(entry.getValue());
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
builder.addTreatment(tBuilder.build());
}
return builder;
}
use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.
the class DefaultL2TunnelHandler method createNextObjective.
/**
* Creates the next objective according to a given
* pipeline. We don't set the next id and we don't
* create the final meta to check if we are re-using
* the same next objective for different tunnels.
*
* @param pipeline the pipeline to support
* @param srcCp the source port
* @param dstCp the destination port
* @param l2Tunnel the tunnel to support
* @param egressId the egress device id
* @param oneHop if the pw only has one hop, push only pw label
* @param termVlanId the outer vlan id of the packet exiting a termination point
* @return the next objective to support the pipeline
*/
private NextObjective.Builder createNextObjective(Pipeline pipeline, ConnectPoint srcCp, ConnectPoint dstCp, L2Tunnel l2Tunnel, DeviceId egressId, boolean oneHop, VlanId termVlanId) {
log.debug("Creating {} next objective for pseudowire {}.", pipeline == TERMINATION ? "termination" : "inititation");
NextObjective.Builder nextObjBuilder;
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (pipeline == INITIATION) {
nextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.SIMPLE).fromApp(srManager.appId());
// be different -1.
if (l2Tunnel.pwLabel().toInt() == MplsLabel.MAX_MPLS) {
log.error("Pw label not configured");
return null;
}
treatmentBuilder.pushMpls();
treatmentBuilder.setMpls(l2Tunnel.pwLabel());
treatmentBuilder.setMplsBos(true);
treatmentBuilder.copyTtlOut();
// If the inter-co label is present we have to set the label.
if (l2Tunnel.interCoLabel().toInt() != MplsLabel.MAX_MPLS) {
treatmentBuilder.pushMpls();
treatmentBuilder.setMpls(l2Tunnel.interCoLabel());
treatmentBuilder.setMplsBos(false);
treatmentBuilder.copyTtlOut();
}
// if not oneHop install transit mpls labels also
if (!oneHop) {
// We retrieve the sr label from the config
// specific for pseudowire traffic
// using the egress leaf device id.
MplsLabel srLabel;
try {
srLabel = MplsLabel.mplsLabel(srManager.deviceConfiguration().getPWRoutingLabel(egressId));
} catch (DeviceConfigNotFoundException e) {
log.error("Sr label for pw traffic not configured");
return null;
}
treatmentBuilder.pushMpls();
treatmentBuilder.setMpls(srLabel);
treatmentBuilder.setMplsBos(false);
treatmentBuilder.copyTtlOut();
}
// We have to rewrite the src and dst mac address.
MacAddress ingressMac;
try {
ingressMac = srManager.deviceConfiguration().getDeviceMac(srcCp.deviceId());
} catch (DeviceConfigNotFoundException e) {
log.error("Was not able to find the ingress mac");
return null;
}
treatmentBuilder.setEthSrc(ingressMac);
MacAddress neighborMac;
try {
neighborMac = srManager.deviceConfiguration().getDeviceMac(dstCp.deviceId());
} catch (DeviceConfigNotFoundException e) {
log.error("Was not able to find the neighbor mac");
return null;
}
treatmentBuilder.setEthDst(neighborMac);
// set the appropriate transport vlan from tunnel information
treatmentBuilder.setVlanId(l2Tunnel.transportVlan());
} else {
// We create the next objective which
// will be a simple l2 group.
nextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.SIMPLE).fromApp(srManager.appId());
// for termination point we use the outer vlan of the
// encapsulated packet for the vlan
treatmentBuilder.setVlanId(termVlanId);
}
treatmentBuilder.setOutput(srcCp.port());
nextObjBuilder.addTreatment(treatmentBuilder.build());
return nextObjBuilder;
}
use of org.onlab.packet.MacAddress in project TFG by mattinelorza.
the class Ipv6RoutingComponent method createNextHopGroup.
/**
* Creates an ONOS SELECT group for the routing table to provide ECMP
* forwarding for the given collection of next hop MAC addresses. ONOS
* SELECT groups are equivalent to P4Runtime action selector groups.
* <p>
* This method will be called by the routing policy methods below to insert
* groups in the L3 table
*
* @param nextHopMacs the collection of mac addresses of next hops
* @param deviceId the device where the group will be installed
* @return a SELECT group
*/
private GroupDescription createNextHopGroup(int groupId, Collection<MacAddress> nextHopMacs, DeviceId deviceId) {
String actionProfileId = "IngressPipeImpl.ecmp_selector";
final List<PiAction> actions = Lists.newArrayList();
// Build one "set next hop" action for each next hop
// *** TODO EXERCISE 5
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "IngressPipeImpl.routing_v6_table";
for (MacAddress nextHopMac : nextHopMacs) {
final PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_next_hop")).withParameter(new PiActionParam(// Action param name.
PiActionParamId.of("dmac"), // Action param value.
nextHopMac.toBytes())).build();
actions.add(action);
}
return Utils.buildSelectGroup(deviceId, tableId, actionProfileId, groupId, actions, appId);
}
Aggregations