Committed by
Jonathan Hart
CORD-131 Added XOS vtn service and port APIs
Change-Id: Ide34212eeb593af5af8db218c6dd2af7d5ab4eaa
Showing
12 changed files
with
664 additions
and
81 deletions
... | @@ -66,6 +66,8 @@ import org.onosproject.net.packet.PacketProcessor; | ... | @@ -66,6 +66,8 @@ import org.onosproject.net.packet.PacketProcessor; |
66 | import org.onosproject.net.packet.PacketService; | 66 | import org.onosproject.net.packet.PacketService; |
67 | import org.onosproject.net.provider.AbstractProvider; | 67 | import org.onosproject.net.provider.AbstractProvider; |
68 | import org.onosproject.net.provider.ProviderId; | 68 | import org.onosproject.net.provider.ProviderId; |
69 | +import org.onosproject.xosclient.api.VtnServiceApi; | ||
70 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
69 | import org.onosproject.xosclient.api.XosAccess; | 71 | import org.onosproject.xosclient.api.XosAccess; |
70 | import org.onosproject.xosclient.api.XosClientService; | 72 | import org.onosproject.xosclient.api.XosClientService; |
71 | import org.openstack4j.api.OSClient; | 73 | import org.openstack4j.api.OSClient; |
... | @@ -166,6 +168,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -166,6 +168,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
166 | private CordVtnRuleInstaller ruleInstaller; | 168 | private CordVtnRuleInstaller ruleInstaller; |
167 | private CordVtnArpProxy arpProxy; | 169 | private CordVtnArpProxy arpProxy; |
168 | 170 | ||
171 | + private volatile XosAccess xosAccess = null; | ||
169 | private volatile Access osAccess = null; | 172 | private volatile Access osAccess = null; |
170 | private volatile MacAddress privateGatewayMac = MacAddress.NONE; | 173 | private volatile MacAddress privateGatewayMac = MacAddress.NONE; |
171 | 174 | ||
... | @@ -446,15 +449,16 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -446,15 +449,16 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
446 | Set<CordServiceId> tServices = Sets.newHashSet(); | 449 | Set<CordServiceId> tServices = Sets.newHashSet(); |
447 | Set<CordServiceId> pServices = Sets.newHashSet(); | 450 | Set<CordServiceId> pServices = Sets.newHashSet(); |
448 | 451 | ||
449 | - if (xosClient.access() != null) { | 452 | + if (xosAccess != null) { |
450 | - tServices = xosClient.vtnServiceApi().getTenantServices(serviceId.id()) | 453 | + VtnServiceApi vtnServiceApi = xosClient.getClient(xosAccess).vtnService(); |
454 | + tServices = vtnServiceApi.tenantServices(VtnServiceId.of(serviceId.id())) | ||
451 | .stream() | 455 | .stream() |
452 | - .map(CordServiceId::of) | 456 | + .map(id -> CordServiceId.of(id.id())) |
453 | .collect(Collectors.toSet()); | 457 | .collect(Collectors.toSet()); |
454 | 458 | ||
455 | - pServices = xosClient.vtnServiceApi().getProviderServices(serviceId.id()) | 459 | + pServices = vtnServiceApi.providerServices(VtnServiceId.of(serviceId.id())) |
456 | .stream() | 460 | .stream() |
457 | - .map(CordServiceId::of) | 461 | + .map(id -> CordServiceId.of(id.id())) |
458 | .collect(Collectors.toSet()); | 462 | .collect(Collectors.toSet()); |
459 | } | 463 | } |
460 | 464 | ||
... | @@ -788,8 +792,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -788,8 +792,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
788 | xosAccess.endpoint(), | 792 | xosAccess.endpoint(), |
789 | xosAccess.username(), | 793 | xosAccess.username(), |
790 | xosAccess.password()); | 794 | xosAccess.password()); |
791 | - | 795 | + this.xosAccess = xosAccess; |
792 | - xosClient.setAccess(xosAccess); | ||
793 | } | 796 | } |
794 | 797 | ||
795 | /** | 798 | /** | ... | ... |
... | @@ -44,6 +44,11 @@ | ... | @@ -44,6 +44,11 @@ |
44 | <groupId>org.osgi</groupId> | 44 | <groupId>org.osgi</groupId> |
45 | <artifactId>org.osgi.compendium</artifactId> | 45 | <artifactId>org.osgi.compendium</artifactId> |
46 | </dependency> | 46 | </dependency> |
47 | + <dependency> | ||
48 | + <groupId>org.onosproject</groupId> | ||
49 | + <artifactId>onlab-misc</artifactId> | ||
50 | + <version>${project.version}</version> | ||
51 | + </dependency> | ||
47 | </dependencies> | 52 | </dependencies> |
48 | 53 | ||
49 | </project> | 54 | </project> | ... | ... |
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.xosclient.api; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | +import org.onlab.packet.MacAddress; | ||
21 | + | ||
22 | +import java.util.Map; | ||
23 | +import java.util.Objects; | ||
24 | + | ||
25 | +/** | ||
26 | + * Representation of port in a CORD VTN controlled network, it can be for VM | ||
27 | + * or container. | ||
28 | + */ | ||
29 | +public final class VtnPort { | ||
30 | + | ||
31 | + private final VtnPortId id; | ||
32 | + private final String name; | ||
33 | + private final VtnServiceId serviceId; | ||
34 | + private final MacAddress mac; | ||
35 | + private final IpAddress ip; | ||
36 | + // TODO remove this when XOS provides vSG information | ||
37 | + private final Map<IpAddress, MacAddress> addressPairs; | ||
38 | + | ||
39 | + | ||
40 | + /** | ||
41 | + * Creates a new vtn port with the specified entities. | ||
42 | + * | ||
43 | + * @param id vtn port id | ||
44 | + * @param name vtn port name | ||
45 | + * @param serviceId id of the service this port is in | ||
46 | + * @param mac mac address | ||
47 | + * @param ip ip address | ||
48 | + * @param addressPairs ip and mac pairs of nested container | ||
49 | + */ | ||
50 | + public VtnPort(VtnPortId id, | ||
51 | + String name, | ||
52 | + VtnServiceId serviceId, | ||
53 | + MacAddress mac, | ||
54 | + IpAddress ip, | ||
55 | + Map<IpAddress, MacAddress> addressPairs) { | ||
56 | + this.id = id; | ||
57 | + this.name = name; | ||
58 | + this.serviceId = serviceId; | ||
59 | + this.mac = mac; | ||
60 | + this.ip = ip; | ||
61 | + this.addressPairs = addressPairs; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Returns vtn port ID. | ||
66 | + * | ||
67 | + * @return vtn port id | ||
68 | + */ | ||
69 | + public VtnPortId id() { | ||
70 | + return id; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Returns vtn port name. | ||
75 | + * | ||
76 | + * @return vtn port name | ||
77 | + */ | ||
78 | + public String name() { | ||
79 | + return name; | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * Returns the ID of the service this port is in. | ||
84 | + * | ||
85 | + * @return vtn service id | ||
86 | + */ | ||
87 | + public VtnServiceId serviceId() { | ||
88 | + return serviceId; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * Returns MAC address of this port. | ||
93 | + * | ||
94 | + * @return mac address | ||
95 | + */ | ||
96 | + public MacAddress mac() { | ||
97 | + return mac; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Returns IP address of this port. | ||
102 | + * | ||
103 | + * @return ip address | ||
104 | + */ | ||
105 | + public IpAddress ip() { | ||
106 | + return ip; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Returns address pairs of the nested containers inside. | ||
111 | + * | ||
112 | + * @return map of ip and address | ||
113 | + */ | ||
114 | + public Map<IpAddress, MacAddress> addressPairs() { | ||
115 | + return addressPairs; | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public int hashCode() { | ||
120 | + return Objects.hash(id); | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public boolean equals(Object obj) { | ||
125 | + if (this == obj) { | ||
126 | + return true; | ||
127 | + } | ||
128 | + if (!(obj instanceof VtnPort)) { | ||
129 | + return false; | ||
130 | + } | ||
131 | + final VtnPort other = (VtnPort) obj; | ||
132 | + return Objects.equals(this.id, other.id); | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public String toString() { | ||
137 | + return MoreObjects.toStringHelper(this) | ||
138 | + .add("id", id) | ||
139 | + .add("name", name) | ||
140 | + .add("serviceId", serviceId) | ||
141 | + .add("mac", mac) | ||
142 | + .add("ip", ip) | ||
143 | + .add("addressPairs", addressPairs) | ||
144 | + .toString(); | ||
145 | + } | ||
146 | +} |
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.xosclient.api; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +/** | ||
21 | + * Service for interacting with XOS VTN ports. | ||
22 | + */ | ||
23 | +public interface VtnPortApi { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns all ports. | ||
27 | + * | ||
28 | + * @return set of ports | ||
29 | + */ | ||
30 | + Set<VtnPort> vtnPorts(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns all ports with a given service. | ||
34 | + * | ||
35 | + * @param serviceId service id | ||
36 | + * @return set of ports | ||
37 | + */ | ||
38 | + Set<VtnPort> vtnPorts(VtnServiceId serviceId); | ||
39 | + | ||
40 | + /** | ||
41 | + * Returns port information with port id. | ||
42 | + * | ||
43 | + * @param portId port id | ||
44 | + * @return vtn port; null if it fails to get port information | ||
45 | + */ | ||
46 | + VtnPort vtnPort(VtnPortId portId); | ||
47 | +} |
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.xosclient.api; | ||
17 | + | ||
18 | +import com.google.common.base.Strings; | ||
19 | +import org.onlab.util.Identifier; | ||
20 | + | ||
21 | +import static com.google.common.base.Preconditions.checkArgument; | ||
22 | + | ||
23 | +/** | ||
24 | + * Representation of VTN port ID. | ||
25 | + */ | ||
26 | +public final class VtnPortId extends Identifier<String> { | ||
27 | + | ||
28 | + private VtnPortId(String id) { | ||
29 | + super(id); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns vtn port identifier with value. | ||
34 | + * | ||
35 | + * @param id id | ||
36 | + * @return instance port id | ||
37 | + */ | ||
38 | + public static VtnPortId of(String id) { | ||
39 | + checkArgument(!Strings.isNullOrEmpty(id)); | ||
40 | + return new VtnPortId(id); | ||
41 | + } | ||
42 | +} |
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.xosclient.api; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.collect.Sets; | ||
20 | +import org.onlab.packet.IpAddress; | ||
21 | +import org.onlab.packet.IpPrefix; | ||
22 | + | ||
23 | +import java.util.Objects; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
27 | + | ||
28 | +/** | ||
29 | + * Representation of CORD VTN controlled network service. | ||
30 | + */ | ||
31 | +public final class VtnService { | ||
32 | + | ||
33 | + public enum NetworkType { | ||
34 | + PRIVATE, | ||
35 | + PUBLIC, | ||
36 | + MANAGEMENT | ||
37 | + } | ||
38 | + | ||
39 | + public enum ServiceType { | ||
40 | + VSG, | ||
41 | + OLT_AGENT, | ||
42 | + DUMMY | ||
43 | + } | ||
44 | + | ||
45 | + private final VtnServiceId id; | ||
46 | + private final String name; | ||
47 | + private final ServiceType serviceType; | ||
48 | + private final NetworkType networkType; | ||
49 | + private final long vni; | ||
50 | + private final IpPrefix subnet; | ||
51 | + private final IpAddress serviceIp; | ||
52 | + private final Set<VtnServiceId> providerServices; | ||
53 | + private final Set<VtnServiceId> tenantServices; | ||
54 | + | ||
55 | + /** | ||
56 | + * Creates a new VTN service with the specified entities. | ||
57 | + * | ||
58 | + * @param id service id | ||
59 | + * @param name user friendly name | ||
60 | + * @param serviceType service type | ||
61 | + * @param networkType network type | ||
62 | + * @param vni vni of this service network | ||
63 | + * @param subnet service network subnet range | ||
64 | + * @param serviceIp service ip for indirect service access | ||
65 | + * @param providerServices provider services | ||
66 | + * @param tenantServices tenant services | ||
67 | + */ | ||
68 | + public VtnService(VtnServiceId id, | ||
69 | + String name, | ||
70 | + ServiceType serviceType, | ||
71 | + NetworkType networkType, | ||
72 | + long vni, | ||
73 | + IpPrefix subnet, | ||
74 | + IpAddress serviceIp, | ||
75 | + Set<VtnServiceId> providerServices, | ||
76 | + Set<VtnServiceId> tenantServices) { | ||
77 | + this.id = checkNotNull(id); | ||
78 | + this.name = name; | ||
79 | + this.serviceType = serviceType; | ||
80 | + this.networkType = networkType; | ||
81 | + this.vni = vni; | ||
82 | + this.subnet = checkNotNull(subnet); | ||
83 | + this.serviceIp = checkNotNull(serviceIp); | ||
84 | + this.providerServices = providerServices == null ? Sets.newHashSet() : providerServices; | ||
85 | + this.tenantServices = tenantServices == null ? Sets.newHashSet() : tenantServices; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Returns service ID. | ||
90 | + * | ||
91 | + * @return service id | ||
92 | + */ | ||
93 | + public VtnServiceId id() { | ||
94 | + return id; | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Returns service name. | ||
99 | + * | ||
100 | + * @return name | ||
101 | + */ | ||
102 | + public String name() { | ||
103 | + return name; | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Returns service type. | ||
108 | + * | ||
109 | + * @return service type | ||
110 | + */ | ||
111 | + public ServiceType serviceType() { | ||
112 | + return serviceType; | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Returns segmentation ID of this service. | ||
117 | + * | ||
118 | + * @return segmentation id | ||
119 | + */ | ||
120 | + public long vni() { | ||
121 | + return vni; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Returns network type. | ||
126 | + * | ||
127 | + * @return network type | ||
128 | + */ | ||
129 | + public NetworkType networkType() { | ||
130 | + return networkType; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Returns service IP range. | ||
135 | + * | ||
136 | + * @return subnet cidr | ||
137 | + */ | ||
138 | + public IpPrefix subnet() { | ||
139 | + return subnet; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Returns service IP address. | ||
144 | + * | ||
145 | + * @return ip address | ||
146 | + */ | ||
147 | + public IpAddress serviceIp() { | ||
148 | + return serviceIp; | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Returns provider service IDs. | ||
153 | + * | ||
154 | + * @return list of provider service id | ||
155 | + */ | ||
156 | + public Set<VtnServiceId> providerServices() { | ||
157 | + return providerServices; | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Returns tenant service IDs. | ||
162 | + * | ||
163 | + * @return list of tenant service id | ||
164 | + */ | ||
165 | + public Set<VtnServiceId> tenantServices() { | ||
166 | + return tenantServices; | ||
167 | + } | ||
168 | + | ||
169 | + @Override | ||
170 | + public int hashCode() { | ||
171 | + return Objects.hash(id); | ||
172 | + } | ||
173 | + | ||
174 | + @Override | ||
175 | + public boolean equals(Object obj) { | ||
176 | + if (this == obj) { | ||
177 | + return true; | ||
178 | + } | ||
179 | + if (!(obj instanceof VtnService)) { | ||
180 | + return false; | ||
181 | + } | ||
182 | + final VtnService other = (VtnService) obj; | ||
183 | + return Objects.equals(this.id, other.id); | ||
184 | + } | ||
185 | + | ||
186 | + @Override | ||
187 | + public String toString() { | ||
188 | + return MoreObjects.toStringHelper(this) | ||
189 | + .add("id", id) | ||
190 | + .add("name", name) | ||
191 | + .add("serviceType", serviceType) | ||
192 | + .add("networkType", networkType) | ||
193 | + .add("vni", vni) | ||
194 | + .add("subnet", subnet) | ||
195 | + .add("serviceIp", serviceIp) | ||
196 | + .add("providerServices", providerServices) | ||
197 | + .add("tenantServices", tenantServices) | ||
198 | + .toString(); | ||
199 | + } | ||
200 | +} |
... | @@ -27,21 +27,29 @@ public interface VtnServiceApi { | ... | @@ -27,21 +27,29 @@ public interface VtnServiceApi { |
27 | * | 27 | * |
28 | * @return service list | 28 | * @return service list |
29 | */ | 29 | */ |
30 | - Set<String> services(); | 30 | + Set<VtnServiceId> services(); |
31 | + | ||
32 | + /** | ||
33 | + * Returns VTN service. | ||
34 | + * | ||
35 | + * @param serviceId service id | ||
36 | + * @return vtn service | ||
37 | + */ | ||
38 | + VtnService service(VtnServiceId serviceId); | ||
31 | 39 | ||
32 | /** | 40 | /** |
33 | * Returns dependent tenant services of a given provider service. | 41 | * Returns dependent tenant services of a given provider service. |
34 | * | 42 | * |
35 | - * @param pServiceId service id | 43 | + * @param pServiceId vtn service id |
36 | - * @return service list | 44 | + * @return set of service ids |
37 | */ | 45 | */ |
38 | - Set<String> getTenantServices(String pServiceId); | 46 | + Set<VtnServiceId> tenantServices(VtnServiceId pServiceId); |
39 | 47 | ||
40 | /** | 48 | /** |
41 | * Returns dependent provider services of a given tenant service. | 49 | * Returns dependent provider services of a given tenant service. |
42 | * | 50 | * |
43 | - * @param tServiceId service id | 51 | + * @param tServiceId vtn service id |
44 | - * @return set of services | 52 | + * @return set of service ids |
45 | */ | 53 | */ |
46 | - Set<String> getProviderServices(String tServiceId); | 54 | + Set<VtnServiceId> providerServices(VtnServiceId tServiceId); |
47 | } | 55 | } | ... | ... |
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.xosclient.api; | ||
17 | + | ||
18 | +import org.onlab.util.Identifier; | ||
19 | + | ||
20 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
21 | + | ||
22 | +/** | ||
23 | + * Representation of VTN service identifier. | ||
24 | + */ | ||
25 | +public final class VtnServiceId extends Identifier<String> { | ||
26 | + /** | ||
27 | + * Default constructor. | ||
28 | + * | ||
29 | + * @param id service identifier | ||
30 | + */ | ||
31 | + private VtnServiceId(String id) { | ||
32 | + super(id); | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Returns the VtnServiceId with value. | ||
37 | + * | ||
38 | + * @param id service id | ||
39 | + * @return CordServiceId | ||
40 | + */ | ||
41 | + public static VtnServiceId of(String id) { | ||
42 | + checkNotNull(id); | ||
43 | + return new VtnServiceId(id); | ||
44 | + } | ||
45 | +} |
... | @@ -28,19 +28,26 @@ public interface XosClientService { | ... | @@ -28,19 +28,26 @@ public interface XosClientService { |
28 | XosAccess access(); | 28 | XosAccess access(); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Sets the XOS API access information to the client service. | 31 | + * Returns XOS client with access. |
32 | * | 32 | * |
33 | * @param xosAccess xos access information | 33 | * @param xosAccess xos access information |
34 | - * @return true if it is set and authenticated, otherwise false | 34 | + * @return xos client; null if access fails authentication |
35 | */ | 35 | */ |
36 | - boolean setAccess(XosAccess xosAccess); | 36 | + XosClientService getClient(XosAccess xosAccess); |
37 | 37 | ||
38 | /** | 38 | /** |
39 | - * Returns CORD VTN service API. | 39 | + * Returns CORD VTN service and service dependency API. |
40 | * | 40 | * |
41 | * @return cord vtn service api | 41 | * @return cord vtn service api |
42 | */ | 42 | */ |
43 | - VtnServiceApi vtnServiceApi(); | 43 | + VtnServiceApi vtnService(); |
44 | + | ||
45 | + /** | ||
46 | + * Returns CORD VTN port API. | ||
47 | + * | ||
48 | + * @return cord vtn port api | ||
49 | + */ | ||
50 | + VtnPortApi vtnPort(); | ||
44 | 51 | ||
45 | /* | 52 | /* |
46 | * adds more XOS service APIs below. | 53 | * adds more XOS service APIs below. | ... | ... |
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.xosclient.impl; | ||
17 | + | ||
18 | +import org.onosproject.xosclient.api.VtnPort; | ||
19 | +import org.onosproject.xosclient.api.VtnPortApi; | ||
20 | +import org.onosproject.xosclient.api.VtnPortId; | ||
21 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
22 | +import org.onosproject.xosclient.api.XosAccess; | ||
23 | + | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +/** | ||
27 | + * Provides CORD VTN port APIs. | ||
28 | + */ | ||
29 | +public class DefaultVtnPortApi extends XosApi implements VtnPortApi { | ||
30 | + | ||
31 | + /** | ||
32 | + * Default constructor. | ||
33 | + * | ||
34 | + * @param baseUrl base url | ||
35 | + * @param access xos access | ||
36 | + */ | ||
37 | + public DefaultVtnPortApi(String baseUrl, XosAccess access) { | ||
38 | + super(baseUrl, access); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public Set<VtnPort> vtnPorts() { | ||
43 | + // TODO implement this when XOS provides this information | ||
44 | + return null; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public Set<VtnPort> vtnPorts(VtnServiceId serviceId) { | ||
49 | + // TODO implement this when XOS provides this information | ||
50 | + return null; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public VtnPort vtnPort(VtnPortId portId) { | ||
55 | + // TODO implement this when XOS provides this information | ||
56 | + return null; | ||
57 | + } | ||
58 | +} |
... | @@ -17,19 +17,18 @@ package org.onosproject.xosclient.impl; | ... | @@ -17,19 +17,18 @@ package org.onosproject.xosclient.impl; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | -import com.google.common.base.Strings; | ||
21 | import com.google.common.collect.Sets; | 20 | import com.google.common.collect.Sets; |
22 | import org.onosproject.xosclient.api.VtnServiceApi; | 21 | import org.onosproject.xosclient.api.VtnServiceApi; |
23 | import org.onosproject.xosclient.api.XosAccess; | 22 | import org.onosproject.xosclient.api.XosAccess; |
23 | +import org.onosproject.xosclient.api.VtnService; | ||
24 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
25 | + | ||
24 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
26 | 28 | ||
27 | import java.io.IOException; | 29 | import java.io.IOException; |
28 | -import java.util.Iterator; | ||
29 | -import java.util.Map; | ||
30 | import java.util.Set; | 30 | import java.util.Set; |
31 | 31 | ||
32 | -import static com.google.common.base.Preconditions.checkArgument; | ||
33 | import static com.google.common.base.Preconditions.checkNotNull; | 32 | import static com.google.common.base.Preconditions.checkNotNull; |
34 | 33 | ||
35 | /** | 34 | /** |
... | @@ -39,63 +38,52 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -39,63 +38,52 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
39 | 38 | ||
40 | private final Logger log = LoggerFactory.getLogger(getClass()); | 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
41 | 40 | ||
42 | - private static DefaultVtnServiceApi instance = null; | ||
43 | - | ||
44 | /** | 41 | /** |
45 | * Default constructor. | 42 | * Default constructor. |
46 | - */ | ||
47 | - private DefaultVtnServiceApi(String baseUrl, XosAccess access) { | ||
48 | - super(baseUrl, access); | ||
49 | - } | ||
50 | - | ||
51 | - /** | ||
52 | - * Returns VTN service API instance. Creates a new instance only if base url or | ||
53 | - * access has been changed. | ||
54 | * | 43 | * |
55 | * @param baseUrl base url | 44 | * @param baseUrl base url |
56 | - * @param access access | 45 | + * @param access xos access |
57 | - * @return vtn service api | ||
58 | */ | 46 | */ |
59 | - public static synchronized DefaultVtnServiceApi getInstance(String baseUrl, XosAccess access) { | 47 | + public DefaultVtnServiceApi(String baseUrl, XosAccess access) { |
60 | - checkNotNull(access, "XOS access information is null"); | 48 | + super(baseUrl, access); |
61 | - checkArgument(!Strings.isNullOrEmpty(baseUrl), "VTN service API base url is null or empty"); | ||
62 | - | ||
63 | - if (instance == null || | ||
64 | - !instance.baseUrl.equals(baseUrl) || | ||
65 | - !instance.access.equals(access)) { | ||
66 | - instance = new DefaultVtnServiceApi(baseUrl, access); | ||
67 | - } | ||
68 | - return instance; | ||
69 | } | 49 | } |
70 | 50 | ||
71 | @Override | 51 | @Override |
72 | - public Set<String> services() { | 52 | + public Set<VtnServiceId> services() { |
73 | String response = restGet(EMPTY_STRING); | 53 | String response = restGet(EMPTY_STRING); |
74 | log.trace("Get services {}", response); | 54 | log.trace("Get services {}", response); |
75 | 55 | ||
76 | ObjectMapper mapper = new ObjectMapper(); | 56 | ObjectMapper mapper = new ObjectMapper(); |
57 | + Set<VtnServiceId> services = Sets.newHashSet(); | ||
58 | + | ||
77 | try { | 59 | try { |
78 | JsonNode nodes = mapper.readTree(response); | 60 | JsonNode nodes = mapper.readTree(response); |
79 | - return Sets.newHashSet(nodes.fieldNames()); | 61 | + nodes.fieldNames().forEachRemaining(id -> services.add(VtnServiceId.of(id))); |
80 | } catch (IOException e) { | 62 | } catch (IOException e) { |
81 | log.warn("Failed to get service list"); | 63 | log.warn("Failed to get service list"); |
82 | - return Sets.newHashSet(); | ||
83 | } | 64 | } |
65 | + return services; | ||
84 | } | 66 | } |
85 | 67 | ||
86 | @Override | 68 | @Override |
87 | - public Set<String> getProviderServices(String tServiceId) { | 69 | + public VtnService service(VtnServiceId serviceId) { |
70 | + // TODO implement this when XOS provides this API | ||
71 | + return null; | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public Set<VtnServiceId> providerServices(VtnServiceId tServiceId) { | ||
88 | checkNotNull(tServiceId); | 76 | checkNotNull(tServiceId); |
89 | 77 | ||
90 | - String response = restGet(tServiceId); | 78 | + String response = restGet(tServiceId.id()); |
91 | log.trace("Get provider services {}", response); | 79 | log.trace("Get provider services {}", response); |
92 | 80 | ||
93 | ObjectMapper mapper = new ObjectMapper(); | 81 | ObjectMapper mapper = new ObjectMapper(); |
94 | - Set<String> pServices = Sets.newHashSet(); | 82 | + Set<VtnServiceId> pServices = Sets.newHashSet(); |
95 | 83 | ||
96 | try { | 84 | try { |
97 | JsonNode nodes = mapper.readTree(response); | 85 | JsonNode nodes = mapper.readTree(response); |
98 | - nodes.forEach(node -> pServices.add(node.asText())); | 86 | + nodes.forEach(node -> pServices.add(VtnServiceId.of(node.asText()))); |
99 | } catch (IOException e) { | 87 | } catch (IOException e) { |
100 | log.warn("Failed to get service dependency"); | 88 | log.warn("Failed to get service dependency"); |
101 | } | 89 | } |
... | @@ -103,26 +91,23 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -103,26 +91,23 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
103 | } | 91 | } |
104 | 92 | ||
105 | @Override | 93 | @Override |
106 | - public Set<String> getTenantServices(String tServiceId) { | 94 | + public Set<VtnServiceId> tenantServices(VtnServiceId tServiceId) { |
107 | checkNotNull(tServiceId); | 95 | checkNotNull(tServiceId); |
108 | 96 | ||
109 | String response = restGet(EMPTY_STRING); | 97 | String response = restGet(EMPTY_STRING); |
110 | log.trace("Get tenant services {}", response); | 98 | log.trace("Get tenant services {}", response); |
111 | 99 | ||
112 | ObjectMapper mapper = new ObjectMapper(); | 100 | ObjectMapper mapper = new ObjectMapper(); |
113 | - Set<String> tServices = Sets.newHashSet(); | 101 | + Set<VtnServiceId> tServices = Sets.newHashSet(); |
102 | + | ||
114 | try { | 103 | try { |
115 | JsonNode nodes = mapper.readTree(response); | 104 | JsonNode nodes = mapper.readTree(response); |
116 | - Iterator<Map.Entry<String, JsonNode>> iterator = nodes.fields(); | 105 | + nodes.fields().forEachRemaining(entry -> entry.getValue().forEach( |
117 | - | 106 | + pService -> { |
118 | - while (iterator.hasNext()) { | 107 | + if (pService.asText().equals(tServiceId.id())) { |
119 | - Map.Entry<String, JsonNode> entry = iterator.next(); | 108 | + tServices.add(VtnServiceId.of(entry.getKey())); |
120 | - entry.getValue().forEach(pService -> { | 109 | + } |
121 | - if (pService.asText().equals(tServiceId)) { | 110 | + })); |
122 | - tServices.add(entry.getKey()); | ||
123 | - } | ||
124 | - }); | ||
125 | - } | ||
126 | } catch (IOException e) { | 111 | } catch (IOException e) { |
127 | log.warn("Failed to get service list"); | 112 | log.warn("Failed to get service list"); |
128 | } | 113 | } | ... | ... |
... | @@ -33,6 +33,7 @@ import org.onosproject.net.config.NetworkConfigEvent; | ... | @@ -33,6 +33,7 @@ import org.onosproject.net.config.NetworkConfigEvent; |
33 | import org.onosproject.net.config.NetworkConfigListener; | 33 | import org.onosproject.net.config.NetworkConfigListener; |
34 | import org.onosproject.net.config.NetworkConfigRegistry; | 34 | import org.onosproject.net.config.NetworkConfigRegistry; |
35 | import org.onosproject.net.config.basics.SubjectFactories; | 35 | import org.onosproject.net.config.basics.SubjectFactories; |
36 | +import org.onosproject.xosclient.api.VtnPortApi; | ||
36 | import org.onosproject.xosclient.api.VtnServiceApi; | 37 | import org.onosproject.xosclient.api.VtnServiceApi; |
37 | import org.onosproject.xosclient.api.XosAccess; | 38 | import org.onosproject.xosclient.api.XosAccess; |
38 | import org.onosproject.xosclient.api.XosAccessConfig; | 39 | import org.onosproject.xosclient.api.XosAccessConfig; |
... | @@ -41,6 +42,7 @@ import org.osgi.service.component.ComponentContext; | ... | @@ -41,6 +42,7 @@ import org.osgi.service.component.ComponentContext; |
41 | import org.slf4j.Logger; | 42 | import org.slf4j.Logger; |
42 | 43 | ||
43 | import java.util.Dictionary; | 44 | import java.util.Dictionary; |
45 | +import java.util.Objects; | ||
44 | 46 | ||
45 | import static org.slf4j.LoggerFactory.getLogger; | 47 | import static org.slf4j.LoggerFactory.getLogger; |
46 | 48 | ||
... | @@ -55,8 +57,11 @@ public class XosClient implements XosClientService { | ... | @@ -55,8 +57,11 @@ public class XosClient implements XosClientService { |
55 | 57 | ||
56 | protected final Logger log = getLogger(getClass()); | 58 | protected final Logger log = getLogger(getClass()); |
57 | 59 | ||
58 | - private static final String VTN_BASE_URL = "vtnBaseUrl"; | 60 | + private static final String VTN_SERVICE_URL = "vtnServiceBaseUrl"; |
59 | - private static final String DEFAULT_VTN_BASE_URL = "/api/service/vtn/services/"; | 61 | + private static final String DEFAULT_VTN_SERVICE_URL = "/api/service/vtn/services/"; |
62 | + | ||
63 | + private static final String VTN_PORT_URL = "vtnPortBaseUrl"; | ||
64 | + private static final String DEFAULT_VTN_PORT_URL = "/api/service/vtn/ports/"; | ||
60 | 65 | ||
61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
62 | protected CoreService coreService; | 67 | protected CoreService coreService; |
... | @@ -67,9 +72,13 @@ public class XosClient implements XosClientService { | ... | @@ -67,9 +72,13 @@ public class XosClient implements XosClientService { |
67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
68 | protected NetworkConfigRegistry configRegistry; | 73 | protected NetworkConfigRegistry configRegistry; |
69 | 74 | ||
70 | - @Property(name = VTN_BASE_URL, value = DEFAULT_VTN_BASE_URL, | 75 | + @Property(name = VTN_SERVICE_URL, value = DEFAULT_VTN_SERVICE_URL, |
71 | label = "XOS VTN service API base url") | 76 | label = "XOS VTN service API base url") |
72 | - private String vtnBaseUrl = DEFAULT_VTN_BASE_URL; | 77 | + private String vtnServiceUrl = DEFAULT_VTN_SERVICE_URL; |
78 | + | ||
79 | + @Property(name = VTN_PORT_URL, value = DEFAULT_VTN_PORT_URL, | ||
80 | + label = "XOS VTN port API base url") | ||
81 | + private String vtnPortUrl = DEFAULT_VTN_PORT_URL; | ||
73 | 82 | ||
74 | private final ConfigFactory configFactory = | 83 | private final ConfigFactory configFactory = |
75 | new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, XosAccessConfig.class, "xosclient") { | 84 | new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, XosAccessConfig.class, "xosclient") { |
... | @@ -84,6 +93,13 @@ public class XosClient implements XosClientService { | ... | @@ -84,6 +93,13 @@ public class XosClient implements XosClientService { |
84 | private ApplicationId appId; | 93 | private ApplicationId appId; |
85 | private XosAccess access = null; | 94 | private XosAccess access = null; |
86 | 95 | ||
96 | + private VtnServiceApi vtnServiceApi = null; | ||
97 | + private VtnPortApi vtnPortApi = null; | ||
98 | + | ||
99 | + /* | ||
100 | + * adds more XOS service APIs below. | ||
101 | + */ | ||
102 | + | ||
87 | @Activate | 103 | @Activate |
88 | protected void activate(ComponentContext context) { | 104 | protected void activate(ComponentContext context) { |
89 | appId = coreService.registerApplication("org.onosproject.xosclient"); | 105 | appId = coreService.registerApplication("org.onosproject.xosclient"); |
... | @@ -99,16 +115,27 @@ public class XosClient implements XosClientService { | ... | @@ -99,16 +115,27 @@ public class XosClient implements XosClientService { |
99 | 115 | ||
100 | @Deactivate | 116 | @Deactivate |
101 | protected void deactivate() { | 117 | protected void deactivate() { |
118 | + configRegistry.unregisterConfigFactory(configFactory); | ||
119 | + configRegistry.removeListener(configListener); | ||
120 | + | ||
102 | log.info("Stopped"); | 121 | log.info("Stopped"); |
103 | } | 122 | } |
104 | 123 | ||
105 | @Modified | 124 | @Modified |
106 | protected void modified(ComponentContext context) { | 125 | protected void modified(ComponentContext context) { |
107 | Dictionary<?, ?> properties = context.getProperties(); | 126 | Dictionary<?, ?> properties = context.getProperties(); |
127 | + String updatedUrl; | ||
108 | 128 | ||
109 | - String updatedUrl = Tools.get(properties, VTN_BASE_URL); | 129 | + updatedUrl = Tools.get(properties, VTN_SERVICE_URL); |
110 | - if (!Strings.isNullOrEmpty(updatedUrl)) { | 130 | + if (!Strings.isNullOrEmpty(updatedUrl) && !updatedUrl.equals(vtnServiceUrl)) { |
111 | - vtnBaseUrl = updatedUrl; | 131 | + vtnServiceUrl = updatedUrl; |
132 | + vtnServiceApi = new DefaultVtnServiceApi(vtnServiceUrl, access); | ||
133 | + } | ||
134 | + | ||
135 | + updatedUrl = Tools.get(properties, VTN_PORT_URL); | ||
136 | + if (!Strings.isNullOrEmpty(updatedUrl) && !updatedUrl.equals(vtnPortUrl)) { | ||
137 | + vtnPortUrl = updatedUrl; | ||
138 | + vtnPortApi = new DefaultVtnPortApi(vtnPortUrl, access); | ||
112 | } | 139 | } |
113 | 140 | ||
114 | log.info("Modified"); | 141 | log.info("Modified"); |
... | @@ -120,18 +147,29 @@ public class XosClient implements XosClientService { | ... | @@ -120,18 +147,29 @@ public class XosClient implements XosClientService { |
120 | } | 147 | } |
121 | 148 | ||
122 | @Override | 149 | @Override |
123 | - public synchronized boolean setAccess(XosAccess xosAccess) { | 150 | + public synchronized XosClient getClient(XosAccess access) { |
124 | - checkNotNull(xosAccess); | 151 | + checkNotNull(access); |
152 | + | ||
153 | + if (!Objects.equals(this.access, access)) { | ||
154 | + // TODO do authentication before return | ||
155 | + this.access = access; | ||
156 | + | ||
157 | + vtnServiceApi = new DefaultVtnServiceApi(vtnServiceUrl, access); | ||
158 | + vtnPortApi = new DefaultVtnPortApi(vtnPortUrl, access); | ||
159 | + } | ||
160 | + return this; | ||
161 | + } | ||
125 | 162 | ||
126 | - // TODO authentication later before using the access | 163 | + @Override |
127 | - access = xosAccess; | 164 | + public VtnServiceApi vtnService() { |
128 | - return true; | 165 | + checkNotNull(vtnServiceApi, "VtnServiceApi is null"); |
166 | + return vtnServiceApi; | ||
129 | } | 167 | } |
130 | 168 | ||
131 | @Override | 169 | @Override |
132 | - public VtnServiceApi vtnServiceApi() { | 170 | + public VtnPortApi vtnPort() { |
133 | - checkNotNull(access, "XOS API access is not set"); | 171 | + checkNotNull(vtnPortApi, "VtnPortApi is null"); |
134 | - return DefaultVtnServiceApi.getInstance(vtnBaseUrl, access); | 172 | + return vtnPortApi; |
135 | } | 173 | } |
136 | 174 | ||
137 | /* | 175 | /* |
... | @@ -144,8 +182,7 @@ public class XosClient implements XosClientService { | ... | @@ -144,8 +182,7 @@ public class XosClient implements XosClientService { |
144 | log.debug("No configuration found"); | 182 | log.debug("No configuration found"); |
145 | return; | 183 | return; |
146 | } | 184 | } |
147 | - | 185 | + getClient(config.xosAccess()); |
148 | - setAccess(config.xosAccess()); | ||
149 | } | 186 | } |
150 | 187 | ||
151 | private class InternalConfigListener implements NetworkConfigListener { | 188 | private class InternalConfigListener implements NetworkConfigListener { | ... | ... |
-
Please register or login to post a comment