Committed by
Jonathan Hart
Added patch interface add and remove behavior, and implemented OVSDB driver
Change-Id: Ic7632906fcfe50ec224fabdc15cb902a70150fae
Showing
8 changed files
with
284 additions
and
9 deletions
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.net.behaviour; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Strings; | ||
20 | +import org.onosproject.net.AbstractDescription; | ||
21 | +import org.onosproject.net.SparseAnnotations; | ||
22 | + | ||
23 | +import java.util.Optional; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkArgument; | ||
26 | + | ||
27 | +/** | ||
28 | + * Default implementation of immutable patch interface description entity. | ||
29 | + */ | ||
30 | +public final class DefaultPatchDescription extends AbstractDescription | ||
31 | + implements PatchDescription { | ||
32 | + | ||
33 | + private final Optional<String> deviceId; | ||
34 | + private final String ifaceName; | ||
35 | + private final String peerName; | ||
36 | + | ||
37 | + private DefaultPatchDescription(Optional<String> deviceId, | ||
38 | + String ifaceName, | ||
39 | + String peerName, | ||
40 | + SparseAnnotations... annotations) { | ||
41 | + super(annotations); | ||
42 | + this.deviceId = deviceId; | ||
43 | + this.ifaceName = ifaceName; | ||
44 | + this.peerName = peerName; | ||
45 | + } | ||
46 | + | ||
47 | + | ||
48 | + @Override | ||
49 | + public Optional<String> deviceId() { | ||
50 | + return deviceId; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public String ifaceName() { | ||
55 | + return ifaceName; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public String peer() { | ||
60 | + return peerName; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public String toString() { | ||
65 | + return MoreObjects.toStringHelper(this) | ||
66 | + .add("deviceId", deviceId) | ||
67 | + .add("ifaceName", ifaceName) | ||
68 | + .add("peerName", peerName) | ||
69 | + .toString(); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Returns new builder instance. | ||
74 | + * | ||
75 | + * @return default patch description builder | ||
76 | + */ | ||
77 | + public static Builder builder() { | ||
78 | + return new Builder(); | ||
79 | + } | ||
80 | + | ||
81 | + public static final class Builder implements PatchDescription.Builder { | ||
82 | + | ||
83 | + private Optional<String> deviceId = Optional.empty(); | ||
84 | + private String ifaceName; | ||
85 | + private String peerName; | ||
86 | + | ||
87 | + private Builder() { | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public PatchDescription build() { | ||
92 | + return new DefaultPatchDescription(deviceId, ifaceName, peerName); | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public PatchDescription.Builder deviceId(String deviceId) { | ||
97 | + this.deviceId = Optional.ofNullable(deviceId); | ||
98 | + return this; | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public PatchDescription.Builder ifaceName(String ifaceName) { | ||
103 | + checkArgument(!Strings.isNullOrEmpty(ifaceName)); | ||
104 | + this.ifaceName = ifaceName; | ||
105 | + return this; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public PatchDescription.Builder peer(String peerName) { | ||
110 | + checkArgument(!Strings.isNullOrEmpty(peerName)); | ||
111 | + this.peerName = peerName; | ||
112 | + return this; | ||
113 | + } | ||
114 | + } | ||
115 | +} |
... | @@ -142,6 +142,23 @@ public interface InterfaceConfig extends HandlerBehaviour { | ... | @@ -142,6 +142,23 @@ public interface InterfaceConfig extends HandlerBehaviour { |
142 | boolean removeTunnelMode(String intf); | 142 | boolean removeTunnelMode(String intf); |
143 | 143 | ||
144 | /** | 144 | /** |
145 | + * Adds a patch mode to the supplied interface. | ||
146 | + * | ||
147 | + * @param ifaceName interface name to set patch mode | ||
148 | + * @param patchInterface interface description | ||
149 | + * @return true if the operation succeeds | ||
150 | + */ | ||
151 | + boolean addPatchMode(String ifaceName, PatchDescription patchInterface); | ||
152 | + | ||
153 | + /** | ||
154 | + * Removes a patch mode from the supplied interface. | ||
155 | + * | ||
156 | + * @param ifaceName interface name | ||
157 | + * @return true if the operation succeeds | ||
158 | + */ | ||
159 | + boolean removePatchMode(String ifaceName); | ||
160 | + | ||
161 | + /** | ||
145 | * Provides the interfaces configured on a device. | 162 | * Provides the interfaces configured on a device. |
146 | * | 163 | * |
147 | * @param deviceId the device ID | 164 | * @param deviceId the device ID | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.net.behaviour; | ||
17 | + | ||
18 | +import org.onosproject.net.Annotated; | ||
19 | +import org.onosproject.net.Description; | ||
20 | + | ||
21 | +import java.util.Optional; | ||
22 | + | ||
23 | +/** | ||
24 | + * Describes a patch interface. | ||
25 | + */ | ||
26 | +public interface PatchDescription extends Description, Annotated { | ||
27 | + | ||
28 | + /** | ||
29 | + * Returns the identifier of the device where this patch interface is. | ||
30 | + * | ||
31 | + * @return device identifier; empty value if not set | ||
32 | + */ | ||
33 | + Optional<String> deviceId(); | ||
34 | + | ||
35 | + /** | ||
36 | + * Return the name of the patch interface. | ||
37 | + * | ||
38 | + * @return patch interface name | ||
39 | + */ | ||
40 | + String ifaceName(); | ||
41 | + | ||
42 | + /** | ||
43 | + * Returns the name of the interface for the other side of the patch. | ||
44 | + * | ||
45 | + * @return peer patch interface name | ||
46 | + */ | ||
47 | + String peer(); | ||
48 | + | ||
49 | + /** | ||
50 | + * Builder of patch interface description entities. | ||
51 | + */ | ||
52 | + interface Builder { | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns new patch interface description. | ||
56 | + * | ||
57 | + * @return patch interface description | ||
58 | + */ | ||
59 | + PatchDescription build(); | ||
60 | + | ||
61 | + /** | ||
62 | + * Returns new patch interface description. | ||
63 | + * | ||
64 | + * @param deviceId device id | ||
65 | + * @return patch interface description builder | ||
66 | + */ | ||
67 | + Builder deviceId(String deviceId); | ||
68 | + /** | ||
69 | + * Returns patch interface description builder with a given interface name. | ||
70 | + * | ||
71 | + * @param ifaceName interface name | ||
72 | + * @return patch interface description builder | ||
73 | + */ | ||
74 | + Builder ifaceName(String ifaceName); | ||
75 | + | ||
76 | + /** | ||
77 | + * Returns patch interface description builder with a given peer. | ||
78 | + * | ||
79 | + * @param peerName peer patch interface name | ||
80 | + * @return patch interface description builder | ||
81 | + */ | ||
82 | + Builder peer(String peerName); | ||
83 | + } | ||
84 | + | ||
85 | +} |
... | @@ -22,6 +22,7 @@ import org.onlab.packet.VlanId; | ... | @@ -22,6 +22,7 @@ import org.onlab.packet.VlanId; |
22 | import org.onosproject.drivers.utilities.XmlConfigParser; | 22 | import org.onosproject.drivers.utilities.XmlConfigParser; |
23 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
24 | import org.onosproject.net.behaviour.InterfaceConfig; | 24 | import org.onosproject.net.behaviour.InterfaceConfig; |
25 | +import org.onosproject.net.behaviour.PatchDescription; | ||
25 | import org.onosproject.net.behaviour.TunnelDescription; | 26 | import org.onosproject.net.behaviour.TunnelDescription; |
26 | import org.onosproject.net.device.DeviceInterfaceDescription; | 27 | import org.onosproject.net.device.DeviceInterfaceDescription; |
27 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 28 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
... | @@ -490,5 +491,15 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour | ... | @@ -490,5 +491,15 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour |
490 | public boolean removeTunnelMode(String ifaceName) { | 491 | public boolean removeTunnelMode(String ifaceName) { |
491 | throw new UnsupportedOperationException("Remove tunnel mode is not supported"); | 492 | throw new UnsupportedOperationException("Remove tunnel mode is not supported"); |
492 | } | 493 | } |
494 | + | ||
495 | + @Override | ||
496 | + public boolean addPatchMode(String ifaceName, PatchDescription patchDesc) { | ||
497 | + throw new UnsupportedOperationException("Add patch interface is not supported"); | ||
498 | + } | ||
499 | + | ||
500 | + @Override | ||
501 | + public boolean removePatchMode(String ifaceName) { | ||
502 | + throw new UnsupportedOperationException("Remove patch interface is not supported"); | ||
503 | + } | ||
493 | } | 504 | } |
494 | 505 | ... | ... |
... | @@ -20,6 +20,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -20,6 +20,7 @@ import org.onlab.packet.IpAddress; |
20 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
21 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.behaviour.InterfaceConfig; | 22 | import org.onosproject.net.behaviour.InterfaceConfig; |
23 | +import org.onosproject.net.behaviour.PatchDescription; | ||
23 | import org.onosproject.net.behaviour.TunnelDescription; | 24 | import org.onosproject.net.behaviour.TunnelDescription; |
24 | import org.onosproject.net.device.DeviceInterfaceDescription; | 25 | import org.onosproject.net.device.DeviceInterfaceDescription; |
25 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 26 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
... | @@ -67,11 +68,28 @@ public class OvsdbInterfaceConfig extends AbstractHandlerBehaviour implements In | ... | @@ -67,11 +68,28 @@ public class OvsdbInterfaceConfig extends AbstractHandlerBehaviour implements In |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | public boolean removeAccessMode(String ifaceName) { | 70 | public boolean removeAccessMode(String ifaceName) { |
70 | - // TODO implement | ||
71 | throw new UnsupportedOperationException("Not implemented yet"); | 71 | throw new UnsupportedOperationException("Not implemented yet"); |
72 | } | 72 | } |
73 | 73 | ||
74 | @Override | 74 | @Override |
75 | + public boolean addPatchMode(String ifaceName, PatchDescription patchDesc) { | ||
76 | + OvsdbInterface ovsdbIface = OvsdbInterface.builder(patchDesc).build(); | ||
77 | + OvsdbClientService ovsdbClient = getOvsdbClient(handler()); | ||
78 | + | ||
79 | + if (!patchDesc.deviceId().isPresent()) { | ||
80 | + log.warn("Device ID is required {}", patchDesc); | ||
81 | + return false; | ||
82 | + } | ||
83 | + return ovsdbClient.createInterface(patchDesc.deviceId().get(), ovsdbIface); | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public boolean removePatchMode(String ifaceName) { | ||
88 | + OvsdbClientService ovsdbClient = getOvsdbClient(handler()); | ||
89 | + return ovsdbClient.dropInterface(ifaceName); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
75 | public boolean addTrunkMode(String ifaceName, List<VlanId> vlanIds) { | 93 | public boolean addTrunkMode(String ifaceName, List<VlanId> vlanIds) { |
76 | // TODO implement | 94 | // TODO implement |
77 | throw new UnsupportedOperationException("Not implemented yet"); | 95 | throw new UnsupportedOperationException("Not implemented yet"); | ... | ... |
... | @@ -60,6 +60,8 @@ public final class OvsdbConstant { | ... | @@ -60,6 +60,8 @@ public final class OvsdbConstant { |
60 | public static final String TUNNEL_LOCAL_IP = "local_ip"; | 60 | public static final String TUNNEL_LOCAL_IP = "local_ip"; |
61 | public static final String TUNNEL_REMOTE_IP = "remote_ip"; | 61 | public static final String TUNNEL_REMOTE_IP = "remote_ip"; |
62 | public static final String TUNNEL_KEY = "key"; | 62 | public static final String TUNNEL_KEY = "key"; |
63 | + // patch interface options | ||
64 | + public static final String PATCH_PEER = "peer"; | ||
63 | 65 | ||
64 | /** Controller table. */ | 66 | /** Controller table. */ |
65 | public static final String CONTROLLER = "Controller"; | 67 | public static final String CONTROLLER = "Controller"; | ... | ... |
... | @@ -23,6 +23,7 @@ import java.util.Objects; | ... | @@ -23,6 +23,7 @@ import java.util.Objects; |
23 | 23 | ||
24 | import com.google.common.collect.Maps; | 24 | import com.google.common.collect.Maps; |
25 | import org.onosproject.net.DefaultAnnotations; | 25 | import org.onosproject.net.DefaultAnnotations; |
26 | +import org.onosproject.net.behaviour.PatchDescription; | ||
26 | import org.onosproject.net.behaviour.TunnelDescription; | 27 | import org.onosproject.net.behaviour.TunnelDescription; |
27 | 28 | ||
28 | /** | 29 | /** |
... | @@ -154,6 +155,16 @@ public final class OvsdbInterface { | ... | @@ -154,6 +155,16 @@ public final class OvsdbInterface { |
154 | } | 155 | } |
155 | 156 | ||
156 | /** | 157 | /** |
158 | + * Returns new OVSDB interface builder with patch interface description. | ||
159 | + * | ||
160 | + * @param patchDesc patch interface description | ||
161 | + * @return ovsdb interface builder | ||
162 | + */ | ||
163 | + public static OvsdbInterface.Builder builder(PatchDescription patchDesc) { | ||
164 | + return new Builder(patchDesc); | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
157 | * Builder of OVSDB interface entities. | 168 | * Builder of OVSDB interface entities. |
158 | */ | 169 | */ |
159 | public static final class Builder { | 170 | public static final class Builder { |
... | @@ -173,18 +184,34 @@ public final class OvsdbInterface { | ... | @@ -173,18 +184,34 @@ public final class OvsdbInterface { |
173 | this.name = tunnelDesc.ifaceName(); | 184 | this.name = tunnelDesc.ifaceName(); |
174 | this.type = Type.valueOf(tunnelDesc.type().name()); | 185 | this.type = Type.valueOf(tunnelDesc.type().name()); |
175 | 186 | ||
187 | + Map<String, String> tunOptions = Maps.newHashMap(); | ||
176 | if (tunnelDesc.local().isPresent()) { | 188 | if (tunnelDesc.local().isPresent()) { |
177 | - options.put(TUNNEL_LOCAL_IP, tunnelDesc.local().get().strValue()); | 189 | + tunOptions.put(TUNNEL_LOCAL_IP, tunnelDesc.local().get().strValue()); |
178 | } | 190 | } |
179 | if (tunnelDesc.remote().isPresent()) { | 191 | if (tunnelDesc.remote().isPresent()) { |
180 | - options.put(TUNNEL_REMOTE_IP, tunnelDesc.remote().get().strValue()); | 192 | + tunOptions.put(TUNNEL_REMOTE_IP, tunnelDesc.remote().get().strValue()); |
181 | } | 193 | } |
182 | if (tunnelDesc.key().isPresent()) { | 194 | if (tunnelDesc.key().isPresent()) { |
183 | - options.put(TUNNEL_KEY, tunnelDesc.key().get().strValue()); | 195 | + tunOptions.put(TUNNEL_KEY, tunnelDesc.key().get().strValue()); |
184 | } | 196 | } |
185 | 197 | ||
186 | // set other configurations if there are any | 198 | // set other configurations if there are any |
187 | - options.putAll(((DefaultAnnotations) tunnelDesc.annotations()).asMap()); | 199 | + tunOptions.putAll(((DefaultAnnotations) tunnelDesc.annotations()).asMap()); |
200 | + options = tunOptions; | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Constructs a builder with a given patch interface description. | ||
205 | + * | ||
206 | + * @param patchDesc patch interface description | ||
207 | + */ | ||
208 | + private Builder(PatchDescription patchDesc) { | ||
209 | + this.name = patchDesc.ifaceName(); | ||
210 | + this.type = Type.PATCH; | ||
211 | + | ||
212 | + Map<String, String> patchOptions = Maps.newHashMap(); | ||
213 | + patchOptions.put(PATCH_PEER, patchDesc.peer()); | ||
214 | + options = patchOptions; | ||
188 | } | 215 | } |
189 | 216 | ||
190 | /** | 217 | /** | ... | ... |
... | @@ -537,21 +537,21 @@ public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientServ | ... | @@ -537,21 +537,21 @@ public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientServ |
537 | ArrayList<Operation> operations = Lists.newArrayList(); | 537 | ArrayList<Operation> operations = Lists.newArrayList(); |
538 | DatabaseSchema dbSchema = schema.get(DATABASENAME); | 538 | DatabaseSchema dbSchema = schema.get(DATABASENAME); |
539 | 539 | ||
540 | - // insert a new port to the port table | 540 | + // insert a new port with the interface name |
541 | Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT); | 541 | Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT); |
542 | port.setName(ovsdbIface.name()); | 542 | port.setName(ovsdbIface.name()); |
543 | Insert portInsert = new Insert(dbSchema.getTableSchema(PORT), PORT, port.getRow()); | 543 | Insert portInsert = new Insert(dbSchema.getTableSchema(PORT), PORT, port.getRow()); |
544 | portInsert.getRow().put(INTERFACES, Uuid.uuid(INTERFACE)); | 544 | portInsert.getRow().put(INTERFACES, Uuid.uuid(INTERFACE)); |
545 | operations.add(portInsert); | 545 | operations.add(portInsert); |
546 | 546 | ||
547 | - // update the bridge table | 547 | + // update the bridge table with the new port |
548 | Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid)); | 548 | Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid)); |
549 | Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid(PORT)); | 549 | Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid(PORT)); |
550 | List<Condition> conditions = Lists.newArrayList(condition); | 550 | List<Condition> conditions = Lists.newArrayList(condition); |
551 | List<Mutation> mutations = Lists.newArrayList(mutation); | 551 | List<Mutation> mutations = Lists.newArrayList(mutation); |
552 | operations.add(new Mutate(dbSchema.getTableSchema(BRIDGE), conditions, mutations)); | 552 | operations.add(new Mutate(dbSchema.getTableSchema(BRIDGE), conditions, mutations)); |
553 | 553 | ||
554 | - // insert a tunnel interface | 554 | + // insert an interface |
555 | Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE); | 555 | Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE); |
556 | intf.setName(ovsdbIface.name()); | 556 | intf.setName(ovsdbIface.name()); |
557 | intf.setType(ovsdbIface.typeToString()); | 557 | intf.setType(ovsdbIface.typeToString()); |
... | @@ -560,7 +560,7 @@ public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientServ | ... | @@ -560,7 +560,7 @@ public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientServ |
560 | operations.add(intfInsert); | 560 | operations.add(intfInsert); |
561 | 561 | ||
562 | transactConfig(DATABASENAME, operations); | 562 | transactConfig(DATABASENAME, operations); |
563 | - log.info("Created interface {}", ovsdbIface.name()); | 563 | + log.info("Created interface {}", ovsdbIface); |
564 | return true; | 564 | return true; |
565 | } | 565 | } |
566 | 566 | ... | ... |
-
Please register or login to post a comment