use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class ConnectivityIntentCommand method buildTrafficTreatment.
/**
* Generates a traffic treatment for this intent based on command line
* arguments presented to the command.
*
* @return traffic treatment
*/
protected TrafficTreatment buildTrafficTreatment() {
final TrafficTreatment.Builder treatmentBuilder = builder();
boolean emptyTreatment = true;
if (!isNullOrEmpty(setEthSrcString)) {
treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setEthDstString)) {
treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setIpSrcString)) {
treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setIpDstString)) {
treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setVlan)) {
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
emptyTreatment = false;
}
if (popVlan) {
treatmentBuilder.popVlan();
emptyTreatment = false;
}
if (!isNullOrEmpty(pushVlan)) {
treatmentBuilder.pushVlan();
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
emptyTreatment = false;
}
if (!isNullOrEmpty(setQueue)) {
// OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
if (setQueue.contains("/")) {
String[] queueConfig = setQueue.split("/");
PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
long queueId = Long.parseLong(queueConfig[1]);
treatmentBuilder.setQueue(queueId, port);
} else {
treatmentBuilder.setQueue(Long.parseLong(setQueue));
}
emptyTreatment = false;
}
if (emptyTreatment) {
return DefaultTrafficTreatment.emptyTreatment();
} else {
return treatmentBuilder.build();
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class IntentCycleCommand method generateIntents.
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Intent> intents = Lists.newArrayList();
for (long i = 0; i < count; i++) {
TrafficSelector selector = selectorBldr.matchEthSrc(MacAddress.valueOf(i + keyOffset)).build();
intents.add(PointToPointIntent.builder().appId(appId()).key(Key.of(i + keyOffset, appId())).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build());
}
return intents;
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class PortWaveLengthCommand method doExecute.
@Override
protected void doExecute() throws Exception {
if (operation.equals("edit-config") || operation.equals("delete-config")) {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
CoreService coreService = get(CoreService.class);
TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
ConnectPoint inCp, outCp = null;
Device inDevice, outDevice = null;
inCp = ConnectPoint.deviceConnectPoint(inConnectPointString);
inDevice = deviceService.getDevice(inCp.deviceId());
if (outConnectPointString != null) {
outCp = ConnectPoint.deviceConnectPoint(outConnectPointString);
outDevice = deviceService.getDevice(outCp.deviceId());
}
if (inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).build();
// Traffic treatment including ochSignal
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(inCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
}
}
if (inDevice.type().equals(Device.Type.ROADM)) {
if (outConnectPointString == null) {
print("[ERROR] output port is required for ROADM devices");
return;
}
if (!inDevice.equals(outDevice)) {
print("[ERROR] input and output ports must be on the same device");
return;
}
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
// Traffic treatment
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(outCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
}
}
if (!inDevice.type().equals(Device.Type.ROADM) && !inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
print("[ERROR] wrong device type: %s", inDevice.type());
}
} else {
print("[ERROR] operation %s is not yet supported", operation);
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method setNorthSouthIcmpReplyRule.
/**
* Installs/uninstalls a flow rule to match north-south ICMP reply packets,
* direct all ICMP reply packets to the controller.
*
* @param port instance port
* @param gw gateway node
* @param install installation flag
*/
private void setNorthSouthIcmpReplyRule(InstancePort port, OpenstackNode gw, boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(port.ipAddress(), PREFIX_LENGTH)).matchIPProtocol(IPv4.PROTOCOL_ICMP).matchIcmpType(ICMP.TYPE_ECHO_REPLY).matchTunnelId(getSegId(osNetworkService, port)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setIpSrc(instancePortService.floatingIp(port.portId())).setEthSrc(port.macAddress()).setEthDst(DEFAULT_EXTERNAL_ROUTER_MAC).punt().build();
osFlowRuleService.setRule(appId, gw.intgBridge(), selector, treatment, PRIORITY_ICMP_PROBE_RULE, GW_COMMON_TABLE, install);
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SelectGroupHandler method generateBucketsForSelectGroup.
private List<GroupBucket> generateBucketsForSelectGroup(DeviceId deviceId, List<GatewayNode> nodeList) {
List<GroupBucket> bucketList = Lists.newArrayList();
nodeList.forEach(node -> {
TrafficTreatment tBuilder = DefaultTrafficTreatment.builder().extension(buildNiciraExtenstion(deviceId, node.getDataIpAddress()), deviceId).setOutput(getTunnelPort(deviceId)).build();
bucketList.add(createSelectGroupBucket(tBuilder));
});
return bucketList;
}
Aggregations