Use LF as line separator
Change-Id: I2098e93a482507eebec0bca3c134d395359349d9
Showing
1 changed file
with
641 additions
and
641 deletions
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.vtn.impl; | 16 | +package org.onosproject.vtn.impl; |
17 | - | 17 | + |
18 | -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 18 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
19 | -import static org.onlab.util.Tools.groupedThreads; | 19 | +import static org.onlab.util.Tools.groupedThreads; |
20 | -import static org.slf4j.LoggerFactory.getLogger; | 20 | +import static org.slf4j.LoggerFactory.getLogger; |
21 | - | 21 | + |
22 | -import java.util.ArrayList; | 22 | +import java.util.ArrayList; |
23 | -import java.util.Collection; | 23 | +import java.util.Collection; |
24 | -import java.util.HashSet; | 24 | +import java.util.HashSet; |
25 | -import java.util.Iterator; | 25 | +import java.util.Iterator; |
26 | -import java.util.List; | 26 | +import java.util.List; |
27 | -import java.util.Set; | 27 | +import java.util.Set; |
28 | -import java.util.concurrent.ScheduledExecutorService; | 28 | +import java.util.concurrent.ScheduledExecutorService; |
29 | - | 29 | + |
30 | -import org.apache.felix.scr.annotations.Activate; | 30 | +import org.apache.felix.scr.annotations.Activate; |
31 | -import org.apache.felix.scr.annotations.Component; | 31 | +import org.apache.felix.scr.annotations.Component; |
32 | -import org.apache.felix.scr.annotations.Deactivate; | 32 | +import org.apache.felix.scr.annotations.Deactivate; |
33 | -import org.apache.felix.scr.annotations.Reference; | 33 | +import org.apache.felix.scr.annotations.Reference; |
34 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | 34 | +import org.apache.felix.scr.annotations.ReferenceCardinality; |
35 | -import org.apache.felix.scr.annotations.Service; | 35 | +import org.apache.felix.scr.annotations.Service; |
36 | -import org.onlab.packet.IpAddress; | 36 | +import org.onlab.packet.IpAddress; |
37 | -import org.onlab.packet.MacAddress; | 37 | +import org.onlab.packet.MacAddress; |
38 | -import org.onlab.util.KryoNamespace; | 38 | +import org.onlab.util.KryoNamespace; |
39 | -import org.onosproject.core.ApplicationId; | 39 | +import org.onosproject.core.ApplicationId; |
40 | -import org.onosproject.core.CoreService; | 40 | +import org.onosproject.core.CoreService; |
41 | -import org.onosproject.net.Device; | 41 | +import org.onosproject.net.Device; |
42 | -import org.onosproject.net.DeviceId; | 42 | +import org.onosproject.net.DeviceId; |
43 | -import org.onosproject.net.Host; | 43 | +import org.onosproject.net.Host; |
44 | -import org.onosproject.net.HostId; | 44 | +import org.onosproject.net.HostId; |
45 | -import org.onosproject.net.Port; | 45 | +import org.onosproject.net.Port; |
46 | -import org.onosproject.net.PortNumber; | 46 | +import org.onosproject.net.PortNumber; |
47 | -import org.onosproject.net.behaviour.BridgeConfig; | 47 | +import org.onosproject.net.behaviour.BridgeConfig; |
48 | -import org.onosproject.net.behaviour.BridgeDescription; | 48 | +import org.onosproject.net.behaviour.BridgeDescription; |
49 | -import org.onosproject.net.behaviour.BridgeName; | 49 | +import org.onosproject.net.behaviour.BridgeName; |
50 | -import org.onosproject.net.behaviour.DefaultTunnelDescription; | 50 | +import org.onosproject.net.behaviour.DefaultTunnelDescription; |
51 | -import org.onosproject.net.behaviour.IpTunnelEndPoint; | 51 | +import org.onosproject.net.behaviour.IpTunnelEndPoint; |
52 | -import org.onosproject.net.behaviour.TunnelConfig; | 52 | +import org.onosproject.net.behaviour.TunnelConfig; |
53 | -import org.onosproject.net.behaviour.TunnelDescription; | 53 | +import org.onosproject.net.behaviour.TunnelDescription; |
54 | -import org.onosproject.net.behaviour.TunnelEndPoint; | 54 | +import org.onosproject.net.behaviour.TunnelEndPoint; |
55 | -import org.onosproject.net.device.DeviceEvent; | 55 | +import org.onosproject.net.device.DeviceEvent; |
56 | -import org.onosproject.net.device.DeviceListener; | 56 | +import org.onosproject.net.device.DeviceListener; |
57 | -import org.onosproject.net.device.DeviceService; | 57 | +import org.onosproject.net.device.DeviceService; |
58 | -import org.onosproject.net.driver.DriverHandler; | 58 | +import org.onosproject.net.driver.DriverHandler; |
59 | -import org.onosproject.net.driver.DriverService; | 59 | +import org.onosproject.net.driver.DriverService; |
60 | -import org.onosproject.net.flow.DefaultTrafficSelector; | 60 | +import org.onosproject.net.flow.DefaultTrafficSelector; |
61 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | 61 | +import org.onosproject.net.flow.DefaultTrafficTreatment; |
62 | -import org.onosproject.net.flow.FlowRuleService; | 62 | +import org.onosproject.net.flow.FlowRuleService; |
63 | -import org.onosproject.net.flow.TrafficSelector; | 63 | +import org.onosproject.net.flow.TrafficSelector; |
64 | -import org.onosproject.net.flow.TrafficTreatment; | 64 | +import org.onosproject.net.flow.TrafficTreatment; |
65 | -import org.onosproject.net.flow.criteria.Criteria; | 65 | +import org.onosproject.net.flow.criteria.Criteria; |
66 | -import org.onosproject.net.flow.instructions.Instructions; | 66 | +import org.onosproject.net.flow.instructions.Instructions; |
67 | -import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 67 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
68 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | 68 | +import org.onosproject.net.flowobjective.FlowObjectiveService; |
69 | -import org.onosproject.net.flowobjective.ForwardingObjective; | 69 | +import org.onosproject.net.flowobjective.ForwardingObjective; |
70 | -import org.onosproject.net.flowobjective.ForwardingObjective.Flag; | 70 | +import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
71 | -import org.onosproject.net.flowobjective.Objective; | 71 | +import org.onosproject.net.flowobjective.Objective; |
72 | -import org.onosproject.net.host.HostEvent; | 72 | +import org.onosproject.net.host.HostEvent; |
73 | -import org.onosproject.net.host.HostListener; | 73 | +import org.onosproject.net.host.HostListener; |
74 | -import org.onosproject.net.host.HostService; | 74 | +import org.onosproject.net.host.HostService; |
75 | -import org.onosproject.store.serializers.KryoNamespaces; | 75 | +import org.onosproject.store.serializers.KryoNamespaces; |
76 | -import org.onosproject.store.service.EventuallyConsistentMap; | 76 | +import org.onosproject.store.service.EventuallyConsistentMap; |
77 | -import org.onosproject.store.service.StorageService; | 77 | +import org.onosproject.store.service.StorageService; |
78 | -import org.onosproject.store.service.WallClockTimestamp; | 78 | +import org.onosproject.store.service.WallClockTimestamp; |
79 | -import org.onosproject.vtn.VTNService; | 79 | +import org.onosproject.vtn.VTNService; |
80 | -import org.onosproject.vtnrsc.SegmentationId; | 80 | +import org.onosproject.vtnrsc.SegmentationId; |
81 | -import org.onosproject.vtnrsc.TenantNetwork; | 81 | +import org.onosproject.vtnrsc.TenantNetwork; |
82 | -import org.onosproject.vtnrsc.VirtualPort; | 82 | +import org.onosproject.vtnrsc.VirtualPort; |
83 | -import org.onosproject.vtnrsc.VirtualPortId; | 83 | +import org.onosproject.vtnrsc.VirtualPortId; |
84 | -import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; | 84 | +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
85 | -import org.onosproject.vtnrsc.virtualport.VirtualPortService; | 85 | +import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
86 | -import org.slf4j.Logger; | 86 | +import org.slf4j.Logger; |
87 | - | 87 | + |
88 | -import com.google.common.collect.Sets; | 88 | +import com.google.common.collect.Sets; |
89 | - | 89 | + |
90 | -/** | 90 | +/** |
91 | - * Provides implementation of VTNService. | 91 | + * Provides implementation of VTNService. |
92 | - */ | 92 | + */ |
93 | -@Component(immediate = true) | 93 | +@Component(immediate = true) |
94 | -@Service | 94 | +@Service |
95 | -public class VTNManager implements VTNService { | 95 | +public class VTNManager implements VTNService { |
96 | - private final Logger log = getLogger(getClass()); | 96 | + private final Logger log = getLogger(getClass()); |
97 | - | 97 | + |
98 | - private static final String APP_ID = "org.onosproject.app.vtn"; | 98 | + private static final String APP_ID = "org.onosproject.app.vtn"; |
99 | - private ScheduledExecutorService backgroundService; | 99 | + private ScheduledExecutorService backgroundService; |
100 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 100 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
101 | - protected DeviceService deviceService; | 101 | + protected DeviceService deviceService; |
102 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 102 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
103 | - protected HostService hostService; | 103 | + protected HostService hostService; |
104 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 104 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
105 | - protected FlowRuleService flowRuleService; | 105 | + protected FlowRuleService flowRuleService; |
106 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 106 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
107 | - protected CoreService coreService; | 107 | + protected CoreService coreService; |
108 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 108 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
109 | - protected StorageService storageService; | 109 | + protected StorageService storageService; |
110 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 110 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
111 | - protected TenantNetworkService tenantNetworkService; | 111 | + protected TenantNetworkService tenantNetworkService; |
112 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 112 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
113 | - protected VirtualPortService virtualPortService; | 113 | + protected VirtualPortService virtualPortService; |
114 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 114 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
115 | - protected DriverService driverService; | 115 | + protected DriverService driverService; |
116 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 116 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
117 | - protected FlowObjectiveService flowObjectiveService; | 117 | + protected FlowObjectiveService flowObjectiveService; |
118 | - private EventuallyConsistentMap<HostId, SegmentationId> binding; | 118 | + private EventuallyConsistentMap<HostId, SegmentationId> binding; |
119 | - private ApplicationId appId; | 119 | + private ApplicationId appId; |
120 | - private HostListener hostListener = new InnerHostListener(); | 120 | + private HostListener hostListener = new InnerHostListener(); |
121 | - private DeviceListener deviceListener = new InnerDeviceListener(); | 121 | + private DeviceListener deviceListener = new InnerDeviceListener(); |
122 | - private static final String IFACEID = "ifaceid"; | 122 | + private static final String IFACEID = "ifaceid"; |
123 | - private static final String PORT_HEAD = "vxlan"; | 123 | + private static final String PORT_HEAD = "vxlan"; |
124 | - private static final String DEFAULT_BRIDGE_NAME = "br-int"; | 124 | + private static final String DEFAULT_BRIDGE_NAME = "br-int"; |
125 | - private static final String CONTROLLER_IP_KEY = "ipaddress"; | 125 | + private static final String CONTROLLER_IP_KEY = "ipaddress"; |
126 | - private static final int DEFAULT_MAC_PRIORITY = 0x0000; | 126 | + private static final int DEFAULT_MAC_PRIORITY = 0x0000; |
127 | - private static final int MAC_PRIORITY = 0xffff; | 127 | + private static final int MAC_PRIORITY = 0xffff; |
128 | - private static final int DEFAULT_PORT_PRIORITY = 0x0000; | 128 | + private static final int DEFAULT_PORT_PRIORITY = 0x0000; |
129 | - private static final int PORT_PRIORITY = 0xffff; | 129 | + private static final int PORT_PRIORITY = 0xffff; |
130 | - private static final String SWITCH_CHANNEL_ID = "channelId"; | 130 | + private static final String SWITCH_CHANNEL_ID = "channelId"; |
131 | - | 131 | + |
132 | - @Activate | 132 | + @Activate |
133 | - public void activate() { | 133 | + public void activate() { |
134 | - KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | 134 | + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
135 | - .register(KryoNamespaces.API); | 135 | + .register(KryoNamespaces.API); |
136 | - appId = coreService.registerApplication(APP_ID); | 136 | + appId = coreService.registerApplication(APP_ID); |
137 | - deviceService.addListener(deviceListener); | 137 | + deviceService.addListener(deviceListener); |
138 | - hostService.addListener(hostListener); | 138 | + hostService.addListener(hostListener); |
139 | - backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn", | 139 | + backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn", |
140 | - "manager-background")); | 140 | + "manager-background")); |
141 | - binding = storageService | 141 | + binding = storageService |
142 | - .<HostId, SegmentationId>eventuallyConsistentMapBuilder() | 142 | + .<HostId, SegmentationId>eventuallyConsistentMapBuilder() |
143 | - .withName("all_tunnel").withSerializer(serializer) | 143 | + .withName("all_tunnel").withSerializer(serializer) |
144 | - .withTimestampProvider((k, v) -> new WallClockTimestamp()) | 144 | + .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
145 | - .build(); | 145 | + .build(); |
146 | - log.info("Started"); | 146 | + log.info("Started"); |
147 | - } | 147 | + } |
148 | - | 148 | + |
149 | - @Deactivate | 149 | + @Deactivate |
150 | - public void deactivate() { | 150 | + public void deactivate() { |
151 | - backgroundService.shutdown(); | 151 | + backgroundService.shutdown(); |
152 | - binding.destroy(); | 152 | + binding.destroy(); |
153 | - log.info("Stopped"); | 153 | + log.info("Stopped"); |
154 | - } | 154 | + } |
155 | - | 155 | + |
156 | - @Override | 156 | + @Override |
157 | - public void onServerDetected(Device device) { | 157 | + public void onServerDetected(Device device) { |
158 | - Iterable<Device> devices = deviceService.getAvailableDevices(); | 158 | + Iterable<Device> devices = deviceService.getAvailableDevices(); |
159 | - DriverHandler handler = driverService.createHandler(device.id()); | 159 | + DriverHandler handler = driverService.createHandler(device.id()); |
160 | - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | 160 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
161 | - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); | 161 | + bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); |
162 | - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); | 162 | + String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
163 | - IpAddress ip = IpAddress.valueOf(ipAddress); | 163 | + IpAddress ip = IpAddress.valueOf(ipAddress); |
164 | - Sets.newHashSet(devices).stream() | 164 | + Sets.newHashSet(devices).stream() |
165 | - .filter(d -> Device.Type.CONTROLLER == d.type()) | 165 | + .filter(d -> Device.Type.CONTROLLER == d.type()) |
166 | - .filter(d -> !device.id().equals(d.id())).forEach(d -> { | 166 | + .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
167 | - if (!device.id().equals(d.id()) | 167 | + if (!device.id().equals(d.id()) |
168 | - && Device.Type.CONTROLLER == d.type()) { | 168 | + && Device.Type.CONTROLLER == d.type()) { |
169 | - String ipAddress1 = d.annotations() | 169 | + String ipAddress1 = d.annotations() |
170 | - .value(CONTROLLER_IP_KEY); | 170 | + .value(CONTROLLER_IP_KEY); |
171 | - IpAddress ip1 = IpAddress.valueOf(ipAddress1); | 171 | + IpAddress ip1 = IpAddress.valueOf(ipAddress1); |
172 | - applyTunnelConfig(ip, ip1, handler); | 172 | + applyTunnelConfig(ip, ip1, handler); |
173 | - DriverHandler handler1 = driverService | 173 | + DriverHandler handler1 = driverService |
174 | - .createHandler(d.id()); | 174 | + .createHandler(d.id()); |
175 | - applyTunnelConfig(ip1, ip, handler1); | 175 | + applyTunnelConfig(ip1, ip, handler1); |
176 | - } | 176 | + } |
177 | - }); | 177 | + }); |
178 | - } | 178 | + } |
179 | - | 179 | + |
180 | - @Override | 180 | + @Override |
181 | - public void onServerVanished(Device device) { | 181 | + public void onServerVanished(Device device) { |
182 | - Iterable<Device> devices = deviceService.getAvailableDevices(); | 182 | + Iterable<Device> devices = deviceService.getAvailableDevices(); |
183 | - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); | 183 | + String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); |
184 | - IpAddress dst = IpAddress.valueOf(ipAddress); | 184 | + IpAddress dst = IpAddress.valueOf(ipAddress); |
185 | - Sets.newHashSet(devices).stream() | 185 | + Sets.newHashSet(devices).stream() |
186 | - .filter(d -> d.type() == Device.Type.CONTROLLER) | 186 | + .filter(d -> d.type() == Device.Type.CONTROLLER) |
187 | - .filter(d -> !device.id().equals(d.id())).forEach(d -> { | 187 | + .filter(d -> !device.id().equals(d.id())).forEach(d -> { |
188 | - String ipAddress1 = d.annotations() | 188 | + String ipAddress1 = d.annotations() |
189 | - .value(CONTROLLER_IP_KEY); | 189 | + .value(CONTROLLER_IP_KEY); |
190 | - DriverHandler handler = driverService.createHandler(d.id()); | 190 | + DriverHandler handler = driverService.createHandler(d.id()); |
191 | - IpAddress src = IpAddress.valueOf(ipAddress1); | 191 | + IpAddress src = IpAddress.valueOf(ipAddress1); |
192 | - removeTunnelConfig(src, dst, handler); | 192 | + removeTunnelConfig(src, dst, handler); |
193 | - }); | 193 | + }); |
194 | - } | 194 | + } |
195 | - | 195 | + |
196 | - private void applyTunnelConfig(IpAddress src, IpAddress dst, | 196 | + private void applyTunnelConfig(IpAddress src, IpAddress dst, |
197 | - DriverHandler handler) { | 197 | + DriverHandler handler) { |
198 | - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); | 198 | + TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); |
199 | - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); | 199 | + TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); |
200 | - TunnelDescription tunnel = new DefaultTunnelDescription( | 200 | + TunnelDescription tunnel = new DefaultTunnelDescription( |
201 | - tunnelAsSrc, | 201 | + tunnelAsSrc, |
202 | - tunnelAsDst, | 202 | + tunnelAsDst, |
203 | - TunnelDescription.Type.VXLAN, | 203 | + TunnelDescription.Type.VXLAN, |
204 | - null); | 204 | + null); |
205 | - TunnelConfig config = handler.behaviour(TunnelConfig.class); | 205 | + TunnelConfig config = handler.behaviour(TunnelConfig.class); |
206 | - config.createTunnel(tunnel); | 206 | + config.createTunnel(tunnel); |
207 | - } | 207 | + } |
208 | - | 208 | + |
209 | - private void removeTunnelConfig(IpAddress src, IpAddress dst, | 209 | + private void removeTunnelConfig(IpAddress src, IpAddress dst, |
210 | - DriverHandler handler) { | 210 | + DriverHandler handler) { |
211 | - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); | 211 | + TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); |
212 | - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); | 212 | + TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); |
213 | - TunnelDescription tunnel = new DefaultTunnelDescription( | 213 | + TunnelDescription tunnel = new DefaultTunnelDescription( |
214 | - tunnelAsSrc, | 214 | + tunnelAsSrc, |
215 | - tunnelAsDst, | 215 | + tunnelAsDst, |
216 | - TunnelDescription.Type.VXLAN, | 216 | + TunnelDescription.Type.VXLAN, |
217 | - null); | 217 | + null); |
218 | - TunnelConfig config = handler.behaviour(TunnelConfig.class); | 218 | + TunnelConfig config = handler.behaviour(TunnelConfig.class); |
219 | - config.removeTunnel(tunnel); | 219 | + config.removeTunnel(tunnel); |
220 | - } | 220 | + } |
221 | - | 221 | + |
222 | - @Override | 222 | + @Override |
223 | - public void onOvsDetected(Device device) { | 223 | + public void onOvsDetected(Device device) { |
224 | - programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); | 224 | + programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); |
225 | - programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); | 225 | + programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); |
226 | - Set<Host> hosts = hostService.getConnectedHosts(device.id()); | 226 | + Set<Host> hosts = hostService.getConnectedHosts(device.id()); |
227 | - hosts.forEach(h -> { | 227 | + hosts.forEach(h -> { |
228 | - String ifaceId = h.annotations().value(IFACEID); | 228 | + String ifaceId = h.annotations().value(IFACEID); |
229 | - String currentControllerIp = getControllerIpOfSwitch(device.id()); | 229 | + String currentControllerIp = getControllerIpOfSwitch(device.id()); |
230 | - VirtualPortId portId = VirtualPortId.portId(ifaceId); | 230 | + VirtualPortId portId = VirtualPortId.portId(ifaceId); |
231 | - VirtualPort port = virtualPortService.getPort(portId); | 231 | + VirtualPort port = virtualPortService.getPort(portId); |
232 | - TenantNetwork network = tenantNetworkService | 232 | + TenantNetwork network = tenantNetworkService |
233 | - .getNetwork(port.networkId()); | 233 | + .getNetwork(port.networkId()); |
234 | - String vxlanName = "vxlan-" + currentControllerIp; | 234 | + String vxlanName = "vxlan-" + currentControllerIp; |
235 | - | 235 | + |
236 | - DriverHandler handler = driverService.createHandler(device.id()); | 236 | + DriverHandler handler = driverService.createHandler(device.id()); |
237 | - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | 237 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
238 | - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | 238 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig |
239 | - .getBridges(); | 239 | + .getBridges(); |
240 | - Iterator<BridgeDescription> it = bridgeDescriptions.iterator(); | 240 | + Iterator<BridgeDescription> it = bridgeDescriptions.iterator(); |
241 | - if (it.hasNext()) { | 241 | + if (it.hasNext()) { |
242 | - BridgeDescription sw = it.next(); | 242 | + BridgeDescription sw = it.next(); |
243 | - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | 243 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
244 | - ports.stream().filter(p -> p.name().equalsIgnoreCase(vxlanName)) | 244 | + ports.stream().filter(p -> p.name().equalsIgnoreCase(vxlanName)) |
245 | - .forEach(p -> { | 245 | + .forEach(p -> { |
246 | - programTunnelOut(sw.deviceId(), network.segmentationId(), p, | 246 | + programTunnelOut(sw.deviceId(), network.segmentationId(), p, |
247 | - h.mac(), appId, Objective.Operation.ADD); | 247 | + h.mac(), appId, Objective.Operation.ADD); |
248 | - }); | 248 | + }); |
249 | - } | 249 | + } |
250 | - | 250 | + |
251 | - }); | 251 | + }); |
252 | - } | 252 | + } |
253 | - | 253 | + |
254 | - @Override | 254 | + @Override |
255 | - public void onOvsVanished(Device device) { | 255 | + public void onOvsVanished(Device device) { |
256 | - programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE); | 256 | + programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE); |
257 | - programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE); | 257 | + programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE); |
258 | - } | 258 | + } |
259 | - | 259 | + |
260 | - @Override | 260 | + @Override |
261 | - public void onHostDetected(Host host) { | 261 | + public void onHostDetected(Host host) { |
262 | - String ifaceId = host.annotations().value(IFACEID); | 262 | + String ifaceId = host.annotations().value(IFACEID); |
263 | - DeviceId deviceId = host.location().deviceId(); | 263 | + DeviceId deviceId = host.location().deviceId(); |
264 | - String currentControllerIp = getControllerIpOfSwitch(deviceId); | 264 | + String currentControllerIp = getControllerIpOfSwitch(deviceId); |
265 | - Iterable<Device> devices = deviceService.getAvailableDevices(); | 265 | + Iterable<Device> devices = deviceService.getAvailableDevices(); |
266 | - VirtualPortId portId = VirtualPortId.portId(ifaceId); | 266 | + VirtualPortId portId = VirtualPortId.portId(ifaceId); |
267 | - VirtualPort port = virtualPortService.getPort(portId); | 267 | + VirtualPort port = virtualPortService.getPort(portId); |
268 | - TenantNetwork network = tenantNetworkService | 268 | + TenantNetwork network = tenantNetworkService |
269 | - .getNetwork(port.networkId()); | 269 | + .getNetwork(port.networkId()); |
270 | - String tunnelName = "vxlan-" + currentControllerIp; | 270 | + String tunnelName = "vxlan-" + currentControllerIp; |
271 | - binding.put(host.id(), network.segmentationId()); | 271 | + binding.put(host.id(), network.segmentationId()); |
272 | - List<Port> allPorts = deviceService.getPorts(deviceId); | 272 | + List<Port> allPorts = deviceService.getPorts(deviceId); |
273 | - PortNumber inPort = host.location().port(); | 273 | + PortNumber inPort = host.location().port(); |
274 | - Set<Port> localPorts = new HashSet<>(); | 274 | + Set<Port> localPorts = new HashSet<>(); |
275 | - Set<Port> tunnelPorts = new HashSet<>(); | 275 | + Set<Port> tunnelPorts = new HashSet<>(); |
276 | - List<Port> outports = new ArrayList<>(); | 276 | + List<Port> outports = new ArrayList<>(); |
277 | - Sets.newHashSet(allPorts.iterator()).stream() | 277 | + Sets.newHashSet(allPorts.iterator()).stream() |
278 | - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | 278 | + .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
279 | - if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | 279 | + if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { |
280 | - localPorts.add(p); | 280 | + localPorts.add(p); |
281 | - } else { | 281 | + } else { |
282 | - tunnelPorts.add(p); | 282 | + tunnelPorts.add(p); |
283 | - } | 283 | + } |
284 | - outports.add(p); | 284 | + outports.add(p); |
285 | - }); | 285 | + }); |
286 | - | 286 | + |
287 | - programLocalBcastRules(deviceId, network.segmentationId(), inPort, | 287 | + programLocalBcastRules(deviceId, network.segmentationId(), inPort, |
288 | - outports, appId, Objective.Operation.ADD); | 288 | + outports, appId, Objective.Operation.ADD); |
289 | - programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), | 289 | + programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), |
290 | - appId, Objective.Operation.ADD); | 290 | + appId, Objective.Operation.ADD); |
291 | - tunnelPorts | 291 | + tunnelPorts |
292 | - .forEach(tp -> programTunnelFloodOut(deviceId, | 292 | + .forEach(tp -> programTunnelFloodOut(deviceId, |
293 | - network.segmentationId(), | 293 | + network.segmentationId(), |
294 | - tp.number(), localPorts, | 294 | + tp.number(), localPorts, |
295 | - appId, | 295 | + appId, |
296 | - Objective.Operation.ADD)); | 296 | + Objective.Operation.ADD)); |
297 | - Sets.newHashSet(devices).stream() | 297 | + Sets.newHashSet(devices).stream() |
298 | - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { | 298 | + .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { |
299 | - DriverHandler handler = driverService.createHandler(d.id()); | 299 | + DriverHandler handler = driverService.createHandler(d.id()); |
300 | - BridgeConfig bridgeConfig = handler | 300 | + BridgeConfig bridgeConfig = handler |
301 | - .behaviour(BridgeConfig.class); | 301 | + .behaviour(BridgeConfig.class); |
302 | - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | 302 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig |
303 | - .getBridges(); | 303 | + .getBridges(); |
304 | - | 304 | + |
305 | - Iterator<BridgeDescription> it = bridgeDescriptions | 305 | + Iterator<BridgeDescription> it = bridgeDescriptions |
306 | - .iterator(); | 306 | + .iterator(); |
307 | - if (it.hasNext()) { | 307 | + if (it.hasNext()) { |
308 | - BridgeDescription sw = it.next(); | 308 | + BridgeDescription sw = it.next(); |
309 | - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | 309 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
310 | - ports.stream() | 310 | + ports.stream() |
311 | - .filter(p -> p.name() | 311 | + .filter(p -> p.name() |
312 | - .equalsIgnoreCase(tunnelName)) | 312 | + .equalsIgnoreCase(tunnelName)) |
313 | - .forEach(p -> { | 313 | + .forEach(p -> { |
314 | - programTunnelOut(sw.deviceId(), | 314 | + programTunnelOut(sw.deviceId(), |
315 | - network.segmentationId(), p, | 315 | + network.segmentationId(), p, |
316 | - host.mac(), appId, | 316 | + host.mac(), appId, |
317 | - Objective.Operation.ADD); | 317 | + Objective.Operation.ADD); |
318 | - }); | 318 | + }); |
319 | - } | 319 | + } |
320 | - }); | 320 | + }); |
321 | - programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), | 321 | + programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), |
322 | - appId, Objective.Operation.ADD); | 322 | + appId, Objective.Operation.ADD); |
323 | - tunnelPorts | 323 | + tunnelPorts |
324 | - .forEach(tp -> programTunnelIn(deviceId, | 324 | + .forEach(tp -> programTunnelIn(deviceId, |
325 | - network.segmentationId(), | 325 | + network.segmentationId(), |
326 | - tp.number(), inPort, host.mac(), | 326 | + tp.number(), inPort, host.mac(), |
327 | - appId, Objective.Operation.ADD)); | 327 | + appId, Objective.Operation.ADD)); |
328 | - | 328 | + |
329 | - } | 329 | + } |
330 | - | 330 | + |
331 | - @Override | 331 | + @Override |
332 | - public void onHostVanished(Host host) { | 332 | + public void onHostVanished(Host host) { |
333 | - SegmentationId segId = binding.remove(host.id()); | 333 | + SegmentationId segId = binding.remove(host.id()); |
334 | - DeviceId deviceId = host.location().deviceId(); | 334 | + DeviceId deviceId = host.location().deviceId(); |
335 | - String currentControllerIp = getControllerIpOfSwitch(deviceId); | 335 | + String currentControllerIp = getControllerIpOfSwitch(deviceId); |
336 | - Iterable<Device> devices = deviceService.getAvailableDevices(); | 336 | + Iterable<Device> devices = deviceService.getAvailableDevices(); |
337 | - List<Port> allPorts = deviceService.getPorts(deviceId); | 337 | + List<Port> allPorts = deviceService.getPorts(deviceId); |
338 | - PortNumber inPort = host.location().port(); | 338 | + PortNumber inPort = host.location().port(); |
339 | - String vxlanName = "vxlan-" + currentControllerIp; | 339 | + String vxlanName = "vxlan-" + currentControllerIp; |
340 | - Set<Port> localPorts = new HashSet<>(); | 340 | + Set<Port> localPorts = new HashSet<>(); |
341 | - Set<Port> tunnelPorts = new HashSet<>(); | 341 | + Set<Port> tunnelPorts = new HashSet<>(); |
342 | - List<Port> outports = new ArrayList<>(); | 342 | + List<Port> outports = new ArrayList<>(); |
343 | - Sets.newHashSet(allPorts.iterator()).stream() | 343 | + Sets.newHashSet(allPorts.iterator()).stream() |
344 | - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { | 344 | + .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { |
345 | - if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { | 345 | + if (!p.annotations().value("portName").startsWith(PORT_HEAD)) { |
346 | - localPorts.add(p); | 346 | + localPorts.add(p); |
347 | - } else { | 347 | + } else { |
348 | - tunnelPorts.add(p); | 348 | + tunnelPorts.add(p); |
349 | - } | 349 | + } |
350 | - outports.add(p); | 350 | + outports.add(p); |
351 | - }); | 351 | + }); |
352 | - | 352 | + |
353 | - programLocalBcastRules(deviceId, segId, inPort, | 353 | + programLocalBcastRules(deviceId, segId, inPort, |
354 | - outports, appId, Objective.Operation.REMOVE); | 354 | + outports, appId, Objective.Operation.REMOVE); |
355 | - programLocalOut(deviceId, segId, inPort, host.mac(), | 355 | + programLocalOut(deviceId, segId, inPort, host.mac(), |
356 | - appId, Objective.Operation.REMOVE); | 356 | + appId, Objective.Operation.REMOVE); |
357 | - tunnelPorts | 357 | + tunnelPorts |
358 | - .forEach(tp -> programTunnelFloodOut(deviceId, | 358 | + .forEach(tp -> programTunnelFloodOut(deviceId, |
359 | - segId, | 359 | + segId, |
360 | - tp.number(), localPorts, | 360 | + tp.number(), localPorts, |
361 | - appId, | 361 | + appId, |
362 | - Objective.Operation.REMOVE)); | 362 | + Objective.Operation.REMOVE)); |
363 | - Sets.newHashSet(devices).stream() | 363 | + Sets.newHashSet(devices).stream() |
364 | - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { | 364 | + .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { |
365 | - DriverHandler handler = driverService.createHandler(d.id()); | 365 | + DriverHandler handler = driverService.createHandler(d.id()); |
366 | - BridgeConfig bridgeConfig = handler | 366 | + BridgeConfig bridgeConfig = handler |
367 | - .behaviour(BridgeConfig.class); | 367 | + .behaviour(BridgeConfig.class); |
368 | - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | 368 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig |
369 | - .getBridges(); | 369 | + .getBridges(); |
370 | - | 370 | + |
371 | - Iterator<BridgeDescription> it = bridgeDescriptions | 371 | + Iterator<BridgeDescription> it = bridgeDescriptions |
372 | - .iterator(); | 372 | + .iterator(); |
373 | - if (it.hasNext()) { | 373 | + if (it.hasNext()) { |
374 | - BridgeDescription sw = it.next(); | 374 | + BridgeDescription sw = it.next(); |
375 | - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); | 375 | + Set<PortNumber> ports = bridgeConfig.getPortNumbers(); |
376 | - ports.stream() | 376 | + ports.stream() |
377 | - .filter(p -> p.name() | 377 | + .filter(p -> p.name() |
378 | - .equalsIgnoreCase(vxlanName)) | 378 | + .equalsIgnoreCase(vxlanName)) |
379 | - .forEach(p -> { | 379 | + .forEach(p -> { |
380 | - programTunnelOut(sw.deviceId(), | 380 | + programTunnelOut(sw.deviceId(), |
381 | - segId, p, | 381 | + segId, p, |
382 | - host.mac(), appId, | 382 | + host.mac(), appId, |
383 | - Objective.Operation.REMOVE); | 383 | + Objective.Operation.REMOVE); |
384 | - }); | 384 | + }); |
385 | - } | 385 | + } |
386 | - }); | 386 | + }); |
387 | - programLocalIn(deviceId, segId, inPort, host.mac(), | 387 | + programLocalIn(deviceId, segId, inPort, host.mac(), |
388 | - appId, Objective.Operation.REMOVE); | 388 | + appId, Objective.Operation.REMOVE); |
389 | - tunnelPorts | 389 | + tunnelPorts |
390 | - .forEach(tp -> programTunnelIn(deviceId, | 390 | + .forEach(tp -> programTunnelIn(deviceId, |
391 | - segId, | 391 | + segId, |
392 | - tp.number(), inPort, host.mac(), | 392 | + tp.number(), inPort, host.mac(), |
393 | - appId, Objective.Operation.REMOVE)); | 393 | + appId, Objective.Operation.REMOVE)); |
394 | - } | 394 | + } |
395 | - | 395 | + |
396 | - private class InnerDeviceListener implements DeviceListener { | 396 | + private class InnerDeviceListener implements DeviceListener { |
397 | - | 397 | + |
398 | - @Override | 398 | + @Override |
399 | - public void event(DeviceEvent event) { | 399 | + public void event(DeviceEvent event) { |
400 | - Device device = event.subject(); | 400 | + Device device = event.subject(); |
401 | - if (Device.Type.CONTROLLER == device.type() | 401 | + if (Device.Type.CONTROLLER == device.type() |
402 | - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { | 402 | + && DeviceEvent.Type.DEVICE_ADDED == event.type()) { |
403 | - backgroundService.execute(() -> { | 403 | + backgroundService.execute(() -> { |
404 | - onServerDetected(device); | 404 | + onServerDetected(device); |
405 | - }); | 405 | + }); |
406 | - } else if (Device.Type.CONTROLLER == device.type() | 406 | + } else if (Device.Type.CONTROLLER == device.type() |
407 | - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event | 407 | + && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event |
408 | - .type()) { | 408 | + .type()) { |
409 | - backgroundService.execute(() -> { | 409 | + backgroundService.execute(() -> { |
410 | - onServerVanished(device); | 410 | + onServerVanished(device); |
411 | - }); | 411 | + }); |
412 | - } else if (Device.Type.SWITCH == device.type() | 412 | + } else if (Device.Type.SWITCH == device.type() |
413 | - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { | 413 | + && DeviceEvent.Type.DEVICE_ADDED == event.type()) { |
414 | - backgroundService.execute(() -> { | 414 | + backgroundService.execute(() -> { |
415 | - onOvsDetected(device); | 415 | + onOvsDetected(device); |
416 | - }); | 416 | + }); |
417 | - } else if (Device.Type.SWITCH == device.type() | 417 | + } else if (Device.Type.SWITCH == device.type() |
418 | - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event | 418 | + && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event |
419 | - .type()) { | 419 | + .type()) { |
420 | - backgroundService.execute(() -> { | 420 | + backgroundService.execute(() -> { |
421 | - onOvsVanished(device); | 421 | + onOvsVanished(device); |
422 | - }); | 422 | + }); |
423 | - } else { | 423 | + } else { |
424 | - log.info("Do nothing for this device type"); | 424 | + log.info("Do nothing for this device type"); |
425 | - } | 425 | + } |
426 | - } | 426 | + } |
427 | - | 427 | + |
428 | - } | 428 | + } |
429 | - | 429 | + |
430 | - private class InnerHostListener implements HostListener { | 430 | + private class InnerHostListener implements HostListener { |
431 | - | 431 | + |
432 | - @Override | 432 | + @Override |
433 | - public void event(HostEvent event) { | 433 | + public void event(HostEvent event) { |
434 | - Host host = event.subject(); | 434 | + Host host = event.subject(); |
435 | - if (HostEvent.Type.HOST_ADDED == event.type()) { | 435 | + if (HostEvent.Type.HOST_ADDED == event.type()) { |
436 | - backgroundService.execute(() -> { | 436 | + backgroundService.execute(() -> { |
437 | - onHostDetected(host); | 437 | + onHostDetected(host); |
438 | - }); | 438 | + }); |
439 | - } else if (HostEvent.Type.HOST_REMOVED == event.type()) { | 439 | + } else if (HostEvent.Type.HOST_REMOVED == event.type()) { |
440 | - backgroundService.execute(() -> { | 440 | + backgroundService.execute(() -> { |
441 | - onHostVanished(host); | 441 | + onHostVanished(host); |
442 | - }); | 442 | + }); |
443 | - } else if (HostEvent.Type.HOST_UPDATED == event.type()) { | 443 | + } else if (HostEvent.Type.HOST_UPDATED == event.type()) { |
444 | - backgroundService.execute(() -> { | 444 | + backgroundService.execute(() -> { |
445 | - onHostVanished(host); | 445 | + onHostVanished(host); |
446 | - onHostDetected(host); | 446 | + onHostDetected(host); |
447 | - }); | 447 | + }); |
448 | - } | 448 | + } |
449 | - } | 449 | + } |
450 | - | 450 | + |
451 | - } | 451 | + } |
452 | - | 452 | + |
453 | - // Used to forward the flows to the local VM. | 453 | + // Used to forward the flows to the local VM. |
454 | - private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, | 454 | + private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, |
455 | - PortNumber outPort, MacAddress sourceMac, | 455 | + PortNumber outPort, MacAddress sourceMac, |
456 | - ApplicationId appid, | 456 | + ApplicationId appid, |
457 | - Objective.Operation type) { | 457 | + Objective.Operation type) { |
458 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 458 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
459 | - .matchEthDst(sourceMac).build(); | 459 | + .matchEthDst(sourceMac).build(); |
460 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 460 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
461 | - .add(Instructions | 461 | + .add(Instructions |
462 | - .modTunnelId(Long.parseLong(segmentationId.toString()))) | 462 | + .modTunnelId(Long.parseLong(segmentationId.toString()))) |
463 | - .setOutput(outPort).build(); | 463 | + .setOutput(outPort).build(); |
464 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 464 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
465 | - .builder().withTreatment(treatment).withSelector(selector) | 465 | + .builder().withTreatment(treatment).withSelector(selector) |
466 | - .fromApp(appId).withFlag(Flag.SPECIFIC) | 466 | + .fromApp(appId).withFlag(Flag.SPECIFIC) |
467 | - .withPriority(MAC_PRIORITY); | 467 | + .withPriority(MAC_PRIORITY); |
468 | - if (type.equals(Objective.Operation.ADD)) { | 468 | + if (type.equals(Objective.Operation.ADD)) { |
469 | - flowObjectiveService.forward(dpid, objective.add()); | 469 | + flowObjectiveService.forward(dpid, objective.add()); |
470 | - } else { | 470 | + } else { |
471 | - flowObjectiveService.forward(dpid, objective.remove()); | 471 | + flowObjectiveService.forward(dpid, objective.remove()); |
472 | - } | 472 | + } |
473 | - | 473 | + |
474 | - } | 474 | + } |
475 | - | 475 | + |
476 | - // Used to forward the flows into the VXLAN tunnel. | 476 | + // Used to forward the flows into the VXLAN tunnel. |
477 | - private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, | 477 | + private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, |
478 | - PortNumber tunnelOutPort, MacAddress dstMac, | 478 | + PortNumber tunnelOutPort, MacAddress dstMac, |
479 | - ApplicationId appid, | 479 | + ApplicationId appid, |
480 | - Objective.Operation type) { | 480 | + Objective.Operation type) { |
481 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 481 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
482 | - .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long | 482 | + .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long |
483 | - .parseLong(segmentationId.toString()))) | 483 | + .parseLong(segmentationId.toString()))) |
484 | - .build(); | 484 | + .build(); |
485 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 485 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
486 | - | 486 | + |
487 | - .setOutput(tunnelOutPort).build(); | 487 | + .setOutput(tunnelOutPort).build(); |
488 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 488 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
489 | - .builder().withTreatment(treatment).withSelector(selector) | 489 | + .builder().withTreatment(treatment).withSelector(selector) |
490 | - .fromApp(appId).withFlag(Flag.SPECIFIC) | 490 | + .fromApp(appId).withFlag(Flag.SPECIFIC) |
491 | - .withPriority(MAC_PRIORITY); | 491 | + .withPriority(MAC_PRIORITY); |
492 | - if (type.equals(Objective.Operation.ADD)) { | 492 | + if (type.equals(Objective.Operation.ADD)) { |
493 | - flowObjectiveService.forward(dpid, objective.add()); | 493 | + flowObjectiveService.forward(dpid, objective.add()); |
494 | - } else { | 494 | + } else { |
495 | - flowObjectiveService.forward(dpid, objective.remove()); | 495 | + flowObjectiveService.forward(dpid, objective.remove()); |
496 | - } | 496 | + } |
497 | - | 497 | + |
498 | - } | 498 | + } |
499 | - | 499 | + |
500 | - // Used to forward multicast flows to remote VMs of the same tenant via | 500 | + // Used to forward multicast flows to remote VMs of the same tenant via |
501 | - // VXLAN tunnel. | 501 | + // VXLAN tunnel. |
502 | - private void programTunnelFloodOut(DeviceId dpid, | 502 | + private void programTunnelFloodOut(DeviceId dpid, |
503 | - SegmentationId segmentationId, | 503 | + SegmentationId segmentationId, |
504 | - PortNumber ofPortOut, | 504 | + PortNumber ofPortOut, |
505 | - Iterable<Port> localports, | 505 | + Iterable<Port> localports, |
506 | - ApplicationId appid, | 506 | + ApplicationId appid, |
507 | - Objective.Operation type) { | 507 | + Objective.Operation type) { |
508 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 508 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
509 | - .matchInPort(ofPortOut) | 509 | + .matchInPort(ofPortOut) |
510 | - | 510 | + |
511 | - .add(Criteria.matchTunnelId(Long.parseLong(segmentationId | 511 | + .add(Criteria.matchTunnelId(Long.parseLong(segmentationId |
512 | - .toString()))).matchEthDst(MacAddress.BROADCAST) | 512 | + .toString()))).matchEthDst(MacAddress.BROADCAST) |
513 | - .build(); | 513 | + .build(); |
514 | - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 514 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
515 | - for (Port outport : localports) { | 515 | + for (Port outport : localports) { |
516 | - treatment.setOutput(outport.number()); | 516 | + treatment.setOutput(outport.number()); |
517 | - } | 517 | + } |
518 | - | 518 | + |
519 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 519 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
520 | - .builder().withTreatment(treatment.build()) | 520 | + .builder().withTreatment(treatment.build()) |
521 | - .withSelector(selector).fromApp(appId).makePermanent() | 521 | + .withSelector(selector).fromApp(appId).makePermanent() |
522 | - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); | 522 | + .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
523 | - if (type.equals(Objective.Operation.ADD)) { | 523 | + if (type.equals(Objective.Operation.ADD)) { |
524 | - flowObjectiveService.forward(dpid, objective.add()); | 524 | + flowObjectiveService.forward(dpid, objective.add()); |
525 | - } else { | 525 | + } else { |
526 | - flowObjectiveService.forward(dpid, objective.remove()); | 526 | + flowObjectiveService.forward(dpid, objective.remove()); |
527 | - } | 527 | + } |
528 | - } | 528 | + } |
529 | - | 529 | + |
530 | - // Applies default flows to mac table. | 530 | + // Applies default flows to mac table. |
531 | - private void programMacDefaultRules(DeviceId dpid, ApplicationId appid, | 531 | + private void programMacDefaultRules(DeviceId dpid, ApplicationId appid, |
532 | - Objective.Operation type) { | 532 | + Objective.Operation type) { |
533 | - TrafficSelector selector = DefaultTrafficSelector.builder().build(); | 533 | + TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
534 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop() | 534 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop() |
535 | - .build(); | 535 | + .build(); |
536 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 536 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
537 | - .builder().withTreatment(treatment).withSelector(selector) | 537 | + .builder().withTreatment(treatment).withSelector(selector) |
538 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 538 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
539 | - .withPriority(DEFAULT_MAC_PRIORITY); | 539 | + .withPriority(DEFAULT_MAC_PRIORITY); |
540 | - if (type.equals(Objective.Operation.ADD)) { | 540 | + if (type.equals(Objective.Operation.ADD)) { |
541 | - flowObjectiveService.forward(dpid, objective.add()); | 541 | + flowObjectiveService.forward(dpid, objective.add()); |
542 | - } else { | 542 | + } else { |
543 | - flowObjectiveService.forward(dpid, objective.remove()); | 543 | + flowObjectiveService.forward(dpid, objective.remove()); |
544 | - } | 544 | + } |
545 | - } | 545 | + } |
546 | - | 546 | + |
547 | - // Used to forward the flows to the local VMs with the same tenant. | 547 | + // Used to forward the flows to the local VMs with the same tenant. |
548 | - private void programLocalBcastRules(DeviceId dpid, | 548 | + private void programLocalBcastRules(DeviceId dpid, |
549 | - SegmentationId segmentationId, | 549 | + SegmentationId segmentationId, |
550 | - PortNumber inPort, List<Port> allports, | 550 | + PortNumber inPort, List<Port> allports, |
551 | - ApplicationId appid, | 551 | + ApplicationId appid, |
552 | - Objective.Operation type) { | 552 | + Objective.Operation type) { |
553 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 553 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
554 | - .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) | 554 | + .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) |
555 | - .add(Criteria.matchTunnelId(Long | 555 | + .add(Criteria.matchTunnelId(Long |
556 | - .parseLong(segmentationId.toString()))) | 556 | + .parseLong(segmentationId.toString()))) |
557 | - .build(); | 557 | + .build(); |
558 | - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 558 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
559 | - | 559 | + |
560 | - for (Port outport : allports) { | 560 | + for (Port outport : allports) { |
561 | - if (inPort != outport.number()) { | 561 | + if (inPort != outport.number()) { |
562 | - treatment.setOutput(outport.number()); | 562 | + treatment.setOutput(outport.number()); |
563 | - } | 563 | + } |
564 | - } | 564 | + } |
565 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 565 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
566 | - .builder().withTreatment(treatment.build()) | 566 | + .builder().withTreatment(treatment.build()) |
567 | - .withSelector(selector).fromApp(appId).makePermanent() | 567 | + .withSelector(selector).fromApp(appId).makePermanent() |
568 | - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); | 568 | + .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); |
569 | - if (type.equals(Objective.Operation.ADD)) { | 569 | + if (type.equals(Objective.Operation.ADD)) { |
570 | - flowObjectiveService.forward(dpid, objective.add()); | 570 | + flowObjectiveService.forward(dpid, objective.add()); |
571 | - } else { | 571 | + } else { |
572 | - flowObjectiveService.forward(dpid, objective.remove()); | 572 | + flowObjectiveService.forward(dpid, objective.remove()); |
573 | - } | 573 | + } |
574 | - } | 574 | + } |
575 | - | 575 | + |
576 | - // Used to apply local entry flow. | 576 | + // Used to apply local entry flow. |
577 | - private void programLocalIn(DeviceId dpid, SegmentationId segmentationId, | 577 | + private void programLocalIn(DeviceId dpid, SegmentationId segmentationId, |
578 | - PortNumber inPort, MacAddress srcMac, | 578 | + PortNumber inPort, MacAddress srcMac, |
579 | - ApplicationId appid, Objective.Operation type) { | 579 | + ApplicationId appid, Objective.Operation type) { |
580 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 580 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
581 | - .matchInPort(inPort).matchEthSrc(srcMac).build(); | 581 | + .matchInPort(inPort).matchEthSrc(srcMac).build(); |
582 | - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 582 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
583 | - treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId | 583 | + treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId |
584 | - .toString()))); | 584 | + .toString()))); |
585 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 585 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
586 | - .builder().withTreatment(treatment.build()) | 586 | + .builder().withTreatment(treatment.build()) |
587 | - .withSelector(selector).fromApp(appId).makePermanent() | 587 | + .withSelector(selector).fromApp(appId).makePermanent() |
588 | - .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); | 588 | + .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); |
589 | - if (type.equals(Objective.Operation.ADD)) { | 589 | + if (type.equals(Objective.Operation.ADD)) { |
590 | - flowObjectiveService.forward(dpid, objective.add()); | 590 | + flowObjectiveService.forward(dpid, objective.add()); |
591 | - } else { | 591 | + } else { |
592 | - flowObjectiveService.forward(dpid, objective.remove()); | 592 | + flowObjectiveService.forward(dpid, objective.remove()); |
593 | - } | 593 | + } |
594 | - } | 594 | + } |
595 | - | 595 | + |
596 | - // Used to forward the flows from the egress tunnel to the VM. | 596 | + // Used to forward the flows from the egress tunnel to the VM. |
597 | - private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, | 597 | + private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, |
598 | - PortNumber tunnelInPort, PortNumber outPort, | 598 | + PortNumber tunnelInPort, PortNumber outPort, |
599 | - MacAddress sourceMac, ApplicationId appid, | 599 | + MacAddress sourceMac, ApplicationId appid, |
600 | - Objective.Operation type) { | 600 | + Objective.Operation type) { |
601 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 601 | + TrafficSelector selector = DefaultTrafficSelector.builder() |
602 | - .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long | 602 | + .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long |
603 | - .parseLong(segmentationId.toString()))) | 603 | + .parseLong(segmentationId.toString()))) |
604 | - .build(); | 604 | + .build(); |
605 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 605 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
606 | - | 606 | + |
607 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 607 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
608 | - .builder().withTreatment(treatment).withSelector(selector) | 608 | + .builder().withTreatment(treatment).withSelector(selector) |
609 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 609 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
610 | - .withPriority(PORT_PRIORITY); | 610 | + .withPriority(PORT_PRIORITY); |
611 | - if (type.equals(Objective.Operation.ADD)) { | 611 | + if (type.equals(Objective.Operation.ADD)) { |
612 | - flowObjectiveService.forward(dpid, objective.add()); | 612 | + flowObjectiveService.forward(dpid, objective.add()); |
613 | - } else { | 613 | + } else { |
614 | - flowObjectiveService.forward(dpid, objective.remove()); | 614 | + flowObjectiveService.forward(dpid, objective.remove()); |
615 | - } | 615 | + } |
616 | - } | 616 | + } |
617 | - | 617 | + |
618 | - // Applies the default flows to port table. | 618 | + // Applies the default flows to port table. |
619 | - private void programPortDefaultRules(DeviceId dpid, ApplicationId appid, | 619 | + private void programPortDefaultRules(DeviceId dpid, ApplicationId appid, |
620 | - Objective.Operation type) { | 620 | + Objective.Operation type) { |
621 | - TrafficSelector selector = DefaultTrafficSelector.builder().build(); | 621 | + TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
622 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 622 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
623 | - ForwardingObjective.Builder objective = DefaultForwardingObjective | 623 | + ForwardingObjective.Builder objective = DefaultForwardingObjective |
624 | - .builder().withTreatment(treatment).withSelector(selector) | 624 | + .builder().withTreatment(treatment).withSelector(selector) |
625 | - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) | 625 | + .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) |
626 | - .withPriority(DEFAULT_PORT_PRIORITY); | 626 | + .withPriority(DEFAULT_PORT_PRIORITY); |
627 | - if (type.equals(Objective.Operation.ADD)) { | 627 | + if (type.equals(Objective.Operation.ADD)) { |
628 | - flowObjectiveService.forward(dpid, objective.add()); | 628 | + flowObjectiveService.forward(dpid, objective.add()); |
629 | - } else { | 629 | + } else { |
630 | - flowObjectiveService.forward(dpid, objective.remove()); | 630 | + flowObjectiveService.forward(dpid, objective.remove()); |
631 | - } | 631 | + } |
632 | - } | 632 | + } |
633 | - | 633 | + |
634 | - // Used to get channelId from the device annotations. | 634 | + // Used to get channelId from the device annotations. |
635 | - private String getControllerIpOfSwitch(DeviceId deviceId) { | 635 | + private String getControllerIpOfSwitch(DeviceId deviceId) { |
636 | - Device device = deviceService.getDevice(deviceId); | 636 | + Device device = deviceService.getDevice(deviceId); |
637 | - String url = device.annotations().value(SWITCH_CHANNEL_ID); | 637 | + String url = device.annotations().value(SWITCH_CHANNEL_ID); |
638 | - return url.substring(0, url.lastIndexOf(":")); | 638 | + return url.substring(0, url.lastIndexOf(":")); |
639 | - } | 639 | + } |
640 | - | 640 | + |
641 | -} | 641 | +} | ... | ... |
-
Please register or login to post a comment