Committed by
Gerrit Code Review
Adding more filtering objectives from the router application and handling them
in the corsa-pipeline driver Change-Id: I3598b84ce25df97c10b33c6f1fdfc76421499046
Showing
2 changed files
with
68 additions
and
43 deletions
... | @@ -20,6 +20,7 @@ import com.google.common.collect.HashMultimap; | ... | @@ -20,6 +20,7 @@ import com.google.common.collect.HashMultimap; |
20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
21 | import com.google.common.collect.Multimap; | 21 | import com.google.common.collect.Multimap; |
22 | import com.google.common.collect.Multiset; | 22 | import com.google.common.collect.Multiset; |
23 | + | ||
23 | import org.apache.felix.scr.annotations.Activate; | 24 | import org.apache.felix.scr.annotations.Activate; |
24 | import org.apache.felix.scr.annotations.Component; | 25 | import org.apache.felix.scr.annotations.Component; |
25 | import org.apache.felix.scr.annotations.Deactivate; | 26 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -30,14 +31,11 @@ import org.onlab.packet.Ip4Address; | ... | @@ -30,14 +31,11 @@ import org.onlab.packet.Ip4Address; |
30 | import org.onlab.packet.Ip6Address; | 31 | import org.onlab.packet.Ip6Address; |
31 | import org.onlab.packet.IpAddress; | 32 | import org.onlab.packet.IpAddress; |
32 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
33 | -import org.onlab.packet.MacAddress; | ||
34 | -import org.onlab.packet.VlanId; | ||
35 | import org.onlab.util.KryoNamespace; | 34 | import org.onlab.util.KryoNamespace; |
36 | import org.onosproject.config.NetworkConfigService; | 35 | import org.onosproject.config.NetworkConfigService; |
37 | import org.onosproject.core.ApplicationId; | 36 | import org.onosproject.core.ApplicationId; |
38 | import org.onosproject.core.CoreService; | 37 | import org.onosproject.core.CoreService; |
39 | import org.onosproject.net.DeviceId; | 38 | import org.onosproject.net.DeviceId; |
40 | -import org.onosproject.net.PortNumber; | ||
41 | import org.onosproject.net.flow.DefaultFlowRule; | 39 | import org.onosproject.net.flow.DefaultFlowRule; |
42 | import org.onosproject.net.flow.DefaultTrafficSelector; | 40 | import org.onosproject.net.flow.DefaultTrafficSelector; |
43 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 41 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
... | @@ -60,7 +58,6 @@ import org.onosproject.net.group.GroupDescription; | ... | @@ -60,7 +58,6 @@ import org.onosproject.net.group.GroupDescription; |
60 | import org.onosproject.net.group.GroupEvent; | 58 | import org.onosproject.net.group.GroupEvent; |
61 | import org.onosproject.net.group.GroupListener; | 59 | import org.onosproject.net.group.GroupListener; |
62 | import org.onosproject.net.group.GroupService; | 60 | import org.onosproject.net.group.GroupService; |
63 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
64 | import org.onosproject.net.packet.PacketService; | 61 | import org.onosproject.net.packet.PacketService; |
65 | import org.onosproject.routing.FibEntry; | 62 | import org.onosproject.routing.FibEntry; |
66 | import org.onosproject.routing.FibListener; | 63 | import org.onosproject.routing.FibListener; |
... | @@ -75,7 +72,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -75,7 +72,6 @@ import org.slf4j.LoggerFactory; |
75 | import java.util.Collection; | 72 | import java.util.Collection; |
76 | import java.util.Collections; | 73 | import java.util.Collections; |
77 | import java.util.HashMap; | 74 | import java.util.HashMap; |
78 | -import java.util.HashSet; | ||
79 | import java.util.Map; | 75 | import java.util.Map; |
80 | import java.util.Set; | 76 | import java.util.Set; |
81 | import java.util.stream.Collectors; | 77 | import java.util.stream.Collectors; |
... | @@ -146,8 +142,6 @@ public class BgpRouter { | ... | @@ -146,8 +142,6 @@ public class BgpRouter { |
146 | 142 | ||
147 | private IcmpHandler icmpHandler; | 143 | private IcmpHandler icmpHandler; |
148 | 144 | ||
149 | - private InternalTableHandler provisionStaticTables = new InternalTableHandler(); | ||
150 | - | ||
151 | private KryoNamespace appKryo = new KryoNamespace.Builder() | 145 | private KryoNamespace appKryo = new KryoNamespace.Builder() |
152 | .register(IpAddress.Version.class) | 146 | .register(IpAddress.Version.class) |
153 | .register(IpAddress.class) | 147 | .register(IpAddress.class) |
... | @@ -168,7 +162,7 @@ public class BgpRouter { | ... | @@ -168,7 +162,7 @@ public class BgpRouter { |
168 | 162 | ||
169 | groupService.addListener(groupListener); | 163 | groupService.addListener(groupListener); |
170 | 164 | ||
171 | - provisionStaticTables.provision(true, configService.getInterfaces()); | 165 | + processIntfFilters(true, configService.getInterfaces()); |
172 | 166 | ||
173 | connectivityManager = new TunnellingConnectivityManager(appId, | 167 | connectivityManager = new TunnellingConnectivityManager(appId, |
174 | configService, | 168 | configService, |
... | @@ -192,7 +186,7 @@ public class BgpRouter { | ... | @@ -192,7 +186,7 @@ public class BgpRouter { |
192 | routingService.stop(); | 186 | routingService.stop(); |
193 | connectivityManager.stop(); | 187 | connectivityManager.stop(); |
194 | icmpHandler.stop(); | 188 | icmpHandler.stop(); |
195 | - provisionStaticTables.provision(false, configService.getInterfaces()); | 189 | + processIntfFilters(false, configService.getInterfaces()); |
196 | 190 | ||
197 | groupService.removeListener(groupListener); | 191 | groupService.removeListener(groupListener); |
198 | 192 | ||
... | @@ -380,30 +374,20 @@ public class BgpRouter { | ... | @@ -380,30 +374,20 @@ public class BgpRouter { |
380 | } | 374 | } |
381 | } | 375 | } |
382 | 376 | ||
383 | - private class InternalTableHandler { | 377 | + private void processIntfFilters(boolean install, Set<Interface> intfs) { |
384 | - | ||
385 | - private Set<InterfaceIpAddress> intfIps = new HashSet<InterfaceIpAddress>(); | ||
386 | - private Set<MacAddress> intfMacs = new HashSet<MacAddress>(); | ||
387 | - private Map<PortNumber, VlanId> portVlanPair = Maps.newHashMap(); | ||
388 | - | ||
389 | - public void provision(boolean install, Set<Interface> intfs) { | ||
390 | - getInterfaceConfig(intfs); | ||
391 | - } | ||
392 | - | ||
393 | - private void getInterfaceConfig(Set<Interface> intfs) { | ||
394 | log.info("Processing {} router interfaces", intfs.size()); | 378 | log.info("Processing {} router interfaces", intfs.size()); |
395 | for (Interface intf : intfs) { | 379 | for (Interface intf : intfs) { |
396 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); | 380 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
397 | - flowObjectiveService.filter(deviceId, Collections.singletonList( | 381 | + fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
398 | - fob.addCondition(Criteria.matchEthDst(intf.mac())) | 382 | + .addCondition(Criteria.matchEthDst(intf.mac())) |
399 | - .fromApp(appId).permit().add())); | 383 | + .addCondition(Criteria.matchVlanId(intf.vlan())); |
400 | - intfIps.addAll(intf.ipAddresses()); | 384 | + intf.ipAddresses().stream() |
401 | - intfMacs.add(intf.mac()); | 385 | + .forEach(ipaddr -> fob.addCondition( |
402 | - portVlanPair.put(intf.connectPoint().port(), intf.vlan()); | 386 | + Criteria.matchIPDst(ipaddr.subnetAddress()))); |
403 | - } | 387 | + fob.permit().fromApp(appId); |
388 | + flowObjectiveService.filter(deviceId, | ||
389 | + Collections.singletonList(fob.add())); | ||
404 | } | 390 | } |
405 | - | ||
406 | - | ||
407 | } | 391 | } |
408 | 392 | ||
409 | private class InternalGroupListener implements GroupListener { | 393 | private class InternalGroupListener implements GroupListener { | ... | ... |
... | @@ -83,39 +83,80 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli | ... | @@ -83,39 +83,80 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli |
83 | 83 | ||
84 | @Override | 84 | @Override |
85 | public Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives) { | 85 | public Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives) { |
86 | - Collection<Future<Boolean>> results = | 86 | + Collection<Future<Boolean>> results = Sets.newHashSet(); |
87 | - Sets.newHashSet(); | ||
88 | filteringObjectives.stream() | 87 | filteringObjectives.stream() |
89 | .filter(obj -> obj.type() == FilteringObjective.Type.PERMIT) | 88 | .filter(obj -> obj.type() == FilteringObjective.Type.PERMIT) |
90 | - .forEach(obj -> obj.conditions() | 89 | + .forEach(filtobj -> results.add(processFilter(filtobj, |
91 | - .forEach(condition -> | 90 | + filtobj.op() == Objective.Operation.ADD, |
92 | - results.add(processCondition(condition, | 91 | + filtobj.appId() |
93 | - obj.op() == Objective.Operation.ADD, | 92 | + ))); |
94 | - obj.appId())) | ||
95 | - )); | ||
96 | 93 | ||
97 | //TODO: return something more helpful/sensible in the future (no pun intended) | 94 | //TODO: return something more helpful/sensible in the future (no pun intended) |
98 | return results.iterator().next(); | 95 | return results.iterator().next(); |
99 | 96 | ||
100 | } | 97 | } |
101 | 98 | ||
102 | - private Future<Boolean> processCondition(Criterion c, boolean install, | 99 | + private Future<Boolean> processFilter(FilteringObjective filt, boolean install, |
103 | ApplicationId applicationId) { | 100 | ApplicationId applicationId) { |
104 | SettableFuture<Boolean> result = SettableFuture.create(); | 101 | SettableFuture<Boolean> result = SettableFuture.create(); |
102 | + // This driver only processes filtering criteria defined with switch | ||
103 | + // ports as the key | ||
104 | + Criteria.PortCriterion p = null; | ||
105 | + if (!filt.key().equals(Criteria.dummy()) && | ||
106 | + filt.key().type() == Criterion.Type.IN_PORT) { | ||
107 | + p = (Criteria.PortCriterion) filt.key(); | ||
108 | + } else { | ||
109 | + log.warn("No key defined in filtering objective from app: {}. Not" | ||
110 | + + "processing filtering objective", applicationId); | ||
111 | + return null; | ||
112 | + } | ||
113 | + // convert filtering conditions for switch-intfs into flowrules | ||
114 | + FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); | ||
115 | + for (Criterion c : filt.conditions()) { | ||
105 | if (c.type() == Criterion.Type.ETH_DST) { | 116 | if (c.type() == Criterion.Type.ETH_DST) { |
106 | Criteria.EthCriterion e = (Criteria.EthCriterion) c; | 117 | Criteria.EthCriterion e = (Criteria.EthCriterion) c; |
107 | log.debug("adding rule for MAC: {}", e.mac()); | 118 | log.debug("adding rule for MAC: {}", e.mac()); |
108 | - | ||
109 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 119 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
110 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 120 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
111 | selector.matchEthDst(e.mac()); | 121 | selector.matchEthDst(e.mac()); |
112 | treatment.transition(FlowRule.Type.VLAN_MPLS); | 122 | treatment.transition(FlowRule.Type.VLAN_MPLS); |
113 | FlowRule rule = new DefaultFlowRule(deviceId, selector.build(), | 123 | FlowRule rule = new DefaultFlowRule(deviceId, selector.build(), |
114 | treatment.build(), | 124 | treatment.build(), |
115 | - CONTROLLER_PRIORITY, applicationId, 0, | 125 | + CONTROLLER_PRIORITY, applicationId, |
116 | - true, FlowRule.Type.FIRST); | 126 | + 0, true, FlowRule.Type.FIRST); |
117 | - FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); | ||
118 | ops = install ? ops.add(rule) : ops.remove(rule); | 127 | ops = install ? ops.add(rule) : ops.remove(rule); |
128 | + } else if (c.type() == Criterion.Type.VLAN_VID) { | ||
129 | + Criteria.VlanIdCriterion v = (Criteria.VlanIdCriterion) c; | ||
130 | + log.debug("adding rule for VLAN: {}", v.vlanId()); | ||
131 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
132 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
133 | + selector.matchVlanId(v.vlanId()); | ||
134 | + selector.matchInPort(p.port()); | ||
135 | + treatment.transition(FlowRule.Type.ETHER); | ||
136 | + treatment.deferred().popVlan(); | ||
137 | + FlowRule rule = new DefaultFlowRule(deviceId, selector.build(), | ||
138 | + treatment.build(), | ||
139 | + CONTROLLER_PRIORITY, applicationId, | ||
140 | + 0, true, FlowRule.Type.VLAN); | ||
141 | + ops = install ? ops.add(rule) : ops.remove(rule); | ||
142 | + } else if (c.type() == Criterion.Type.IPV4_DST) { | ||
143 | + Criteria.IPCriterion ip = (Criteria.IPCriterion) c; | ||
144 | + log.debug("adding rule for IP: {}", ip.ip()); | ||
145 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
146 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
147 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
148 | + selector.matchIPDst(ip.ip()); | ||
149 | + treatment.transition(FlowRule.Type.ACL); | ||
150 | + FlowRule rule = new DefaultFlowRule(deviceId, selector.build(), | ||
151 | + treatment.build(), HIGHEST_PRIORITY, appId, | ||
152 | + 0, true, FlowRule.Type.IP); | ||
153 | + ops = install ? ops.add(rule) : ops.remove(rule); | ||
154 | + } else { | ||
155 | + log.warn("Driver does not currently process filtering condition" | ||
156 | + + " of type: {}", c.type()); | ||
157 | + } | ||
158 | + } | ||
159 | + // apply filtering flow rules | ||
119 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { | 160 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
120 | @Override | 161 | @Override |
121 | public void onSuccess(FlowRuleOperations ops) { | 162 | public void onSuccess(FlowRuleOperations ops) { |
... | @@ -129,7 +170,7 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli | ... | @@ -129,7 +170,7 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli |
129 | log.info("Failed to provision default table for bgp router"); | 170 | log.info("Failed to provision default table for bgp router"); |
130 | } | 171 | } |
131 | })); | 172 | })); |
132 | - } | 173 | + |
133 | return result; | 174 | return result; |
134 | } | 175 | } |
135 | 176 | ... | ... |
-
Please register or login to post a comment