use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class K8sFlowRuleManager method setAnyRoutingRule.
private void setAnyRoutingRule(IpPrefix srcIpPrefix, MacAddress mac, K8sNetwork k8sNetwork) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpPrefix).matchIPDst(IpPrefix.valueOf(k8sNetwork.cidr()));
for (K8sNode node : k8sNodeService.completeNodes()) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(k8sNetwork.segmentId()));
if (node.hostname().equals(k8sNetwork.name())) {
if (mac != null) {
tBuilder.setEthSrc(mac);
}
tBuilder.transition(STAT_EGRESS_TABLE);
} else {
K8sNode localNode = k8sNodeService.node(k8sNetwork.name());
tBuilder.setOutput(node.intgToTunPortNum());
// install flows into tunnel bridge
PortNumber portNum = tunnelPortNumByNetId(k8sNetwork.networkId(), k8sNetworkService, node);
TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, node.tunBridge(), localNode.dataIp().getIp4Address()), node.tunBridge()).setTunnelId(Long.valueOf(k8sNetwork.segmentId())).setOutput(portNum).build();
FlowRule remoteFlowRule = DefaultFlowRule.builder().forDevice(node.tunBridge()).withSelector(sBuilder.build()).withTreatment(treatmentToRemote).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(TUN_ENTRY_TABLE).build();
applyRule(remoteFlowRule, true);
}
FlowRule flowRule = DefaultFlowRule.builder().forDevice(node.intgBridge()).withSelector(sBuilder.build()).withTreatment(tBuilder.build()).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(ROUTING_TABLE).build();
applyRule(flowRule, true);
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SdnIpReactiveRouting method forwardPacketToDst.
/**
* Emits the specified packet onto the network.
*
* @param context the packet context
* @param connectPoint the connect point where the packet should be
* sent out
*/
private void forwardPacketToDst(PacketContext context, ConnectPoint connectPoint) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, context.inPacket().unparsed());
packetService.emit(packet);
log.trace("sending packet: {}", packet);
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class RoadmManager method createConnection.
@Override
public FlowId createConnection(DeviceId deviceId, int priority, boolean isPermanent, int timeout, PortNumber inPort, PortNumber outPort, OchSignal ochSignal) {
checkNotNull(deviceId);
checkNotNull(inPort);
checkNotNull(outPort);
// Creation of selector.
TrafficSelector selector = DefaultTrafficSelector.builder().add(Criteria.matchInPort(inPort)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
// Creation of treatment
TrafficTreatment treatment = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(outPort)).build();
FlowRule.Builder flowBuilder = DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).withPriority(priority).withSelector(selector).withTreatment(treatment);
if (isPermanent) {
flowBuilder.makePermanent();
} else {
flowBuilder.makeTemporary(timeout);
}
FlowRule flowRule = flowBuilder.build();
flowRuleService.applyFlowRules(flowRule);
log.info("Created connection from input port {} to output port {}", inPort.toLong(), outPort.toLong());
return flowRule.id();
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class AddMultiPointToSinglePointIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
if (deviceStrings.length < 2) {
return;
}
String egressDeviceString = deviceStrings[deviceStrings.length - 1];
FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));
Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
for (int index = 0; index < deviceStrings.length - 1; index++) {
String ingressDeviceString = deviceStrings[index];
ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
ingressPoints.add(new FilteredConnectPoint(ingress));
}
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
Intent intent = MultiPointToSinglePointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoints(ingressPoints).filteredEgressPoint(egress).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Multipoint to single point intent submitted:\n%s", intent.toString());
}
use of org.onosproject.net.flow.TrafficTreatment 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