Jonathan Hart
Committed by Gerrit Code Review

Add default drop rule in OF1.0 switches.

Default drop rule has the lowest priority and matches everything. This means
if a packet doesn't match any rules in the flow table, it is dropped. This
brings OF1.0 behaviour into line with OF1.3+ behaviour.

Change-Id: Id73839907a664bdccbc7a5eb904a8edd2a6222e7
...@@ -25,6 +25,7 @@ import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; ...@@ -25,6 +25,7 @@ import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
25 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; 25 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
26 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory; 26 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory;
27 import org.projectfloodlight.openflow.protocol.OFDescStatsReply; 27 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
28 +import org.projectfloodlight.openflow.protocol.OFFlowAdd;
28 import org.projectfloodlight.openflow.protocol.OFMessage; 29 import org.projectfloodlight.openflow.protocol.OFMessage;
29 import org.projectfloodlight.openflow.protocol.OFPortDesc; 30 import org.projectfloodlight.openflow.protocol.OFPortDesc;
30 import org.projectfloodlight.openflow.protocol.OFVersion; 31 import org.projectfloodlight.openflow.protocol.OFVersion;
...@@ -39,6 +40,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -39,6 +40,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
39 40
40 private static final Logger log = LoggerFactory.getLogger(DriverManager.class); 41 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
41 42
43 + private static final int LOWEST_PRIORITY = 0;
44 +
42 /** 45 /**
43 * Return an IOFSwitch object based on switch's manufacturer description 46 * Return an IOFSwitch object based on switch's manufacturer description
44 * from OFDescStatsReply. 47 * from OFDescStatsReply.
...@@ -98,7 +101,13 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -98,7 +101,13 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
98 } 101 }
99 102
100 @Override 103 @Override
101 - public void startDriverHandshake() {} 104 + public void startDriverHandshake() {
105 + if (factory().getVersion() == OFVersion.OF_10) {
106 + OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
107 + fmBuilder.setPriority(LOWEST_PRIORITY);
108 + write(fmBuilder.build());
109 + }
110 + }
102 111
103 @Override 112 @Override
104 public void processDriverHandshakeMessage(OFMessage m) {} 113 public void processDriverHandshakeMessage(OFMessage m) {}
......
...@@ -15,15 +15,16 @@ ...@@ -15,15 +15,16 @@
15 */ 15 */
16 package org.onosproject.openflow.drivers; 16 package org.onosproject.openflow.drivers;
17 17
18 +import java.util.Collections;
19 +import java.util.List;
20 +
18 import org.onosproject.openflow.controller.Dpid; 21 import org.onosproject.openflow.controller.Dpid;
19 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; 22 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
20 import org.projectfloodlight.openflow.protocol.OFDescStatsReply; 23 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
24 +import org.projectfloodlight.openflow.protocol.OFFlowAdd;
21 import org.projectfloodlight.openflow.protocol.OFMessage; 25 import org.projectfloodlight.openflow.protocol.OFMessage;
22 import org.projectfloodlight.openflow.protocol.OFPortDesc; 26 import org.projectfloodlight.openflow.protocol.OFPortDesc;
23 27
24 -import java.util.Collections;
25 -import java.util.List;
26 -
27 /** 28 /**
28 * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make 29 * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make
29 * (Hardware Desc.) : Open vSwitch Model (Datapath Desc.) : None Software : 30 * (Hardware Desc.) : Open vSwitch Model (Datapath Desc.) : None Software :
...@@ -31,6 +32,8 @@ import java.util.List; ...@@ -31,6 +32,8 @@ import java.util.List;
31 */ 32 */
32 public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch { 33 public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch {
33 34
35 + private static final int LOWEST_PRIORITY = 0;
36 +
34 public OFSwitchImplOVS10(Dpid dpid, OFDescStatsReply desc) { 37 public OFSwitchImplOVS10(Dpid dpid, OFDescStatsReply desc) {
35 super(dpid); 38 super(dpid);
36 setSwitchDescription(desc); 39 setSwitchDescription(desc);
...@@ -53,7 +56,11 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch { ...@@ -53,7 +56,11 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch {
53 } 56 }
54 57
55 @Override 58 @Override
56 - public void startDriverHandshake() {} 59 + public void startDriverHandshake() {
60 + OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
61 + fmBuilder.setPriority(LOWEST_PRIORITY);
62 + write(fmBuilder.build());
63 + }
57 64
58 @Override 65 @Override
59 public boolean isDriverHandshakeComplete() { 66 public boolean isDriverHandshakeComplete() {
......
...@@ -15,11 +15,24 @@ ...@@ -15,11 +15,24 @@
15 */ 15 */
16 package org.onosproject.provider.of.flow.impl; 16 package org.onosproject.provider.of.flow.impl;
17 17
18 -import com.google.common.base.MoreObjects; 18 +import static com.google.common.base.Preconditions.checkState;
19 -import com.google.common.collect.ArrayListMultimap; 19 +import static org.slf4j.LoggerFactory.getLogger;
20 -import com.google.common.collect.Maps; 20 +
21 -import com.google.common.collect.Multimap; 21 +import java.util.Collections;
22 -import com.google.common.collect.Sets; 22 +import java.util.HashMap;
23 +import java.util.List;
24 +import java.util.Map;
25 +import java.util.Optional;
26 +import java.util.Set;
27 +import java.util.concurrent.ConcurrentHashMap;
28 +import java.util.concurrent.CountDownLatch;
29 +import java.util.concurrent.ExecutionException;
30 +import java.util.concurrent.Future;
31 +import java.util.concurrent.TimeUnit;
32 +import java.util.concurrent.TimeoutException;
33 +import java.util.concurrent.atomic.AtomicBoolean;
34 +import java.util.concurrent.atomic.AtomicLong;
35 +import java.util.stream.Collectors;
23 36
24 import org.apache.felix.scr.annotations.Activate; 37 import org.apache.felix.scr.annotations.Activate;
25 import org.apache.felix.scr.annotations.Component; 38 import org.apache.felix.scr.annotations.Component;
...@@ -71,24 +84,11 @@ import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyAct ...@@ -71,24 +84,11 @@ import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyAct
71 import org.projectfloodlight.openflow.types.OFPort; 84 import org.projectfloodlight.openflow.types.OFPort;
72 import org.slf4j.Logger; 85 import org.slf4j.Logger;
73 86
74 -import java.util.Collections; 87 +import com.google.common.base.MoreObjects;
75 -import java.util.HashMap; 88 +import com.google.common.collect.ArrayListMultimap;
76 -import java.util.List; 89 +import com.google.common.collect.Maps;
77 -import java.util.Map; 90 +import com.google.common.collect.Multimap;
78 -import java.util.Optional; 91 +import com.google.common.collect.Sets;
79 -import java.util.Set;
80 -import java.util.concurrent.ConcurrentHashMap;
81 -import java.util.concurrent.CountDownLatch;
82 -import java.util.concurrent.ExecutionException;
83 -import java.util.concurrent.Future;
84 -import java.util.concurrent.TimeUnit;
85 -import java.util.concurrent.TimeoutException;
86 -import java.util.concurrent.atomic.AtomicBoolean;
87 -import java.util.concurrent.atomic.AtomicLong;
88 -import java.util.stream.Collectors;
89 -
90 -import static com.google.common.base.Preconditions.checkState;
91 -import static org.slf4j.LoggerFactory.getLogger;
92 92
93 /** 93 /**
94 * Provider which uses an OpenFlow controller to detect network 94 * Provider which uses an OpenFlow controller to detect network
...@@ -99,6 +99,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -99,6 +99,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
99 99
100 enum BatchState { STARTED, FINISHED, CANCELLED }; 100 enum BatchState { STARTED, FINISHED, CANCELLED };
101 101
102 + private static final int LOWEST_PRIORITY = 0;
103 +
102 private final Logger log = getLogger(getClass()); 104 private final Logger log = getLogger(getClass());
103 105
104 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -344,10 +346,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -344,10 +346,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
344 } 346 }
345 347
346 private boolean tableMissRule(Dpid dpid, OFFlowStatsEntry reply) { 348 private boolean tableMissRule(Dpid dpid, OFFlowStatsEntry reply) {
347 - if (reply.getVersion().equals(OFVersion.OF_10) || 349 + if (reply.getMatch().getMatchFields().iterator().hasNext()) {
348 - reply.getMatch().getMatchFields().iterator().hasNext()) {
349 return false; 350 return false;
350 } 351 }
352 + if (reply.getVersion().equals(OFVersion.OF_10)) {
353 + return reply.getPriority() == LOWEST_PRIORITY
354 + && reply.getActions().isEmpty();
355 + }
351 for (OFInstruction ins : reply.getInstructions()) { 356 for (OFInstruction ins : reply.getInstructions()) {
352 if (ins.getType() == OFInstructionType.APPLY_ACTIONS) { 357 if (ins.getType() == OFInstructionType.APPLY_ACTIONS) {
353 OFInstructionApplyActions apply = (OFInstructionApplyActions) ins; 358 OFInstructionApplyActions apply = (OFInstructionApplyActions) ins;
......