Committed by
Gerrit Code Review
ONOS-2724
Fix bug of apply flowrule and remove flowrule Change-Id: Ia7dec83206c3f5e24f912f111bd87dab6eab4610
Showing
9 changed files
with
119 additions
and
22 deletions
This diff is collapsed. Click to expand it.
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.net.behaviour; | 16 | package org.onosproject.net.behaviour; |
17 | 17 | ||
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | +import java.util.List; | ||
19 | import java.util.Set; | 20 | import java.util.Set; |
20 | 21 | ||
21 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
... | @@ -75,4 +76,12 @@ public interface BridgeConfig extends HandlerBehaviour { | ... | @@ -75,4 +76,12 @@ public interface BridgeConfig extends HandlerBehaviour { |
75 | * @return portNumbers set of PortNumber | 76 | * @return portNumbers set of PortNumber |
76 | */ | 77 | */ |
77 | Set<PortNumber> getPortNumbers(); | 78 | Set<PortNumber> getPortNumbers(); |
79 | + | ||
80 | + /** | ||
81 | + * Get logical/virtual ports by ifaceIds. | ||
82 | + * | ||
83 | + * @param ifaceIds the ifaceid that needed | ||
84 | + * @return list of PortNumber | ||
85 | + */ | ||
86 | + List<PortNumber> getLocalPorts(Iterable<String> ifaceIds); | ||
78 | } | 87 | } | ... | ... |
... | @@ -153,8 +153,8 @@ public class DefaultDriver implements Driver { | ... | @@ -153,8 +153,8 @@ public class DefaultDriver implements Driver { |
153 | // Creates an instance of behaviour primed with the specified driver data. | 153 | // Creates an instance of behaviour primed with the specified driver data. |
154 | private <T extends Behaviour> T createBehaviour(DriverData data, DriverHandler handler, | 154 | private <T extends Behaviour> T createBehaviour(DriverData data, DriverHandler handler, |
155 | Class<T> behaviourClass) { | 155 | Class<T> behaviourClass) { |
156 | - checkArgument(handler != null || !HandlerBehaviour.class.isAssignableFrom(behaviourClass), | 156 | + //checkArgument(handler != null || !HandlerBehaviour.class.isAssignableFrom(behaviourClass), |
157 | - "{} is applicable only to handler context", behaviourClass.getName()); | 157 | + // "{} is applicable only to handler context", behaviourClass.getName()); |
158 | 158 | ||
159 | // Locate the implementation of the requested behaviour. | 159 | // Locate the implementation of the requested behaviour. |
160 | Class<? extends Behaviour> implementation = behaviours.get(behaviourClass); | 160 | Class<? extends Behaviour> implementation = behaviours.get(behaviourClass); | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.driver.ovsdb; | 16 | package org.onosproject.driver.ovsdb; |
17 | 17 | ||
18 | +import java.util.ArrayList; | ||
18 | import java.util.Collection; | 19 | import java.util.Collection; |
20 | +import java.util.List; | ||
19 | import java.util.Set; | 21 | import java.util.Set; |
20 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; |
21 | 23 | ||
... | @@ -146,4 +148,18 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -146,4 +148,18 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
146 | ) | 148 | ) |
147 | .collect(Collectors.toSet()); | 149 | .collect(Collectors.toSet()); |
148 | } | 150 | } |
151 | + | ||
152 | + @Override | ||
153 | + public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { | ||
154 | + List<PortNumber> ports = new ArrayList<>(); | ||
155 | + DriverHandler handler = handler(); | ||
156 | + OvsdbClientService clientService = getOvsdbClientService(handler); | ||
157 | + Set<OvsdbPort> ovsdbSet = clientService.getLocalPorts(ifaceIds); | ||
158 | + ovsdbSet.forEach(o -> { | ||
159 | + PortNumber port = PortNumber.portNumber(o.portNumber().value(), | ||
160 | + o.portName().value()); | ||
161 | + ports.add(port); | ||
162 | + }); | ||
163 | + return ports; | ||
164 | + } | ||
149 | } | 165 | } | ... | ... |
... | @@ -26,7 +26,6 @@ import org.onosproject.net.DeviceId; | ... | @@ -26,7 +26,6 @@ import org.onosproject.net.DeviceId; |
26 | import org.onosproject.net.behaviour.Pipeliner; | 26 | import org.onosproject.net.behaviour.Pipeliner; |
27 | import org.onosproject.net.behaviour.PipelinerContext; | 27 | import org.onosproject.net.behaviour.PipelinerContext; |
28 | import org.onosproject.net.device.DeviceService; | 28 | import org.onosproject.net.device.DeviceService; |
29 | -import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
30 | import org.onosproject.net.flow.DefaultFlowRule; | 29 | import org.onosproject.net.flow.DefaultFlowRule; |
31 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
32 | import org.onosproject.net.flow.FlowRule; | 31 | import org.onosproject.net.flow.FlowRule; |
... | @@ -48,9 +47,10 @@ import org.slf4j.Logger; | ... | @@ -48,9 +47,10 @@ import org.slf4j.Logger; |
48 | /** | 47 | /** |
49 | * Driver for standard OpenVSwitch. | 48 | * Driver for standard OpenVSwitch. |
50 | */ | 49 | */ |
51 | -public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | 50 | +public class OpenVSwitchPipeline extends DefaultSingleTablePipeline |
52 | implements Pipeliner { | 51 | implements Pipeliner { |
53 | 52 | ||
53 | + private static final String VTN_APP_ID = "org.onosproject.app.vtn"; | ||
54 | private final Logger log = getLogger(getClass()); | 54 | private final Logger log = getLogger(getClass()); |
55 | private CoreService coreService; | 55 | private CoreService coreService; |
56 | private ServiceDirectory serviceDirectory; | 56 | private ServiceDirectory serviceDirectory; |
... | @@ -58,14 +58,13 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -58,14 +58,13 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
58 | protected DeviceId deviceId; | 58 | protected DeviceId deviceId; |
59 | protected FlowRuleService flowRuleService; | 59 | protected FlowRuleService flowRuleService; |
60 | protected DeviceService deviceService; | 60 | protected DeviceService deviceService; |
61 | - private static final int MAC_TABLE_PRIORITY = 0xffff; | ||
62 | - private static final int PORT_TABLE_PRIORITY = 0xffff; | ||
63 | private static final int TIME_OUT = 0; | 61 | private static final int TIME_OUT = 0; |
64 | private static final int MAC_TABLE = 40; | 62 | private static final int MAC_TABLE = 40; |
65 | private static final int PORT_TABLE = 0; | 63 | private static final int PORT_TABLE = 0; |
66 | 64 | ||
67 | @Override | 65 | @Override |
68 | public void init(DeviceId deviceId, PipelinerContext context) { | 66 | public void init(DeviceId deviceId, PipelinerContext context) { |
67 | + super.init(deviceId, context); | ||
69 | this.serviceDirectory = context.directory(); | 68 | this.serviceDirectory = context.directory(); |
70 | this.deviceId = deviceId; | 69 | this.deviceId = deviceId; |
71 | 70 | ||
... | @@ -79,11 +78,15 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -79,11 +78,15 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
79 | 78 | ||
80 | @Override | 79 | @Override |
81 | public void filter(FilteringObjective filteringObjective) { | 80 | public void filter(FilteringObjective filteringObjective) { |
82 | - // TODO Auto-generated method stub | 81 | + super.filter(filteringObjective); |
83 | } | 82 | } |
84 | 83 | ||
85 | @Override | 84 | @Override |
86 | public void forward(ForwardingObjective fwd) { | 85 | public void forward(ForwardingObjective fwd) { |
86 | + if (!VTN_APP_ID.equals(fwd.appId().name())) { | ||
87 | + super.forward(fwd); | ||
88 | + return; | ||
89 | + } | ||
87 | Collection<FlowRule> rules; | 90 | Collection<FlowRule> rules; |
88 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations | 91 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations |
89 | .builder(); | 92 | .builder(); |
... | @@ -119,8 +122,7 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -119,8 +122,7 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
119 | 122 | ||
120 | @Override | 123 | @Override |
121 | public void next(NextObjective nextObjective) { | 124 | public void next(NextObjective nextObjective) { |
122 | - // TODO Auto-generated method stub | 125 | + super.next(nextObjective); |
123 | - | ||
124 | } | 126 | } |
125 | 127 | ||
126 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { | 128 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
... | @@ -148,18 +150,16 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour | ... | @@ -148,18 +150,16 @@ public class OpenVSwitchPipeline extends AbstractHandlerBehaviour |
148 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() | 150 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
149 | .fromApp(fwd.appId()).withPriority(fwd.priority()) | 151 | .fromApp(fwd.appId()).withPriority(fwd.priority()) |
150 | .forDevice(deviceId).withSelector(selector) | 152 | .forDevice(deviceId).withSelector(selector) |
151 | - .makeTemporary(TIME_OUT); | 153 | + .withTreatment(tb).makeTemporary(TIME_OUT); |
152 | - | 154 | + ruleBuilder.withPriority(fwd.priority()); |
153 | if (fwd.permanent()) { | 155 | if (fwd.permanent()) { |
154 | ruleBuilder.makePermanent(); | 156 | ruleBuilder.makePermanent(); |
155 | } | 157 | } |
156 | if (selector.getCriterion(Type.ETH_DST) != null | 158 | if (selector.getCriterion(Type.ETH_DST) != null |
157 | || tb.allInstructions().contains(Instructions.createDrop())) { | 159 | || tb.allInstructions().contains(Instructions.createDrop())) { |
158 | - ruleBuilder.withPriority(MAC_TABLE_PRIORITY); | ||
159 | ruleBuilder.withTreatment(tb); | 160 | ruleBuilder.withTreatment(tb); |
160 | ruleBuilder.forTable(MAC_TABLE); | 161 | ruleBuilder.forTable(MAC_TABLE); |
161 | } else { | 162 | } else { |
162 | - ruleBuilder.withPriority(PORT_TABLE_PRIORITY); | ||
163 | TrafficTreatment.Builder newTraffic = DefaultTrafficTreatment.builder(); | 163 | TrafficTreatment.Builder newTraffic = DefaultTrafficTreatment.builder(); |
164 | tb.allInstructions().forEach(t -> newTraffic.add(t)); | 164 | tb.allInstructions().forEach(t -> newTraffic.add(t)); |
165 | newTraffic.transition(MAC_TABLE); | 165 | newTraffic.transition(MAC_TABLE); | ... | ... |
... | @@ -115,5 +115,10 @@ | ... | @@ -115,5 +115,10 @@ |
115 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" | 115 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" |
116 | impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> | 116 | impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> |
117 | </driver> | 117 | </driver> |
118 | + <driver name="onosfw" extends="default" | ||
119 | + manufacturer="" hwVersion="" swVersion=""> | ||
120 | + <behaviour api="org.onosproject.net.behaviour.Pipeliner" | ||
121 | + impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/> | ||
122 | + </driver> | ||
118 | </drivers> | 123 | </drivers> |
119 | 124 | ... | ... |
... | @@ -212,7 +212,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -212,7 +212,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
212 | void removeRow(String dbName, String tableName, String uuid); | 212 | void removeRow(String dbName, String tableName, String uuid); |
213 | 213 | ||
214 | /** | 214 | /** |
215 | - * Update the local ovsdb store. | 215 | + * Updates the local ovsdb store. |
216 | * | 216 | * |
217 | * @param dbName database name | 217 | * @param dbName database name |
218 | * @param tableName table name | 218 | * @param tableName table name |
... | @@ -221,4 +221,11 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -221,4 +221,11 @@ public interface OvsdbClientService extends OvsdbRPC { |
221 | */ | 221 | */ |
222 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); | 222 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); |
223 | 223 | ||
224 | + /** | ||
225 | + * Gets ovsdb local ports. | ||
226 | + * | ||
227 | + * @param ifaceids the ifaceid that needed | ||
228 | + * @return ovsdb ports | ||
229 | + */ | ||
230 | + Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids); | ||
224 | } | 231 | } | ... | ... |
... | @@ -46,6 +46,7 @@ import org.onosproject.ovsdb.rfc.message.OperationResult; | ... | @@ -46,6 +46,7 @@ import org.onosproject.ovsdb.rfc.message.OperationResult; |
46 | import org.onosproject.ovsdb.rfc.message.TableUpdates; | 46 | import org.onosproject.ovsdb.rfc.message.TableUpdates; |
47 | import org.onosproject.ovsdb.rfc.notation.Condition; | 47 | import org.onosproject.ovsdb.rfc.notation.Condition; |
48 | import org.onosproject.ovsdb.rfc.notation.Mutation; | 48 | import org.onosproject.ovsdb.rfc.notation.Mutation; |
49 | +import org.onosproject.ovsdb.rfc.notation.OvsdbMap; | ||
49 | import org.onosproject.ovsdb.rfc.notation.OvsdbSet; | 50 | import org.onosproject.ovsdb.rfc.notation.OvsdbSet; |
50 | import org.onosproject.ovsdb.rfc.notation.Row; | 51 | import org.onosproject.ovsdb.rfc.notation.Row; |
51 | import org.onosproject.ovsdb.rfc.notation.UUID; | 52 | import org.onosproject.ovsdb.rfc.notation.UUID; |
... | @@ -74,6 +75,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -74,6 +75,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
74 | import com.google.common.base.Function; | 75 | import com.google.common.base.Function; |
75 | import com.google.common.collect.Lists; | 76 | import com.google.common.collect.Lists; |
76 | import com.google.common.collect.Maps; | 77 | import com.google.common.collect.Maps; |
78 | +import com.google.common.collect.Sets; | ||
77 | import com.google.common.util.concurrent.Futures; | 79 | import com.google.common.util.concurrent.Futures; |
78 | import com.google.common.util.concurrent.ListenableFuture; | 80 | import com.google.common.util.concurrent.ListenableFuture; |
79 | import com.google.common.util.concurrent.SettableFuture; | 81 | import com.google.common.util.concurrent.SettableFuture; |
... | @@ -1125,4 +1127,62 @@ public class DefaultOvsdbClient | ... | @@ -1125,4 +1127,62 @@ public class DefaultOvsdbClient |
1125 | Iterator<Integer> it = ofPorts.iterator(); | 1127 | Iterator<Integer> it = ofPorts.iterator(); |
1126 | return Long.parseLong(it.next().toString()); | 1128 | return Long.parseLong(it.next().toString()); |
1127 | } | 1129 | } |
1130 | + | ||
1131 | + @Override | ||
1132 | + public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) { | ||
1133 | + Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | ||
1134 | + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | ||
1135 | + if (tableStore == null) { | ||
1136 | + return null; | ||
1137 | + } | ||
1138 | + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); | ||
1139 | + if (rowStore == null) { | ||
1140 | + return null; | ||
1141 | + } | ||
1142 | + ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | ||
1143 | + for (String uuid : rows.keySet()) { | ||
1144 | + Row row = getRow(OvsdbConstant.DATABASENAME, | ||
1145 | + OvsdbConstant.INTERFACE, uuid); | ||
1146 | + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); | ||
1147 | + Interface intf = (Interface) TableGenerator | ||
1148 | + .getTable(dbSchema, row, OvsdbTable.INTERFACE); | ||
1149 | + if (intf == null || getIfaceid(intf) == null) { | ||
1150 | + continue; | ||
1151 | + } | ||
1152 | + String portName = intf.getName(); | ||
1153 | + Set<String> ifaceidSet = Sets.newHashSet(ifaceids); | ||
1154 | + if (portName.startsWith("vxlan") | ||
1155 | + || !ifaceidSet.contains(getIfaceid(intf))) { | ||
1156 | + continue; | ||
1157 | + } | ||
1158 | + long ofPort = getOfPort(intf); | ||
1159 | + if ((ofPort < 0) || (portName == null)) { | ||
1160 | + continue; | ||
1161 | + } | ||
1162 | + | ||
1163 | + OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), | ||
1164 | + new OvsdbPortName(portName)); | ||
1165 | + if (ovsdbPort != null) { | ||
1166 | + ovsdbPorts.add(ovsdbPort); | ||
1167 | + } | ||
1168 | + } | ||
1169 | + return ovsdbPorts; | ||
1170 | + } | ||
1171 | + | ||
1172 | + private String getIfaceid(Interface intf) { | ||
1173 | + OvsdbMap ovsdbMap = (OvsdbMap) intf.getExternalIdsColumn().data(); | ||
1174 | + @SuppressWarnings("unchecked") | ||
1175 | + Map<String, String> externalIds = ovsdbMap.map(); | ||
1176 | + if (externalIds.isEmpty()) { | ||
1177 | + log.warn("The external_ids is null"); | ||
1178 | + return null; | ||
1179 | + } | ||
1180 | + String ifaceid = externalIds | ||
1181 | + .get(OvsdbConstant.EXTERNAL_ID_INTERFACE_ID); | ||
1182 | + if (ifaceid == null) { | ||
1183 | + log.warn("The ifaceid is null"); | ||
1184 | + return null; | ||
1185 | + } | ||
1186 | + return ifaceid; | ||
1187 | + } | ||
1128 | } | 1188 | } | ... | ... |
... | @@ -220,7 +220,6 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -220,7 +220,6 @@ public class OvsdbControllerImpl implements OvsdbController { |
220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", | 220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", |
221 | uuid.value(), dbName, tableName); | 221 | uuid.value(), dbName, tableName); |
222 | 222 | ||
223 | - Row oldRow = update.getOld(uuid); | ||
224 | Row newRow = update.getNew(uuid); | 223 | Row newRow = update.getNew(uuid); |
225 | if (newRow != null) { | 224 | if (newRow != null) { |
226 | clientService.updateOvsdbStore(dbName, tableName, | 225 | clientService.updateOvsdbStore(dbName, tableName, |
... | @@ -228,18 +227,19 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -228,18 +227,19 @@ public class OvsdbControllerImpl implements OvsdbController { |
228 | 227 | ||
229 | if (OvsdbConstant.INTERFACE.equals(tableName)) { | 228 | if (OvsdbConstant.INTERFACE.equals(tableName)) { |
230 | dispatchInterfaceEvent(clientService, | 229 | dispatchInterfaceEvent(clientService, |
231 | - newRow, null, | 230 | + newRow, |
232 | OvsdbEvent.Type.PORT_ADDED, | 231 | OvsdbEvent.Type.PORT_ADDED, |
233 | dbSchema); | 232 | dbSchema); |
234 | } | 233 | } |
235 | } else if (update.getOld(uuid) != null) { | 234 | } else if (update.getOld(uuid) != null) { |
236 | - clientService.removeRow(dbName, tableName, uuid.value()); | 235 | + if (OvsdbConstant.INTERFACE.equals(tableName)) { |
237 | - if (OvsdbConstant.PORT.equals(tableName)) { | 236 | + Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value()); |
238 | - dispatchInterfaceEvent(clientService, null, | 237 | + dispatchInterfaceEvent(clientService, |
239 | - oldRow, | 238 | + row, |
240 | OvsdbEvent.Type.PORT_REMOVED, | 239 | OvsdbEvent.Type.PORT_REMOVED, |
241 | dbSchema); | 240 | dbSchema); |
242 | } | 241 | } |
242 | + clientService.removeRow(dbName, tableName, uuid.value()); | ||
243 | } | 243 | } |
244 | } | 244 | } |
245 | } | 245 | } |
... | @@ -255,13 +255,13 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -255,13 +255,13 @@ public class OvsdbControllerImpl implements OvsdbController { |
255 | * @param dbSchema ovsdb database schema | 255 | * @param dbSchema ovsdb database schema |
256 | */ | 256 | */ |
257 | private void dispatchInterfaceEvent(OvsdbClientService clientService, | 257 | private void dispatchInterfaceEvent(OvsdbClientService clientService, |
258 | - Row newRow, Row oldRow, | 258 | + Row row, |
259 | Type eventType, | 259 | Type eventType, |
260 | DatabaseSchema dbSchema) { | 260 | DatabaseSchema dbSchema) { |
261 | 261 | ||
262 | long dpid = getDataPathid(clientService, dbSchema); | 262 | long dpid = getDataPathid(clientService, dbSchema); |
263 | Interface intf = (Interface) TableGenerator | 263 | Interface intf = (Interface) TableGenerator |
264 | - .getTable(dbSchema, newRow, OvsdbTable.INTERFACE); | 264 | + .getTable(dbSchema, row, OvsdbTable.INTERFACE); |
265 | if (intf == null) { | 265 | if (intf == null) { |
266 | return; | 266 | return; |
267 | } | 267 | } | ... | ... |
-
Please register or login to post a comment