use of org.onosproject.net.flow.FlowRule 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.FlowRule in project onos by opennetworkinglab.
the class K8sFlowRuleManager method setupJumpTable.
private void setupJumpTable(K8sNode k8sNode) {
DeviceId deviceId = k8sNode.intgBridge();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchEthDst(DEFAULT_GATEWAY_MAC);
treatment.transition(ROUTING_TABLE);
FlowRule flowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(HIGH_PRIORITY).fromApp(appId).makePermanent().forTable(GROUPING_TABLE).build();
applyRule(flowRule, true);
selector = DefaultTrafficSelector.builder();
treatment = DefaultTrafficTreatment.builder();
treatment.transition(STAT_EGRESS_TABLE);
flowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DROP_PRIORITY).fromApp(appId).makePermanent().forTable(GROUPING_TABLE).build();
applyRule(flowRule, true);
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class K8sFlowRuleManager method setUpTableMissEntry.
@Override
public void setUpTableMissEntry(DeviceId deviceId, int table) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.drop();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DROP_PRIORITY).fromApp(appId).makePermanent().forTable(table).build();
applyRule(flowRule, true);
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class SimpleFabricRouting method dump.
// Dump Cli Handler
private void dump(String subject, PrintStream out) {
if ("intents".equals(subject)) {
out.println("Routing Route Intents:\n");
for (Intent entry : intentService.getIntents()) {
if (appId.equals(entry.appId())) {
MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
out.println(" " + intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
}
}
out.println("");
out.println("Routing Intercept Flow Rules:\n");
List<FlowRule> rules = new ArrayList(interceptFlowRules);
Collections.sort(rules, new Comparator<FlowRule>() {
@Override
public int compare(FlowRule a, FlowRule b) {
int r = a.deviceId().toString().compareTo(b.deviceId().toString());
// descending on priority
return (r != 0) ? r : Integer.compare(b.priority(), a.priority());
}
});
for (FlowRule rule : rules) {
out.println(" device=" + rule.deviceId().toString() + " priority=" + rule.priority() + " selector=" + rule.selector().criteria().toString());
}
out.println("");
out.println("Routing Intents to Be Purged:\n");
for (Key key : toBePurgedIntentKeys) {
out.println(" " + key.toString());
}
out.println("");
} else if ("reactive-intents".equals(subject)) {
for (Intent entry : intentService.getIntents()) {
if (appId.equals(entry.appId())) {
MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
out.println(intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
}
}
}
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class SimpleFabricRouting method generateInterceptFlowRule.
private FlowRule generateInterceptFlowRule(boolean isDstLocalSubnet, DeviceId deviceId, IpPrefix prefix) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (prefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
if (prefix.prefixLength() > 0) {
selector.matchIPDst(prefix);
}
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
if (prefix.prefixLength() > 0) {
selector.matchIPv6Dst(prefix);
}
}
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withPriority(reactivePriority(false, isDstLocalSubnet, prefix.prefixLength())).withSelector(selector.build()).withTreatment(DefaultTrafficTreatment.builder().punt().build()).fromApp(appId).makePermanent().forTable(0).build();
return rule;
}
Aggregations