use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class TsCheckLoop method doExecute.
@Override
protected void doExecute() {
NetworkDiagnosticService service = getService(NetworkDiagnosticService.class);
DeviceService ds = getService(DeviceService.class);
HostService hs = getService(HostService.class);
FlowRuleService frs = getService(FlowRuleService.class);
LinkService ls = getService(LinkService.class);
service.findAnomalies(NetworkDiagnostic.Type.LOOP).forEach(loop -> print(loop.toString()));
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class TelemetryVflowListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
FlowRuleService flowService = get(FlowRuleService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
for (FlowEntry entry : flows) {
TrafficSelector selector = entry.selector();
IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
TpPort srcPort = TpPort.tpPort(0);
TpPort dstPort = TpPort.tpPort(0);
String protocolStr = "ANY";
Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
if (ipProtocolCriterion != null) {
short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
if (protocol == PROTOCOL_TCP) {
srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
protocolStr = TCP;
}
if (protocol == PROTOCOL_UDP) {
srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
protocolStr = UDP;
}
}
print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
}
}
use of org.onosproject.net.flow.FlowRuleService 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.FlowRuleService in project onos by opennetworkinglab.
the class VirtualFlowsListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
VirtualNetworkService vnetservice = get(VirtualNetworkService.class);
DeviceService deviceService = vnetservice.get(NetworkId.networkId(networkId), DeviceService.class);
FlowRuleService service = vnetservice.get(NetworkId.networkId(networkId), FlowRuleService.class);
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
compilePredicate();
SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service);
if (outputJson()) {
print("%s", json(flows.keySet(), flows));
} else {
flows.forEach((device, flow) -> printFlows(device, flow, coreService));
}
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class AddTestFlowsCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
CoreService coreService = get(CoreService.class);
ApplicationId appId = coreService.registerApplication("onos.test.flow.installer");
int flowsPerDevice = Integer.parseInt(flows);
int num = Integer.parseInt(numOfRuns);
ArrayList<Long> results = Lists.newArrayList();
Iterable<Device> devices = deviceService.getDevices();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(RandomUtils.nextInt(MAX_OUT_PORT))).build();
TrafficSelector.Builder sbuilder;
FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
FlowRuleOperations.Builder remove = FlowRuleOperations.builder();
for (Device d : devices) {
for (long i = 0; i < flowsPerDevice; i++) {
sbuilder = DefaultTrafficSelector.builder();
sbuilder.matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i)).matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));
int randomPriority = RandomUtils.nextInt(FlowRule.MAX_PRIORITY - FlowRule.MIN_PRIORITY + 1) + FlowRule.MIN_PRIORITY;
FlowRule addRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
FlowRule removeRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
rules.add(addRule);
remove.remove(removeRule);
}
}
// close stages
rules.newStage();
remove.newStage();
for (int i = 0; i < num; i++) {
printProgress("Run %d:", i);
latch = new CountDownLatch(2);
final CountDownLatch addSuccess = new CountDownLatch(1);
printProgress("..batch add request");
Stopwatch add = Stopwatch.createStarted();
flowService.apply(rules.build(new FlowRuleOperationsContext() {
private final Stopwatch timer = Stopwatch.createStarted();
@Override
public void onSuccess(FlowRuleOperations ops) {
timer.stop();
printProgress("..add success");
results.add(timer.elapsed(TimeUnit.MILLISECONDS));
if (results.size() == num) {
if (outputJson()) {
print("%s", json(new ObjectMapper(), true, results));
} else {
printTime(true, results);
}
}
latch.countDown();
addSuccess.countDown();
}
}));
try {
addSuccess.await();
// wait until all flows reaches ADDED state
while (!Streams.stream(flowService.getFlowEntriesById(appId)).allMatch(fr -> fr.state() == FlowEntryState.ADDED)) {
Thread.sleep(100);
}
add.stop();
printProgress("..completed %d ± 100 ms", add.elapsed(TimeUnit.MILLISECONDS));
} catch (InterruptedException e1) {
printProgress("Interrupted");
Thread.currentThread().interrupt();
}
printProgress("..cleaning up");
flowService.apply(remove.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
latch.countDown();
}
}));
try {
latch.await();
while (!Iterables.isEmpty(flowService.getFlowEntriesById(appId))) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
printProgress("Interrupted.");
Thread.currentThread().interrupt();
}
}
if (outputJson()) {
print("%s", json(new ObjectMapper(), true, results));
} else {
printTime(true, results);
}
}
Aggregations