Committed by
Gerrit Code Review
[ONOS-3180] Add initialize method to add table miss rules
Change-Id: Ifd4e9719139606826096c1a1445b97b4ea8e488b
Showing
1 changed file
with
63 additions
and
5 deletions
| ... | @@ -21,12 +21,14 @@ import java.util.Collection; | ... | @@ -21,12 +21,14 @@ import java.util.Collection; |
| 21 | import java.util.Collections; | 21 | import java.util.Collections; |
| 22 | 22 | ||
| 23 | import org.onlab.osgi.ServiceDirectory; | 23 | import org.onlab.osgi.ServiceDirectory; |
| 24 | +import org.onosproject.core.ApplicationId; | ||
| 24 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
| 25 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.behaviour.Pipeliner; | 27 | import org.onosproject.net.behaviour.Pipeliner; |
| 27 | import org.onosproject.net.behaviour.PipelinerContext; | 28 | import org.onosproject.net.behaviour.PipelinerContext; |
| 28 | import org.onosproject.net.device.DeviceService; | 29 | import org.onosproject.net.device.DeviceService; |
| 29 | import org.onosproject.net.flow.DefaultFlowRule; | 30 | import org.onosproject.net.flow.DefaultFlowRule; |
| 31 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 31 | import org.onosproject.net.flow.FlowRule; | 33 | import org.onosproject.net.flow.FlowRule; |
| 32 | import org.onosproject.net.flow.FlowRuleOperations; | 34 | import org.onosproject.net.flow.FlowRuleOperations; |
| ... | @@ -56,11 +58,13 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline | ... | @@ -56,11 +58,13 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
| 56 | private ServiceDirectory serviceDirectory; | 58 | private ServiceDirectory serviceDirectory; |
| 57 | protected FlowObjectiveStore flowObjectiveStore; | 59 | protected FlowObjectiveStore flowObjectiveStore; |
| 58 | protected DeviceId deviceId; | 60 | protected DeviceId deviceId; |
| 61 | + protected ApplicationId appId; | ||
| 59 | protected FlowRuleService flowRuleService; | 62 | protected FlowRuleService flowRuleService; |
| 60 | protected DeviceService deviceService; | 63 | protected DeviceService deviceService; |
| 61 | private static final int TIME_OUT = 0; | 64 | private static final int TIME_OUT = 0; |
| 62 | - private static final int MAC_TABLE = 40; | 65 | + private static final int CLASSIFIER_TABLE = 0; |
| 63 | - private static final int PORT_TABLE = 0; | 66 | + private static final int MAC_TABLE = 50; |
| 67 | + private static final int TABLE_MISS_PRIORITY = 0; | ||
| 64 | 68 | ||
| 65 | @Override | 69 | @Override |
| 66 | public void init(DeviceId deviceId, PipelinerContext context) { | 70 | public void init(DeviceId deviceId, PipelinerContext context) { |
| ... | @@ -71,9 +75,9 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline | ... | @@ -71,9 +75,9 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
| 71 | coreService = serviceDirectory.get(CoreService.class); | 75 | coreService = serviceDirectory.get(CoreService.class); |
| 72 | flowRuleService = serviceDirectory.get(FlowRuleService.class); | 76 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
| 73 | flowObjectiveStore = context.store(); | 77 | flowObjectiveStore = context.store(); |
| 74 | - coreService | 78 | + appId = coreService |
| 75 | .registerApplication("org.onosproject.driver.OpenVSwitchPipeline"); | 79 | .registerApplication("org.onosproject.driver.OpenVSwitchPipeline"); |
| 76 | - | 80 | + initializePipeline(); |
| 77 | } | 81 | } |
| 78 | 82 | ||
| 79 | @Override | 83 | @Override |
| ... | @@ -125,6 +129,60 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline | ... | @@ -125,6 +129,60 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
| 125 | super.next(nextObjective); | 129 | super.next(nextObjective); |
| 126 | } | 130 | } |
| 127 | 131 | ||
| 132 | + private void initializePipeline() { | ||
| 133 | + processClassifierTable(true); | ||
| 134 | + processMacTable(true); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + private void processClassifierTable(boolean install) { | ||
| 138 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 139 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
| 140 | + | ||
| 141 | + treatment.transition(MAC_TABLE); | ||
| 142 | + | ||
| 143 | + FlowRule rule; | ||
| 144 | + rule = DefaultFlowRule.builder().forDevice(deviceId) | ||
| 145 | + .withSelector(selector.build()) | ||
| 146 | + .withTreatment(treatment.build()) | ||
| 147 | + .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) | ||
| 148 | + .makePermanent().forTable(CLASSIFIER_TABLE).build(); | ||
| 149 | + | ||
| 150 | + applyRules(install, rule); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + private void processMacTable(boolean install) { | ||
| 154 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 155 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
| 156 | + | ||
| 157 | + treatment.drop(); | ||
| 158 | + | ||
| 159 | + FlowRule rule; | ||
| 160 | + rule = DefaultFlowRule.builder().forDevice(deviceId) | ||
| 161 | + .withSelector(selector.build()) | ||
| 162 | + .withTreatment(treatment.build()) | ||
| 163 | + .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) | ||
| 164 | + .makePermanent().forTable(MAC_TABLE).build(); | ||
| 165 | + | ||
| 166 | + applyRules(install, rule); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + private void applyRules(boolean install, FlowRule rule) { | ||
| 170 | + FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); | ||
| 171 | + | ||
| 172 | + ops = install ? ops.add(rule) : ops.remove(rule); | ||
| 173 | + flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { | ||
| 174 | + @Override | ||
| 175 | + public void onSuccess(FlowRuleOperations ops) { | ||
| 176 | + log.info("ONOSW provisioned " + rule.tableId() + " table"); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + @Override | ||
| 180 | + public void onError(FlowRuleOperations ops) { | ||
| 181 | + log.info("ONOSW failed to provision " + rule.tableId() + " table"); | ||
| 182 | + } | ||
| 183 | + })); | ||
| 184 | + } | ||
| 185 | + | ||
| 128 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { | 186 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 129 | switch (fwd.flag()) { | 187 | switch (fwd.flag()) { |
| 130 | case SPECIFIC: | 188 | case SPECIFIC: |
| ... | @@ -164,7 +222,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline | ... | @@ -164,7 +222,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
| 164 | tb.allInstructions().forEach(t -> newTraffic.add(t)); | 222 | tb.allInstructions().forEach(t -> newTraffic.add(t)); |
| 165 | newTraffic.transition(MAC_TABLE); | 223 | newTraffic.transition(MAC_TABLE); |
| 166 | ruleBuilder.withTreatment(newTraffic.build()); | 224 | ruleBuilder.withTreatment(newTraffic.build()); |
| 167 | - ruleBuilder.forTable(PORT_TABLE); | 225 | + ruleBuilder.forTable(CLASSIFIER_TABLE); |
| 168 | } | 226 | } |
| 169 | return Collections.singletonList(ruleBuilder.build()); | 227 | return Collections.singletonList(ruleBuilder.build()); |
| 170 | } | 228 | } | ... | ... |
-
Please register or login to post a comment