Refactored to handle service instance by service type
- Added service instance handler - Implemented dummy, vsg, and olt agent instance handler Change-Id: Id3edd5eecb1caadf0f835cb10a952100e18b283b
Showing
20 changed files
with
505 additions
and
49 deletions
... | @@ -11,6 +11,7 @@ COMPILE_DEPS = [ | ... | @@ -11,6 +11,7 @@ COMPILE_DEPS = [ |
11 | '//core/store/serializers:onos-core-serializers', | 11 | '//core/store/serializers:onos-core-serializers', |
12 | '//apps/dhcp/api:onos-apps-dhcp-api', | 12 | '//apps/dhcp/api:onos-apps-dhcp-api', |
13 | '//apps/xosclient:onos-apps-xosclient', | 13 | '//apps/xosclient:onos-apps-xosclient', |
14 | + '//apps/cordconfig:onos-apps-cordconfig', | ||
14 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', | 15 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', |
15 | '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', | 16 | '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', |
16 | ] | 17 | ] |
... | @@ -35,5 +36,5 @@ onos_app ( | ... | @@ -35,5 +36,5 @@ onos_app ( |
35 | included_bundles = BUNDLES, | 36 | included_bundles = BUNDLES, |
36 | excluded_bundles = EXCLUDED_BUNDLES, | 37 | excluded_bundles = EXCLUDED_BUNDLES, |
37 | description = 'APIs for interacting with the CORD VTN application.', | 38 | description = 'APIs for interacting with the CORD VTN application.', |
38 | - required_apps = [ 'org.onosproject.xosclient', 'org.onosproject.dhcp', 'org.onosproject.ovsdb' ], | 39 | + required_apps = [ 'org.onosproject.cord-config', 'org.onosproject.xosclient', 'org.onosproject.dhcp', 'org.onosproject.ovsdb' ], |
39 | ) | 40 | ) | ... | ... |
... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
18 | category="Traffic Steering" url="http://onosproject.org" title="CORD Virtual Tenant Network" | 18 | category="Traffic Steering" url="http://onosproject.org" title="CORD Virtual Tenant Network" |
19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | 19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" |
20 | features="${project.artifactId}" | 20 | features="${project.artifactId}" |
21 | - apps="org.onosproject.ovsdb-base,org.onosproject.dhcp,org.onosproject.xosclient"> | 21 | + apps="org.onosproject.ovsdb-base,org.onosproject.dhcp,org.onosproject.xosclient,org.onosproject.cord-config"> |
22 | <description>${project.description}</description> | 22 | <description>${project.description}</description> |
23 | <artifact>mvn:${project.groupId}/onos-app-cordvtn/${project.version}</artifact> | 23 | <artifact>mvn:${project.groupId}/onos-app-cordvtn/${project.version}</artifact> |
24 | </app> | 24 | </app> | ... | ... |
... | @@ -108,6 +108,11 @@ | ... | @@ -108,6 +108,11 @@ |
108 | <version>${project.version}</version> | 108 | <version>${project.version}</version> |
109 | </dependency> | 109 | </dependency> |
110 | <dependency> | 110 | <dependency> |
111 | + <groupId>org.onosproject</groupId> | ||
112 | + <artifactId>onos-cord-config</artifactId> | ||
113 | + <version>${project.version}</version> | ||
114 | + </dependency> | ||
115 | + <dependency> | ||
111 | <groupId>com.jcraft</groupId> | 116 | <groupId>com.jcraft</groupId> |
112 | <artifactId>jsch</artifactId> | 117 | <artifactId>jsch</artifactId> |
113 | <version>0.1.53</version> | 118 | <version>0.1.53</version> | ... | ... |
... | @@ -20,6 +20,7 @@ import com.google.common.collect.Maps; | ... | @@ -20,6 +20,7 @@ import com.google.common.collect.Maps; |
20 | import com.google.common.collect.Sets; | 20 | import com.google.common.collect.Sets; |
21 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
23 | +import org.onlab.packet.IpPrefix; | ||
23 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
24 | import org.onlab.packet.TpPort; | 25 | import org.onlab.packet.TpPort; |
25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
... | @@ -46,6 +47,7 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -46,6 +47,7 @@ public class CordVtnConfig extends Config<ApplicationId> { |
46 | public static final String GATEWAY_IP = "gatewayIp"; | 47 | public static final String GATEWAY_IP = "gatewayIp"; |
47 | public static final String GATEWAY_MAC = "gatewayMac"; | 48 | public static final String GATEWAY_MAC = "gatewayMac"; |
48 | public static final String LOCAL_MANAGEMENT_IP = "localManagementIp"; | 49 | public static final String LOCAL_MANAGEMENT_IP = "localManagementIp"; |
50 | + public static final String MANAGEMENT_IP = "managementIpRange"; | ||
49 | public static final String OVSDB_PORT = "ovsdbPort"; | 51 | public static final String OVSDB_PORT = "ovsdbPort"; |
50 | 52 | ||
51 | public static final String CORDVTN_NODES = "nodes"; | 53 | public static final String CORDVTN_NODES = "nodes"; |
... | @@ -187,6 +189,25 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -187,6 +189,25 @@ public class CordVtnConfig extends Config<ApplicationId> { |
187 | } | 189 | } |
188 | 190 | ||
189 | /** | 191 | /** |
192 | + * Returns management IP address range. | ||
193 | + * | ||
194 | + * @return management network ip prefix, or null | ||
195 | + */ | ||
196 | + public IpPrefix managementIpRange() { | ||
197 | + JsonNode jsonNode = object.get(MANAGEMENT_IP); | ||
198 | + if (jsonNode == null) { | ||
199 | + return null; | ||
200 | + } | ||
201 | + | ||
202 | + try { | ||
203 | + return IpPrefix.valueOf(jsonNode.asText()); | ||
204 | + } catch (IllegalArgumentException e) { | ||
205 | + log.error("{}:{} wrong address format", MANAGEMENT_IP, jsonNode); | ||
206 | + return null; | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
190 | * Returns XOS access information. | 211 | * Returns XOS access information. |
191 | * | 212 | * |
192 | * @return XOS access, or null | 213 | * @return XOS access, or null | ... | ... |
... | @@ -15,14 +15,8 @@ | ... | @@ -15,14 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cordvtn.api; | 16 | package org.onosproject.cordvtn.api; |
17 | 17 | ||
18 | -import org.onlab.packet.IpAddress; | ||
19 | -import org.onlab.packet.MacAddress; | ||
20 | -import org.onosproject.net.ConnectPoint; | ||
21 | -import org.onosproject.net.HostId; | ||
22 | import org.onosproject.xosclient.api.VtnServiceId; | 18 | import org.onosproject.xosclient.api.VtnServiceId; |
23 | 19 | ||
24 | -import java.util.Map; | ||
25 | - | ||
26 | /** | 20 | /** |
27 | * Service for provisioning overlay virtual networks on compute nodes. | 21 | * Service for provisioning overlay virtual networks on compute nodes. |
28 | */ | 22 | */ |
... | @@ -31,21 +25,6 @@ public interface CordVtnService { | ... | @@ -31,21 +25,6 @@ public interface CordVtnService { |
31 | String CORDVTN_APP_ID = "org.onosproject.cordvtn"; | 25 | String CORDVTN_APP_ID = "org.onosproject.cordvtn"; |
32 | 26 | ||
33 | /** | 27 | /** |
34 | - * Adds a new VM on a given node and connect point. | ||
35 | - * | ||
36 | - * @param node cordvtn node | ||
37 | - * @param connectPoint connect point | ||
38 | - */ | ||
39 | - void addServiceVm(CordVtnNode node, ConnectPoint connectPoint); | ||
40 | - | ||
41 | - /** | ||
42 | - * Removes a VM from a given node and connect point. | ||
43 | - * | ||
44 | - * @param connectPoint connect point | ||
45 | - */ | ||
46 | - void removeServiceVm(ConnectPoint connectPoint); | ||
47 | - | ||
48 | - /** | ||
49 | * Creates dependencies for a given tenant service. | 28 | * Creates dependencies for a given tenant service. |
50 | * | 29 | * |
51 | * @param tServiceId id of the service which has a dependency | 30 | * @param tServiceId id of the service which has a dependency |
... | @@ -62,14 +41,4 @@ public interface CordVtnService { | ... | @@ -62,14 +41,4 @@ public interface CordVtnService { |
62 | * @param pServiceId id of the service which provide dependency | 41 | * @param pServiceId id of the service which provide dependency |
63 | */ | 42 | */ |
64 | void removeServiceDependency(VtnServiceId tServiceId, VtnServiceId pServiceId); | 43 | void removeServiceDependency(VtnServiceId tServiceId, VtnServiceId pServiceId); |
65 | - | ||
66 | - /** | ||
67 | - * Updates virtual service gateways. | ||
68 | - * | ||
69 | - * @param vSgHost host id of vSG host | ||
70 | - * @param serviceVlan service vlan id | ||
71 | - * @param vSgs map of ip and mac address of vSGs running in this vSG host | ||
72 | - */ | ||
73 | - void updateVirtualSubscriberGateways(HostId vSgHost, String serviceVlan, | ||
74 | - Map<IpAddress, MacAddress> vSgs); | ||
75 | } | 44 | } | ... | ... |
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.cordvtn.api; | ||
17 | + | ||
18 | +import com.google.common.base.Strings; | ||
19 | +import org.onlab.packet.Ip4Address; | ||
20 | +import org.onlab.packet.MacAddress; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.Host; | ||
23 | +import org.onosproject.net.PortNumber; | ||
24 | +import org.onosproject.xosclient.api.VtnPortId; | ||
25 | +import org.onosproject.xosclient.api.VtnService; | ||
26 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
27 | + | ||
28 | +import static com.google.common.base.Preconditions.checkArgument; | ||
29 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | + | ||
31 | +/** | ||
32 | + * Provides methods to help to handle network service instance. | ||
33 | + */ | ||
34 | +public final class Instance { | ||
35 | + | ||
36 | + public static final String SERVICE_ID = "serviceId"; | ||
37 | + public static final String SERVICE_TYPE = "serviceType"; | ||
38 | + public static final String PORT_ID = "vtnPortId"; | ||
39 | + public static final String CREATE_TIME = "createTime"; | ||
40 | + public static final String NESTED_INSTANCE = "nestedInstance"; | ||
41 | + public static final String TRUE = "true"; | ||
42 | + | ||
43 | + private final Host host; | ||
44 | + | ||
45 | + /** | ||
46 | + * Default constructor. | ||
47 | + * | ||
48 | + * @param instance host object of this instance | ||
49 | + */ | ||
50 | + private Instance(Host instance) { | ||
51 | + this.host = instance; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns host object of this instance. | ||
56 | + * | ||
57 | + * @return host | ||
58 | + */ | ||
59 | + public Host host() { | ||
60 | + return this.host; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Returns new instance. | ||
65 | + * | ||
66 | + * @param host host object of this instance | ||
67 | + * @return instance | ||
68 | + */ | ||
69 | + public static Instance of(Host host) { | ||
70 | + checkNotNull(host); | ||
71 | + checkArgument(!Strings.isNullOrEmpty(host.annotations().value(SERVICE_ID))); | ||
72 | + checkArgument(!Strings.isNullOrEmpty(host.annotations().value(SERVICE_TYPE))); | ||
73 | + checkArgument(!Strings.isNullOrEmpty(host.annotations().value(PORT_ID))); | ||
74 | + checkArgument(!Strings.isNullOrEmpty(host.annotations().value(CREATE_TIME))); | ||
75 | + | ||
76 | + return new Instance(host); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Returns service ID of a given host. | ||
81 | + * | ||
82 | + * @return vtn service id | ||
83 | + */ | ||
84 | + public VtnServiceId serviceId() { | ||
85 | + String serviceId = host.annotations().value(SERVICE_ID); | ||
86 | + return VtnServiceId.of(serviceId); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns service type of a given host. | ||
91 | + * | ||
92 | + * @return vtn service type | ||
93 | + */ | ||
94 | + public VtnService.ServiceType serviceType() { | ||
95 | + String serviceType = host.annotations().value(SERVICE_TYPE); | ||
96 | + return VtnService.ServiceType.valueOf(serviceType); | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Returns port ID of a given host. | ||
101 | + * | ||
102 | + * @return vtn port id | ||
103 | + */ | ||
104 | + public VtnPortId portId() { | ||
105 | + String portId = host.annotations().value(PORT_ID); | ||
106 | + return VtnPortId.of(portId); | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Returns if the instance is nested container or not. | ||
111 | + * | ||
112 | + * @return true if it's nested container; false otherwise | ||
113 | + */ | ||
114 | + public boolean isNestedInstance() { | ||
115 | + return host.annotations().value(NESTED_INSTANCE) != null; | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Returns MAC address of this instance. | ||
120 | + * | ||
121 | + * @return mac address | ||
122 | + */ | ||
123 | + public MacAddress mac() { | ||
124 | + return host.mac(); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Returns IP address of this instance. | ||
129 | + * | ||
130 | + * @return ip address | ||
131 | + */ | ||
132 | + public Ip4Address ipAddress() { | ||
133 | + // assume all instance has only one IP address, and only IP4 is supported now | ||
134 | + return host.ipAddresses().stream().findFirst().get().getIp4Address(); | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Returns device ID of this host. | ||
139 | + * | ||
140 | + * @return device id | ||
141 | + */ | ||
142 | + public DeviceId deviceId() { | ||
143 | + return host.location().deviceId(); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Returns the port number where this host is. | ||
148 | + * | ||
149 | + * @return port number | ||
150 | + */ | ||
151 | + public PortNumber portNumber() { | ||
152 | + return host.location().port(); | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * Returns annotation value with a given key. | ||
157 | + * | ||
158 | + * @param annotationKey annotation key | ||
159 | + * @return annotation value | ||
160 | + */ | ||
161 | + public String getAnnotation(String annotationKey) { | ||
162 | + return host.annotations().value(annotationKey); | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public String toString() { | ||
167 | + return host.toString(); | ||
168 | + } | ||
169 | +} |
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.cordvtn.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Handles service instance detection and removal. | ||
20 | + */ | ||
21 | +public interface InstanceHandler { | ||
22 | + | ||
23 | + /** | ||
24 | + * Handles newly detected instance. | ||
25 | + * | ||
26 | + * @param instance instance | ||
27 | + */ | ||
28 | + void instanceDetected(Instance instance); | ||
29 | + | ||
30 | + /** | ||
31 | + * Handles removed instance. | ||
32 | + * | ||
33 | + * @param instance instance | ||
34 | + */ | ||
35 | + void instanceRemoved(Instance instance); | ||
36 | +} |
... | @@ -18,7 +18,7 @@ package org.onosproject.cordvtn.cli; | ... | @@ -18,7 +18,7 @@ package org.onosproject.cordvtn.cli; |
18 | 18 | ||
19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
20 | import org.onosproject.cli.AbstractShellCommand; | 20 | import org.onosproject.cli.AbstractShellCommand; |
21 | -import org.onosproject.cordvtn.impl.CordVtnNodeManager; | 21 | +import org.onosproject.cordvtn.impl.CordVtnPipeline; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Deletes nodes from the service. | 24 | * Deletes nodes from the service. |
... | @@ -29,8 +29,8 @@ public class CordVtnFlushRules extends AbstractShellCommand { | ... | @@ -29,8 +29,8 @@ public class CordVtnFlushRules extends AbstractShellCommand { |
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | protected void execute() { | 31 | protected void execute() { |
32 | - CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); | 32 | + CordVtnPipeline pipeline = AbstractShellCommand.get(CordVtnPipeline.class); |
33 | - nodeManager.flushRules(); | 33 | + pipeline.flushRules(); |
34 | print("Successfully flushed"); | 34 | print("Successfully flushed"); |
35 | } | 35 | } |
36 | } | 36 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -22,6 +22,7 @@ import org.onlab.packet.Ethernet; | ... | @@ -22,6 +22,7 @@ import org.onlab.packet.Ethernet; |
22 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
23 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
24 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
25 | +import org.onosproject.cordvtn.api.Instance; | ||
25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.Host; | 27 | import org.onosproject.net.Host; |
27 | import org.onosproject.net.flow.DefaultTrafficSelector; | 28 | import org.onosproject.net.flow.DefaultTrafficSelector; |
... | @@ -166,9 +167,9 @@ public class CordVtnArpProxy { | ... | @@ -166,9 +167,9 @@ public class CordVtnArpProxy { |
166 | * Emits gratuitous ARP when a gateway mac address has been changed. | 167 | * Emits gratuitous ARP when a gateway mac address has been changed. |
167 | * | 168 | * |
168 | * @param gatewayIp gateway ip address to update MAC | 169 | * @param gatewayIp gateway ip address to update MAC |
169 | - * @param hosts set of hosts to send gratuitous ARP packet | 170 | + * @param instances set of instances to send gratuitous ARP packet |
170 | */ | 171 | */ |
171 | - public void sendGratuitousArpForGateway(IpAddress gatewayIp, Set<Host> hosts) { | 172 | + public void sendGratuitousArpForGateway(IpAddress gatewayIp, Set<Instance> instances) { |
172 | MacAddress gatewayMac = gateways.get(gatewayIp.getIp4Address()); | 173 | MacAddress gatewayMac = gateways.get(gatewayIp.getIp4Address()); |
173 | if (gatewayMac == null) { | 174 | if (gatewayMac == null) { |
174 | log.debug("Gateway {} is not registered to ARP proxy", gatewayIp.toString()); | 175 | log.debug("Gateway {} is not registered to ARP proxy", gatewayIp.toString()); |
... | @@ -176,13 +177,13 @@ public class CordVtnArpProxy { | ... | @@ -176,13 +177,13 @@ public class CordVtnArpProxy { |
176 | } | 177 | } |
177 | 178 | ||
178 | Ethernet ethArp = buildGratuitousArp(gatewayIp.getIp4Address(), gatewayMac); | 179 | Ethernet ethArp = buildGratuitousArp(gatewayIp.getIp4Address(), gatewayMac); |
179 | - hosts.stream().forEach(host -> { | 180 | + instances.stream().forEach(instance -> { |
180 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 181 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
181 | - .setOutput(host.location().port()) | 182 | + .setOutput(instance.portNumber()) |
182 | .build(); | 183 | .build(); |
183 | 184 | ||
184 | packetService.emit(new DefaultOutboundPacket( | 185 | packetService.emit(new DefaultOutboundPacket( |
185 | - host.location().deviceId(), | 186 | + instance.deviceId(), |
186 | treatment, | 187 | treatment, |
187 | ByteBuffer.wrap(ethArp.serialize()))); | 188 | ByteBuffer.wrap(ethArp.serialize()))); |
188 | }); | 189 | }); | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
deleted
100644 → 0
This diff is collapsed. Click to expand it.
apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/service/DummyInstanceHandler.java
0 → 100644
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.cordvtn.impl.service; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | + | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.onosproject.cordvtn.api.Instance; | ||
23 | +import org.onosproject.cordvtn.api.InstanceHandler; | ||
24 | +import org.onosproject.cordvtn.impl.CordVtnInstanceHandler; | ||
25 | +import org.onosproject.xosclient.api.VtnService; | ||
26 | + | ||
27 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
28 | +import static org.onlab.util.Tools.groupedThreads; | ||
29 | + | ||
30 | +/** | ||
31 | + * Provides network connectivity for dummy service instances. | ||
32 | + */ | ||
33 | +@Component(immediate = true) | ||
34 | +public class DummyInstanceHandler extends CordVtnInstanceHandler implements InstanceHandler { | ||
35 | + | ||
36 | + @Activate | ||
37 | + protected void activate() { | ||
38 | + serviceType = VtnService.ServiceType.DUMMY; | ||
39 | + eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/cordvtn-dummy", "event-handler")); | ||
40 | + super.activate(); | ||
41 | + } | ||
42 | + | ||
43 | + @Deactivate | ||
44 | + protected void deactivate() { | ||
45 | + super.deactivate(); | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public void instanceDetected(Instance instance) { | ||
50 | + super.instanceDetected(instance); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public void instanceRemoved(Instance instance) { | ||
55 | + super.instanceRemoved(instance); | ||
56 | + } | ||
57 | +} |
apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/service/OltAgentInstanceHandler.java
0 → 100644
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.cordvtn.impl.service; | ||
17 | + | ||
18 | +import com.google.common.collect.Maps; | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.onlab.packet.Ethernet; | ||
23 | +import org.onlab.packet.IpPrefix; | ||
24 | +import org.onosproject.cordconfig.access.AccessAgentConfig; | ||
25 | +import org.onosproject.cordconfig.access.AccessAgentData; | ||
26 | +import org.onosproject.cordvtn.api.CordVtnConfig; | ||
27 | +import org.onosproject.cordvtn.api.Instance; | ||
28 | +import org.onosproject.cordvtn.api.InstanceHandler; | ||
29 | +import org.onosproject.cordvtn.impl.CordVtnInstanceHandler; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.PortNumber; | ||
32 | +import org.onosproject.net.config.ConfigFactory; | ||
33 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
34 | +import org.onosproject.net.config.NetworkConfigListener; | ||
35 | +import org.onosproject.net.config.basics.SubjectFactories; | ||
36 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
37 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
38 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
39 | +import org.onosproject.net.flow.FlowRule; | ||
40 | +import org.onosproject.net.flow.TrafficSelector; | ||
41 | +import org.onosproject.net.flow.TrafficTreatment; | ||
42 | +import org.onosproject.xosclient.api.VtnService; | ||
43 | + | ||
44 | +import java.util.Map; | ||
45 | +import java.util.Set; | ||
46 | + | ||
47 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
48 | +import static org.onlab.util.Tools.groupedThreads; | ||
49 | +import static org.onosproject.cordvtn.impl.CordVtnPipeline.PRIORITY_MANAGEMENT; | ||
50 | +import static org.onosproject.cordvtn.impl.CordVtnPipeline.TABLE_ACCESS_TYPE; | ||
51 | + | ||
52 | +/** | ||
53 | + * Provides network connectivity for OLT agent instances. | ||
54 | + */ | ||
55 | +@Component(immediate = true) | ||
56 | +public class OltAgentInstanceHandler extends CordVtnInstanceHandler implements InstanceHandler { | ||
57 | + | ||
58 | + private static final Class<AccessAgentConfig> CONFIG_CLASS = AccessAgentConfig.class; | ||
59 | + private ConfigFactory<DeviceId, AccessAgentConfig> configFactory = | ||
60 | + new ConfigFactory<DeviceId, AccessAgentConfig>( | ||
61 | + SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessAgent") { | ||
62 | + @Override | ||
63 | + public AccessAgentConfig createConfig() { | ||
64 | + return new AccessAgentConfig(); | ||
65 | + } | ||
66 | + }; | ||
67 | + | ||
68 | + private Map<DeviceId, AccessAgentData> oltAgentData = Maps.newConcurrentMap(); | ||
69 | + private IpPrefix mgmtIpRange = null; | ||
70 | + | ||
71 | + @Activate | ||
72 | + protected void activate() { | ||
73 | + eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/cordvtn-olt", "event-handler")); | ||
74 | + serviceType = VtnService.ServiceType.OLT_AGENT; | ||
75 | + | ||
76 | + configRegistry.registerConfigFactory(configFactory); | ||
77 | + configListener = new InternalConfigListener(); | ||
78 | + | ||
79 | + super.activate(); | ||
80 | + } | ||
81 | + | ||
82 | + @Deactivate | ||
83 | + protected void deactivate() { | ||
84 | + super.deactivate(); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public void instanceDetected(Instance instance) { | ||
89 | + log.info("OLT agent instance detected {}", instance); | ||
90 | + | ||
91 | + managementAccessRule(instance.deviceId(), true); | ||
92 | + // TODO implement | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public void instanceRemoved(Instance instance) { | ||
97 | + log.info("OLT agent instance removed {}", instance); | ||
98 | + | ||
99 | + if (getInstances(instance.serviceId()).isEmpty()) { | ||
100 | + nodeManager.completeNodes().stream().forEach(node -> | ||
101 | + managementAccessRule(node.intBrId(), false)); | ||
102 | + } | ||
103 | + | ||
104 | + // TODO implement | ||
105 | + } | ||
106 | + | ||
107 | + private void managementAccessRule(DeviceId deviceId, boolean install) { | ||
108 | + // TODO remove this rule after long term management network is done | ||
109 | + if (mgmtIpRange != null) { | ||
110 | + TrafficSelector selector = DefaultTrafficSelector.builder() | ||
111 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
112 | + .matchIPDst(mgmtIpRange) | ||
113 | + .build(); | ||
114 | + | ||
115 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
116 | + .setOutput(PortNumber.LOCAL) | ||
117 | + .build(); | ||
118 | + | ||
119 | + FlowRule flowRule = DefaultFlowRule.builder() | ||
120 | + .fromApp(appId) | ||
121 | + .withSelector(selector) | ||
122 | + .withTreatment(treatment) | ||
123 | + .withPriority(PRIORITY_MANAGEMENT) | ||
124 | + .forDevice(deviceId) | ||
125 | + .forTable(TABLE_ACCESS_TYPE) | ||
126 | + .makePermanent() | ||
127 | + .build(); | ||
128 | + | ||
129 | + pipeline.processFlowRule(install, flowRule); | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + private void readAccessAgentConfig() { | ||
134 | + | ||
135 | + Set<DeviceId> deviceSubjects = configRegistry.getSubjects(DeviceId.class, CONFIG_CLASS); | ||
136 | + deviceSubjects.stream().forEach(subject -> { | ||
137 | + AccessAgentConfig config = configRegistry.getConfig(subject, CONFIG_CLASS); | ||
138 | + if (config != null) { | ||
139 | + oltAgentData.put(subject, config.getAgent()); | ||
140 | + } | ||
141 | + }); | ||
142 | + } | ||
143 | + | ||
144 | + @Override | ||
145 | + protected void readConfiguration() { | ||
146 | + CordVtnConfig config = configRegistry.getConfig(appId, CordVtnConfig.class); | ||
147 | + if (config == null) { | ||
148 | + log.debug("No configuration found"); | ||
149 | + return; | ||
150 | + } | ||
151 | + | ||
152 | + osAccess = config.openstackAccess(); | ||
153 | + xosAccess = config.xosAccess(); | ||
154 | + mgmtIpRange = config.managementIpRange(); | ||
155 | + } | ||
156 | + | ||
157 | + public class InternalConfigListener implements NetworkConfigListener { | ||
158 | + | ||
159 | + @Override | ||
160 | + public void event(NetworkConfigEvent event) { | ||
161 | + | ||
162 | + switch (event.type()) { | ||
163 | + case CONFIG_UPDATED: | ||
164 | + case CONFIG_ADDED: | ||
165 | + if (event.configClass().equals(CordVtnConfig.class)) { | ||
166 | + readConfiguration(); | ||
167 | + } else if (event.configClass().equals(CONFIG_CLASS)) { | ||
168 | + readAccessAgentConfig(); | ||
169 | + } | ||
170 | + break; | ||
171 | + default: | ||
172 | + break; | ||
173 | + } | ||
174 | + } | ||
175 | + } | ||
176 | +} |
This diff is collapsed. Click to expand it.
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 | + | ||
17 | +/** | ||
18 | + * Implementation of instance handlers for various network services. | ||
19 | + */ | ||
20 | +package org.onosproject.cordvtn.impl.service; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -18,9 +18,10 @@ package org.onosproject.cordvtn.rest; | ... | @@ -18,9 +18,10 @@ package org.onosproject.cordvtn.rest; |
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.collect.Maps; | 20 | import com.google.common.collect.Maps; |
21 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
21 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
22 | import org.onlab.packet.MacAddress; | 23 | import org.onlab.packet.MacAddress; |
23 | -import org.onosproject.cordvtn.api.CordVtnService; | 24 | +import org.onosproject.cordvtn.impl.service.VsgInstanceHandler; |
24 | import org.onosproject.net.HostId; | 25 | import org.onosproject.net.HostId; |
25 | import org.onosproject.rest.AbstractWebResource; | 26 | import org.onosproject.rest.AbstractWebResource; |
26 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
... | @@ -57,7 +58,7 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { | ... | @@ -57,7 +58,7 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { |
57 | private static final String STAG_PREFIX = "stag-"; | 58 | private static final String STAG_PREFIX = "stag-"; |
58 | private static final int STAG_BEGIN_INDEX = 5; | 59 | private static final int STAG_BEGIN_INDEX = 5; |
59 | 60 | ||
60 | - private final CordVtnService service = get(CordVtnService.class); | 61 | + private final VsgInstanceHandler service = DefaultServiceDirectory.getService(VsgInstanceHandler.class); |
61 | 62 | ||
62 | @POST | 63 | @POST |
63 | @Consumes(MediaType.APPLICATION_JSON) | 64 | @Consumes(MediaType.APPLICATION_JSON) |
... | @@ -74,6 +75,7 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { | ... | @@ -74,6 +75,7 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { |
74 | public Response updatePorts(@PathParam("id") String id, InputStream input) { | 75 | public Response updatePorts(@PathParam("id") String id, InputStream input) { |
75 | log.debug(String.format(PORTS_MESSAGE, "update")); | 76 | log.debug(String.format(PORTS_MESSAGE, "update")); |
76 | 77 | ||
78 | + // TODO get vSG updates from XOS to CORD VTN service directly | ||
77 | try { | 79 | try { |
78 | ObjectMapper mapper = new ObjectMapper(); | 80 | ObjectMapper mapper = new ObjectMapper(); |
79 | JsonNode jsonNode = mapper.readTree(input).get(PORT); | 81 | JsonNode jsonNode = mapper.readTree(input).get(PORT); |
... | @@ -88,17 +90,16 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { | ... | @@ -88,17 +90,16 @@ public class NeutronMl2PortsWebResource extends AbstractWebResource { |
88 | 90 | ||
89 | // this is allowed address pairs updates | 91 | // this is allowed address pairs updates |
90 | MacAddress mac = MacAddress.valueOf(jsonNode.path(MAC_ADDRESS).asText()); | 92 | MacAddress mac = MacAddress.valueOf(jsonNode.path(MAC_ADDRESS).asText()); |
91 | - Map<IpAddress, MacAddress> vSgs = Maps.newHashMap(); | 93 | + Map<IpAddress, MacAddress> vsgInstances = Maps.newHashMap(); |
92 | jsonNode.path(ADDRESS_PAIRS).forEach(addrPair -> { | 94 | jsonNode.path(ADDRESS_PAIRS).forEach(addrPair -> { |
93 | IpAddress pairIp = IpAddress.valueOf(addrPair.path(IP_ADDERSS).asText()); | 95 | IpAddress pairIp = IpAddress.valueOf(addrPair.path(IP_ADDERSS).asText()); |
94 | MacAddress pairMac = MacAddress.valueOf(addrPair.path(MAC_ADDRESS).asText()); | 96 | MacAddress pairMac = MacAddress.valueOf(addrPair.path(MAC_ADDRESS).asText()); |
95 | - vSgs.put(pairIp, pairMac); | 97 | + vsgInstances.put(pairIp, pairMac); |
96 | }); | 98 | }); |
97 | 99 | ||
98 | - service.updateVirtualSubscriberGateways( | 100 | + service.updateVsgInstances(HostId.hostId(mac), |
99 | - HostId.hostId(mac), | 101 | + name.substring(STAG_BEGIN_INDEX), |
100 | - name.substring(STAG_BEGIN_INDEX), | 102 | + vsgInstances); |
101 | - vSgs); | ||
102 | } catch (Exception e) { | 103 | } catch (Exception e) { |
103 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); | 104 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); |
104 | } | 105 | } | ... | ... |
-
Please register or login to post a comment