2 * Copyright (C) 2013 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal, Brent Salisbury, Dave Tucker
10 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
12 import java.net.InetAddress;
13 import java.util.List;
16 import java.util.concurrent.ExecutionException;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
20 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
21 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.neutron.spi.NeutronNetwork;
25 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
26 import org.opendaylight.ovsdb.lib.notation.Row;
27 import org.opendaylight.ovsdb.lib.notation.UUID;
28 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
29 import org.opendaylight.ovsdb.openstack.netvirt.api.*;
30 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
31 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
32 import org.opendaylight.ovsdb.schema.openvswitch.Port;
33 import org.opendaylight.ovsdb.utils.mdsal.node.StringConvertor;
34 import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
77 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
81 import com.google.common.base.Optional;
82 import com.google.common.base.Preconditions;
83 import com.google.common.collect.Lists;
84 import com.google.common.collect.Maps;
85 import com.google.common.util.concurrent.CheckedFuture;
88 * Open vSwitch OpenFlow 1.3 Networking Provider for OpenStack Neutron
90 public class OF13Provider implements NetworkingProvider {
91 private static final Logger logger = LoggerFactory.getLogger(OF13Provider.class);
92 private DataBroker dataBroker;
93 private static final short TABLE_0_DEFAULT_INGRESS = 0;
94 private static final short TABLE_1_ISOLATE_TENANT = 10;
95 private static final short TABLE_2_LOCAL_FORWARD = 20;
96 private static Long groupId = 1L;
98 private volatile ConfigurationService configurationService;
99 private volatile BridgeConfigurationManager bridgeConfigurationManager;
100 private volatile TenantNetworkManager tenantNetworkManager;
101 private volatile OvsdbConfigurationService ovsdbConfigurationService;
102 private volatile OvsdbConnectionService connectionService;
103 private volatile MdsalConsumer mdsalConsumer;
104 private volatile SecurityServicesManager securityServicesManager;
105 private volatile IngressAclProvider ingressAclProvider;
106 private volatile EgressAclProvider egressAclProvider;
107 private volatile ClassifierProvider classifierProvider;
108 private volatile L2ForwardingProvider l2ForwardingProvider;
110 public static final String NAME = "OF13Provider";
112 public OF13Provider(){
117 public String getName() {
122 public boolean supportsServices() {
127 public boolean hasPerTenantTunneling() {
131 private Status getTunnelReadinessStatus (Node node, String tunnelKey) {
132 InetAddress srcTunnelEndPoint = configurationService.getTunnelEndPoint(node);
133 if (srcTunnelEndPoint == null) {
134 logger.error("Tunnel Endpoint not configured for Node {}", node);
135 return new Status(StatusCode.NOTFOUND, "Tunnel Endpoint not configured for "+ node);
138 if (!bridgeConfigurationManager.isNodeNeutronReady(node)) {
139 logger.error(node+" is not Overlay ready");
140 return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
143 if (!tenantNetworkManager.isTenantNetworkPresentInNode(node, tunnelKey)) {
144 logger.debug(node+" has no VM corresponding to segment "+ tunnelKey);
145 return new Status(StatusCode.NOTACCEPTABLE, node+" has no VM corresponding to segment "+ tunnelKey);
147 return new Status(StatusCode.SUCCESS);
150 private String getTunnelName(String tunnelType, InetAddress dst) {
151 return tunnelType+"-"+dst.getHostAddress();
154 private boolean isTunnelPresent(Node node, String tunnelName, String bridgeUUID) throws Exception {
155 /* TODO SB_MIGRATION */
156 Preconditions.checkNotNull(ovsdbConfigurationService);
157 Row bridgeRow = ovsdbConfigurationService
158 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
159 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
160 if (bridge != null) {
161 Set<UUID> ports = bridge.getPortsColumn().getData();
162 for (UUID portUUID : ports) {
163 Row portRow = ovsdbConfigurationService
164 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID.toString());
165 Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
166 if (port != null && tunnelName.equalsIgnoreCase(port.getName())) return true;
172 private String getPortUuid(Node node, String name, String bridgeUUID) throws Exception {
173 /* TODO SB_MIGRATION */
174 Preconditions.checkNotNull(ovsdbConfigurationService);
175 Row bridgeRow = ovsdbConfigurationService
176 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
177 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
178 if (bridge != null) {
179 Set<UUID> ports = bridge.getPortsColumn().getData();
180 for (UUID portUUID : ports) {
181 Row portRow = ovsdbConfigurationService
182 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID.toString());
183 Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
184 if (port != null && name.equalsIgnoreCase(port.getName())) return portUUID.toString();
190 private Status addTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst) {
191 /* TODO SB_MIGRATION */
192 Preconditions.checkNotNull(ovsdbConfigurationService);
194 String bridgeUUID = null;
195 String tunnelBridgeName = configurationService.getIntegrationBridgeName();
196 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
197 if (bridgeTable != null) {
198 for (String uuid : bridgeTable.keySet()) {
199 Bridge bridge = ovsdbConfigurationService.getTypedRow(node,Bridge.class, bridgeTable.get(uuid));
200 if (bridge.getName().equals(tunnelBridgeName)) {
206 if (bridgeUUID == null) {
207 logger.error("Could not find Bridge {} in {}", tunnelBridgeName, node);
208 return new Status(StatusCode.NOTFOUND, "Could not find "+tunnelBridgeName+" in "+node);
210 String portName = getTunnelName(tunnelType, dst);
212 if (this.isTunnelPresent(node, portName, bridgeUUID)) {
213 logger.trace("Tunnel {} is present in {} of {}", portName, tunnelBridgeName, node);
214 return new Status(StatusCode.SUCCESS);
217 Port tunnelPort = ovsdbConfigurationService.createTypedRow(node, Port.class);
218 tunnelPort.setName(portName);
219 StatusWithUuid statusWithUuid = ovsdbConfigurationService
220 .insertRow(node, ovsdbConfigurationService.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
221 if (!statusWithUuid.isSuccess()) {
222 logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
223 return statusWithUuid;
226 String tunnelPortUUID = statusWithUuid.getUuid().toString();
227 String interfaceUUID = null;
229 while ((interfaceUUID == null) && (timeout > 0)) {
230 Row portRow = ovsdbConfigurationService
231 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), tunnelPortUUID);
232 tunnelPort = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
233 Set<UUID> interfaces = tunnelPort.getInterfacesColumn().getData();
234 if (interfaces == null || interfaces.size() == 0) {
235 // Wait for the OVSDB update to sync up the Local cache.
240 interfaceUUID = interfaces.toArray()[0].toString();
241 Row intfRow = ovsdbConfigurationService
242 .getRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), interfaceUUID);
243 Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, intfRow);
244 if (intf == null) interfaceUUID = null;
247 if (interfaceUUID == null) {
248 logger.error("Cannot identify Tunnel Interface for port {}/{}", portName, tunnelPortUUID);
249 return new Status(StatusCode.INTERNALERROR);
252 Interface tunInterface = ovsdbConfigurationService.createTypedRow(node, Interface.class);
253 tunInterface.setType(tunnelType);
254 Map<String, String> options = Maps.newHashMap();
255 options.put("key", "flow");
256 options.put("local_ip", src.getHostAddress());
257 options.put("remote_ip", dst.getHostAddress());
258 tunInterface.setOptions(options);
259 Status status = ovsdbConfigurationService
260 .updateRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
261 logger.debug("Tunnel {} add status : {}", tunInterface, status);
263 } catch (Exception e) {
264 logger.error("Exception in addTunnelPort", e);
265 return new Status(StatusCode.INTERNALERROR);
269 /* delete port from ovsdb port table */
270 private Status deletePort(Node node, String bridgeName, String portName) {
271 /* TODO SB_MIGRATION */
272 Preconditions.checkNotNull(ovsdbConfigurationService);
274 String bridgeUUID = null;
275 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
276 if (bridgeTable != null) {
277 for (String uuid : bridgeTable.keySet()) {
278 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
279 if (bridge.getName().equals(bridgeName)) {
285 if (bridgeUUID == null) {
286 logger.debug("Could not find Bridge {} in {}", bridgeName, node);
287 return new Status(StatusCode.SUCCESS);
290 String portUUID = this.getPortUuid(node, portName, bridgeUUID);
291 Status status = new Status(StatusCode.SUCCESS);
292 if (portUUID != null) {
293 status = ovsdbConfigurationService
294 .deleteRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID);
295 if (!status.isSuccess()) {
296 logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
300 logger.debug("Port {} delete status : {}", portName, status);
303 } catch (Exception e) {
304 logger.error("Exception in deletePort", e);
305 return new Status(StatusCode.INTERNALERROR);
309 private Status deleteTunnelPort(Node node, String tunnelType, InetAddress src, InetAddress dst) {
310 String tunnelBridgeName = configurationService.getIntegrationBridgeName();
311 String portName = getTunnelName(tunnelType, dst);
312 return deletePort(node, tunnelBridgeName, portName);
315 private Status deletePhysicalPort(Node node, String phyIntfName) {
316 String intBridgeName = configurationService.getIntegrationBridgeName();
317 return deletePort(node, intBridgeName, phyIntfName);
320 private void programLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
324 * Match: VM sMac and Local Ingress Port
325 * Action:Action: Set Tunnel ID and GOTO Local Table (5)
328 handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, true);
333 * Match: Drop any remaining Ingress Local VM Packets
334 * Action: Drop w/ a low priority
337 handleDropSrcIface(dpid, localPort, true);
342 * Match: Match TunID and Destination DL/dMAC Addr
343 * Action: Output Port
344 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
347 handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, true);
352 * Match: Tunnel ID and dMAC (::::FF:FF)
353 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
354 * actions=output:2,3,4,5
357 handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
358 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
361 * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
366 * Match: Any remaining Ingress Local VM Packets
367 * Action: Drop w/ a low priority
368 * -------------------------------------------
369 * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
372 handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, true);
377 * Match: Any Remaining Flows w/a TunID
378 * Action: Drop w/ a low priority
379 * table=2,priority=8192,tun_id=0x5 actions=drop
382 handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, true);
385 private void removeLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
389 * Match: VM sMac and Local Ingress Port
390 * Action:Action: Set Tunnel ID and GOTO Local Table (5)
393 handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, false);
398 * Match: Drop any remaining Ingress Local VM Packets
399 * Action: Drop w/ a low priority
402 handleDropSrcIface(dpid, localPort, false);
407 * Match: Match TunID and Destination DL/dMAC Addr
408 * Action: Output Port
409 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
412 handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, false);
417 * Match: Tunnel ID and dMAC (::::FF:FF)
418 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
419 * actions=output:2,3,4,5
422 handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
423 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
426 private void programLocalIngressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
430 * Match: Ingress Port, Tunnel ID
431 * Action: GOTO Local Table (20)
434 handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
439 * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
440 * Action: Flood to selected destination TEPs
441 * -------------------------------------------
442 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
443 * actions=output:10,output:11,goto_table:2
446 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
450 private void programRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
454 * Match: Drop any remaining Ingress Local VM Packets
455 * Action: Drop w/ a low priority
456 * -------------------------------------------
457 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
458 * actions=output:11,goto_table:2
461 handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, true);
464 private void removeRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
468 * Match: Drop any remaining Ingress Local VM Packets
469 * Action: Drop w/ a low priority
470 * -------------------------------------------
471 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
472 * actions=output:11,goto_table:2
475 handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, false);
478 /* Remove tunnel rules if last node in this tenant network */
479 private void removePerTunnelRules(Node node, Long dpid, String segmentationId, long tunnelOFPort) {
481 * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
486 * Match: Any remaining Ingress Local VM Packets
487 * Action: Drop w/ a low priority
488 * -------------------------------------------
489 * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
492 handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, false);
497 * Match: Any Remaining Flows w/a TunID
498 * Action: Drop w/ a low priority
499 * table=2,priority=8192,tun_id=0x5 actions=drop
502 handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, false);
507 * Match: Ingress Port, Tunnel ID
508 * Action: GOTO Local Table (10)
511 handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
516 * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
517 * Action: Flood to selected destination TEPs
518 * -------------------------------------------
519 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
520 * actions=output:10,output:11,goto_table:2
523 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
526 private void programLocalVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
530 * Tag traffic coming from the local port and vm srcmac
531 * Match: VM sMac and Local Ingress Port
532 * Action: Set VLAN ID and GOTO Local Table 1
535 handleLocalInPortSetVlan(dpid, TABLE_0_DEFAULT_INGRESS,
536 TABLE_1_ISOLATE_TENANT, segmentationId, localPort,
542 * Drop all other traffic coming from the local port
543 * Match: Drop any remaining Ingress Local VM Packets
544 * Action: Drop w/ a low priority
547 handleDropSrcIface(dpid, localPort, true);
552 * Forward unicast traffic destined to the local port after stripping tag
553 * Match: Match VLAN ID and Destination DL/dMAC Addr
554 * Action: strip vlan, output to local port
555 * Example: table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions= strip vlan, output:2
558 handleLocalVlanUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
559 localPort, attachedMac, true);
564 * Match: VLAN ID and dMAC (::::FF:FF)
565 * Action: strip vlan, output to all local ports in this vlan
566 * Example: table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
567 * actions= strip_vlan, output:2,3,4,5
570 //handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
571 // localPort, ethPort, true);
572 //handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
573 // segmentationId, localPort, ethport, true);
578 * Match: Any Remaining Flows w/a VLAN ID
579 * Action: Drop w/ a low priority
580 * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
583 //handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
587 private void removeLocalVlanRules(Node node, Long dpid,
588 String segmentationId, String attachedMac, long localPort) {
592 * Match: VM sMac and Local Ingress Port
593 * Action: Set VLAN ID and GOTO Local Table 1
596 handleLocalInPortSetVlan(dpid, TABLE_0_DEFAULT_INGRESS,
597 TABLE_1_ISOLATE_TENANT, segmentationId, localPort,
603 * Match: Drop any remaining Ingress Local VM Packets
604 * Action: Drop w/ a low priority
607 handleDropSrcIface(dpid, localPort, false);
612 * Match: Match VLAN ID and Destination DL/dMAC Addr
613 * Action: strip vlan, output to local port
614 * Example: table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions= strip vlan, output:2
617 handleLocalVlanUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
618 localPort, attachedMac, false);
623 * Match: VLAN ID and dMAC (::::FF:FF)
624 * Action: strip vlan, output to all local ports in this vlan
625 * Example: table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
626 * actions= strip_vlan, output:2,3,4,5
629 //handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
630 // localPort, ethPort, false);
631 //handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
632 // segmentationId, localPort, false);
636 private void programLocalIngressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac,
637 long localPort, long ethPort) {
641 * Match: Ingress port = physical interface, Vlan ID
642 * Action: GOTO Local Table 2
645 handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
646 segmentationId, ethPort, true);
651 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
652 * Action: Flood to local and remote VLAN members
653 * -------------------------------------------
654 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
655 * actions=output:10 (eth port),goto_table:2
656 * table=110, priority=16384,dl_vlan=2001,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=output:2,pop_vlan,output:1,output:3,output:4
659 handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, ethPort, true);
664 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
665 * Action: Flood to local and remote VLAN members
666 * -------------------------------------------
667 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
668 * actions=output:10 (eth port),goto_table:2
671 //handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
672 // segmentationId, ethPort, true);
675 private void programRemoteEgressVlanRules(Node node, Long dpid, String segmentationId,
676 String attachedMac, long ethPort) {
680 * Match: Destination MAC is local VM MAC and vlan id
681 * Action: go to table 2
682 * -------------------------------------------
683 * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
684 * actions=goto_table:2
687 //handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
688 // segmentationId, ethPort, attachedMac, true);
694 * Action: Go to table 2
695 * -------------------------------------------
696 * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
697 * table=110,priority=8192,dl_vlan=2001 actions=output:2
700 handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, ethPort, true);
703 private void removeRemoteEgressVlanRules(Node node, Long dpid, String segmentationId,
704 String attachedMac, long localPort, long ethPort) {
708 * Match: Destination MAC is local VM MAC and vlan id
709 * Action: go to table 2
710 * -------------------------------------------
711 * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
712 * actions=goto_table:2
715 //handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
716 // segmentationId, ethPort, attachedMac, false);
721 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
722 * Action: Flood to local and remote VLAN members
723 * -------------------------------------------
724 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
725 * actions=output:10 (eth port),goto_table:2
726 * table=110, priority=16384,dl_vlan=2001,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=output:2,pop_vlan,output:1,output:3,output:4
729 handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, ethPort, false);
732 private void removePerVlanRules(Node node, Long dpid, String segmentationId, long localPort, long ethPort) {
736 * Match: Any Remaining Flows w/a VLAN ID
737 * Action: Drop w/ a low priority
738 * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
741 //handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, false);
746 * Match: Ingress port = physical interface, Vlan ID
747 * Action: GOTO Local Table 2
750 handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, ethPort, false);
755 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
756 * Action: Flood to local and remote VLAN members
757 * -------------------------------------------
758 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
759 * actions=output:10 (eth port),goto_table:2
760 * table=110, priority=16384,dl_vlan=2001,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=output:2,pop_vlan,output:1,output:3,output:4
763 //handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, ethPort, false);
768 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
769 * Action: Flood to local and remote VLAN members
770 * -------------------------------------------
771 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
772 * actions=output:10 (eth port),goto_table:2
775 //handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
776 // segmentationId, ethPort, false);
782 * Action: Go to table 2
783 * -------------------------------------------
784 * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
785 * table=110,priority=8192,dl_vlan=2001 actions=output:2
788 handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, ethPort, false);
791 private Long getDpid (Node node, String bridgeUuid) {
793 Preconditions.checkNotNull(ovsdbConfigurationService);
795 Row bridgeRow = ovsdbConfigurationService
796 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUuid);
797 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
798 Set<String> dpids = bridge.getDatapathIdColumn().getData();
799 if (dpids == null || dpids.size() == 0) return 0L;
800 return StringConvertor.dpidStringToLong((String) dpids.toArray()[0]);
801 } catch (Exception e) {
802 logger.error("Error finding Bridge's OF DPID", e);
807 private Long getIntegrationBridgeOFDPID (Node node) {
809 String bridgeName = configurationService.getIntegrationBridgeName();
810 String brIntId = this.getInternalBridgeUUID(node, bridgeName);
811 if (brIntId == null) {
812 logger.error("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
816 return getDpid(node, brIntId);
817 } catch (Exception e) {
818 logger.error("Error finding Integration Bridge's OF DPID", e);
823 private Long getExternalBridgeDpid (Node node) {
825 String bridgeName = configurationService.getExternalBridgeName();
826 String brUuid = this.getInternalBridgeUUID(node, bridgeName);
827 if (brUuid == null) {
828 // Note: it is okay for certain nodes to not have br-ex configured; not an error
829 logger.info("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
833 return getDpid(node, brUuid);
834 } catch (Exception e) {
835 logger.error("Error finding External Bridge's OF DPID", e);
840 private void programLocalRules (String networkType, String segmentationId, Node node, Interface intf) {
842 Long dpid = this.getIntegrationBridgeOFDPID(node);
844 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
848 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
849 if (of_ports == null || of_ports.size() <= 0) {
850 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
853 long localPort = (Long)of_ports.toArray()[0];
855 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
856 if (externalIds == null) {
857 logger.error("No external_ids seen in {}", intf);
861 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
862 if (attachedMac == null) {
863 logger.error("No AttachedMac seen in {}", intf);
867 /* Program local rules based on network type */
868 if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
869 logger.debug("Program local vlan rules for interface {}", intf.getName());
870 programLocalVlanRules(node, dpid, segmentationId, attachedMac, localPort);
872 /* If the network type is tunnel based (VXLAN/GRRE/etc) with Neutron Port Security ACLs */
873 if ((networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) || networkType.equalsIgnoreCase
874 (NetworkHandler.NETWORK_TYPE_VXLAN)) && securityServicesManager.isPortSecurityReady(intf)) {
875 logger.debug("Neutron port has a Port Security Group");
876 /* Retrieve the security group UUID from the Neutron Port */
877 NeutronSecurityGroup securityGroupInPort = securityServicesManager.getSecurityGroupInPort(intf);
878 logger.debug("Program Local rules for networkType: {} does contain a Port Security Group: {} " +
879 "to be installed on DPID: {}", networkType, securityGroupInPort, dpid);
880 ingressAclProvider.programPortSecurityACL(dpid, segmentationId, attachedMac, localPort,
881 securityGroupInPort);
882 egressAclProvider.programPortSecurityACL(dpid, segmentationId, attachedMac, localPort,
883 securityGroupInPort);
885 if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
886 networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
887 logger.debug("Program local bridge rules for interface {}", intf.getName());
888 programLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
890 } catch (Exception e) {
891 logger.error("Exception in programming Local Rules for "+intf+" on "+node, e);
895 private void removeLocalRules (String networkType, String segmentationId, Node node, Interface intf) {
897 Long dpid = this.getIntegrationBridgeOFDPID(node);
899 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
903 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
904 if (of_ports == null || of_ports.size() <= 0) {
905 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
908 long localPort = (Long)of_ports.toArray()[0];
910 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
911 if (externalIds == null) {
912 logger.error("No external_ids seen in {}", intf);
916 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
917 if (attachedMac == null) {
918 logger.error("No AttachedMac seen in {}", intf);
922 /* Program local rules based on network type */
923 if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
924 logger.debug("Remove local vlan rules for interface {}", intf.getName());
925 removeLocalVlanRules(node, dpid, segmentationId, attachedMac, localPort);
926 } else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
927 networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
928 logger.debug("Remove local bridge rules for interface {}", intf.getName());
929 removeLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
931 } catch (Exception e) {
932 logger.error("Exception in removing Local Rules for "+intf+" on "+node, e);
936 private void programTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
937 Interface intf, boolean local) {
938 /* TODO SB_MIGRATION */
939 Preconditions.checkNotNull(ovsdbConfigurationService);
943 Long dpid = this.getIntegrationBridgeOFDPID(node);
945 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
949 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
950 if (of_ports == null || of_ports.size() <= 0) {
951 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
954 long localPort = (Long)of_ports.toArray()[0];
956 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
957 if (externalIds == null) {
958 logger.error("No external_ids seen in {}", intf);
962 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
963 if (attachedMac == null) {
964 logger.error("No AttachedMac seen in {}", intf);
968 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
970 for (Row row : intfs.values()) {
971 Interface tunIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
972 if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
973 of_ports = tunIntf.getOpenFlowPortColumn().getData();
974 if (of_ports == null || of_ports.size() <= 0) {
975 logger.debug("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
978 long tunnelOFPort = (Long)of_ports.toArray()[0];
980 if (tunnelOFPort == -1) {
981 logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
984 logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
987 programRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
989 logger.trace("program local ingress tunnel rules: node"
990 + node.getNodeId().getValue() + " intf " + intf.getName());
992 programLocalIngressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
998 } catch (Exception e) {
1003 private void removeTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
1004 Interface intf, boolean local, boolean isLastInstanceOnNode) {
1005 /* TODO SB_MIGRATION */
1006 Preconditions.checkNotNull(ovsdbConfigurationService);
1009 Long dpid = this.getIntegrationBridgeOFDPID(node);
1011 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1015 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
1016 if (of_ports == null || of_ports.size() <= 0) {
1017 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
1020 long localPort = (Long)of_ports.toArray()[0];
1022 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
1023 if (externalIds == null) {
1024 logger.error("No external_ids seen in {}", intf);
1028 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
1029 if (attachedMac == null) {
1030 logger.error("No AttachedMac seen in {}", intf);
1034 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1035 if (intfs != null) {
1036 for (Row row : intfs.values()) {
1037 Interface tunIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1038 if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
1039 of_ports = tunIntf.getOpenFlowPortColumn().getData();
1040 if (of_ports == null || of_ports.size() <= 0) {
1041 logger.error("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
1044 long tunnelOFPort = (Long)of_ports.toArray()[0];
1046 if (tunnelOFPort == -1) {
1047 logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
1050 logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
1053 removeRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
1055 if (local && isLastInstanceOnNode) {
1056 removePerTunnelRules(node, dpid, segmentationId, tunnelOFPort);
1062 } catch (Exception e) {
1063 logger.error("", e);
1067 private void programVlanRules (NeutronNetwork network, Node node, Interface intf) {
1068 /* TODO SB_MIGRATION */
1069 Preconditions.checkNotNull(ovsdbConfigurationService);
1070 logger.debug("Program vlan rules for interface {}", intf.getName());
1073 Long dpid = this.getIntegrationBridgeOFDPID(node);
1075 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1079 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
1081 while ((of_ports == null) && (timeout > 0)) {
1082 of_ports = intf.getOpenFlowPortColumn().getData();
1083 if (of_ports == null || of_ports.size() <= 0) {
1084 // Wait for the OVSDB update to sync up the Local cache.
1089 if (of_ports == null || of_ports.size() <= 0) {
1090 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
1093 long localPort = (Long)of_ports.toArray()[0];
1095 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
1096 if (externalIds == null) {
1097 logger.error("No external_ids seen in {}", intf);
1101 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
1102 if (attachedMac == null) {
1103 logger.error("No AttachedMac seen in {}", intf);
1107 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1108 if (intfs != null) {
1109 for (Row row : intfs.values()) {
1110 Interface ethIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1111 if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork()))) {
1112 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1114 while ((of_ports == null) && (timeout > 0)) {
1115 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1116 if (of_ports == null || of_ports.size() <= 0) {
1117 // Wait for the OVSDB update to sync up the Local cache.
1123 if (of_ports == null || of_ports.size() <= 0) {
1124 logger.error("Could NOT Identify eth port {} on {}", ethIntf.getName(), node);
1127 long ethOFPort = (Long)of_ports.toArray()[0];
1129 if (ethOFPort == -1) {
1130 logger.error("Could NOT Identify eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1131 throw new Exception("port number < 0");
1133 logger.debug("Identified eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1134 // TODO: add logic to only add rule on remote nodes
1135 programRemoteEgressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, ethOFPort);
1136 programLocalIngressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, localPort, ethOFPort);
1141 } catch (Exception e) {
1142 logger.error("", e);
1146 private void removeVlanRules (NeutronNetwork network, Node node,
1147 Interface intf, boolean isLastInstanceOnNode) {
1148 /* TODO SB_MIGRATION */
1149 Preconditions.checkNotNull(ovsdbConfigurationService);
1150 logger.debug("Remove vlan rules for interface {}", intf.getName());
1154 Long dpid = this.getIntegrationBridgeOFDPID(node);
1156 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1160 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
1161 if (of_ports == null || of_ports.size() <= 0) {
1162 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
1165 long localPort = (Long)of_ports.toArray()[0];
1167 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
1168 if (externalIds == null) {
1169 logger.error("No external_ids seen in {}", intf);
1173 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
1174 if (attachedMac == null) {
1175 logger.error("No AttachedMac seen in {}", intf);
1179 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1180 if (intfs != null) {
1181 for (Row row : intfs.values()) {
1182 Interface ethIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1183 if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node,
1184 network.getProviderPhysicalNetwork()))) {
1185 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1186 if (of_ports == null || of_ports.size() <= 0) {
1187 logger.error("Could NOT Identify eth port {} on {}", ethIntf.getName(), node);
1190 long ethOFPort = (Long)of_ports.toArray()[0];
1192 if (ethOFPort == -1) {
1193 logger.error("Could NOT Identify eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1194 throw new Exception("port number < 0");
1196 logger.debug("Identified eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1198 removeRemoteEgressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, localPort, ethOFPort);
1199 if (isLastInstanceOnNode) {
1200 removePerVlanRules(node, dpid, network.getProviderSegmentationID(), localPort, ethOFPort);
1206 } catch (Exception e) {
1207 logger.error("", e);
1212 public Status handleInterfaceUpdate(NeutronNetwork network, Node srcNode, Interface intf) {
1213 /* TODO SB_MIGRATION */
1214 Preconditions.checkNotNull(connectionService);
1215 List<Node> nodes = connectionService.getNodes();
1216 nodes.remove(srcNode);
1217 this.programLocalRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), srcNode, intf);
1219 if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
1220 this.programVlanRules(network, srcNode, intf);
1221 } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
1222 || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)){
1223 for (Node dstNode : nodes) {
1224 InetAddress src = configurationService.getTunnelEndPoint(srcNode);
1225 InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
1226 if ((src != null) && (dst != null)) {
1227 Status status = addTunnelPort(srcNode, network.getProviderNetworkType(), src, dst);
1228 if (status.isSuccess()) {
1229 this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, intf, true);
1231 addTunnelPort(dstNode, network.getProviderNetworkType(), dst, src);
1232 if (status.isSuccess()) {
1233 this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, intf, false);
1236 logger.warn("Tunnel end-point configuration missing. Please configure it in OpenVSwitch Table. " +
1237 "Check source {} or destination {}",
1238 src != null ? src.getHostAddress() : "null",
1239 dst != null ? dst.getHostAddress() : "null");
1244 return new Status(StatusCode.SUCCESS);
1247 private Status triggerInterfaceUpdates(Node node) {
1248 /* TODO SB_MIGRATION */
1249 Preconditions.checkNotNull(ovsdbConfigurationService);
1251 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1252 if (intfs != null) {
1253 for (Row row : intfs.values()) {
1254 Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1255 NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
1256 logger.debug("Trigger Interface update for {}", intf);
1257 if (network != null) {
1258 this.handleInterfaceUpdate(network, node, intf);
1262 } catch (Exception e) {
1263 logger.error("Error Triggering the lost interface updates for "+ node, e);
1264 return new Status(StatusCode.INTERNALERROR, e.getLocalizedMessage());
1266 return new Status(StatusCode.SUCCESS);
1269 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
1270 // TODO Auto-generated method stub
1275 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node srcNode, Interface intf,
1276 boolean isLastInstanceOnNode) {
1277 /* TODO SB_MIGRATION */
1278 Preconditions.checkNotNull(connectionService);
1279 Status status = new Status(StatusCode.SUCCESS);
1280 List<Node> nodes = connectionService.getNodes();
1281 nodes.remove(srcNode);
1283 logger.info("Delete intf " + intf.getName() + " isLastInstanceOnNode " + isLastInstanceOnNode);
1284 List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(srcNode);
1285 if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)
1286 || intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
1287 // Delete tunnel port
1289 Map<String, String> options = intf.getOptionsColumn().getData();
1290 InetAddress src = InetAddress.getByName(options.get("local_ip"));
1291 InetAddress dst = InetAddress.getByName(options.get("remote_ip"));
1292 status = deleteTunnelPort(srcNode, intf.getTypeColumn().getData(), src, dst);
1293 } catch (Exception e) {
1294 logger.error(e.getMessage(), e);
1296 } else if (phyIfName.contains(intf.getName())) {
1297 deletePhysicalPort(srcNode, intf.getName());
1299 // delete all other interfaces
1300 this.removeLocalRules(network.getProviderNetworkType(), network.getProviderSegmentationID(),
1303 if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
1304 this.removeVlanRules(network, srcNode,
1305 intf, isLastInstanceOnNode);
1306 } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
1307 || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
1309 for (Node dstNode : nodes) {
1310 InetAddress src = configurationService.getTunnelEndPoint(srcNode);
1311 InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
1312 if ((src != null) && (dst != null)) {
1313 logger.info("Remove tunnel rules for interface "
1314 + intf.getName() + " on srcNode " + srcNode.getNodeId().getValue());
1315 this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
1316 dst, srcNode, intf, true, isLastInstanceOnNode);
1317 logger.info("Remove tunnel rules for interface "
1318 + intf.getName() + " on dstNode " + dstNode.getNodeId().getValue());
1319 this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
1320 src, dstNode, intf, false, isLastInstanceOnNode);
1322 logger.warn("Tunnel end-point configuration missing. Please configure it in OpenVSwitch Table. ",
1323 "Check source {} or destination {}",
1324 src != null ? src.getHostAddress() : "null",
1325 dst != null ? dst.getHostAddress() : "null");
1331 return new Status(StatusCode.SUCCESS);
1335 public void initializeFlowRules(Node node) {
1336 this.initializeFlowRules(node, configurationService.getIntegrationBridgeName());
1337 this.initializeFlowRules(node, configurationService.getExternalBridgeName());
1338 this.triggerInterfaceUpdates(node);
1341 private void initializeFlowRules(Node node, String bridgeName) {
1342 String bridgeUuid = this.getInternalBridgeUUID(node, bridgeName);
1343 if (bridgeUuid == null) {
1347 Long dpid = getDpid(node, bridgeUuid);
1350 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1357 * Match: LLDP (0x88CCL)
1358 * Action: Packet_In to Controller Reserved Port
1361 writeLLDPRule(dpid);
1362 if (bridgeName.equals(configurationService.getExternalBridgeName())) {
1363 writeNormalRule(dpid);
1368 * Create an LLDP Flow Rule to encapsulate into
1369 * a packet_in that is sent to the controller
1370 * for topology handling.
1371 * Match: Ethertype 0x88CCL
1372 * Action: Punt to Controller in a Packet_In msg
1375 private void writeLLDPRule(Long dpidLong) {
1376 classifierProvider.programLLDPPuntRule(dpidLong);
1380 * Create a NORMAL Table Miss Flow Rule
1382 * Action: forward to NORMAL pipeline
1385 private void writeNormalRule(Long dpidLong) {
1387 String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
1389 MatchBuilder matchBuilder = new MatchBuilder();
1390 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1391 FlowBuilder flowBuilder = new FlowBuilder();
1393 // Create the OF Actions and Instructions
1394 InstructionBuilder ib = new InstructionBuilder();
1395 InstructionsBuilder isb = new InstructionsBuilder();
1397 // Instructions List Stores Individual Instructions
1398 List<Instruction> instructions = Lists.newArrayList();
1400 // Call the InstructionBuilder Methods Containing Actions
1401 InstructionUtils.createNormalInstructions(nodeName, ib);
1403 ib.setKey(new InstructionKey(0));
1404 instructions.add(ib.build());
1406 // Add InstructionBuilder to the Instruction(s)Builder List
1407 isb.setInstruction(instructions);
1409 // Add InstructionsBuilder to FlowBuilder
1410 flowBuilder.setInstructions(isb.build());
1412 String flowId = "NORMAL";
1413 flowBuilder.setId(new FlowId(flowId));
1414 FlowKey key = new FlowKey(new FlowId(flowId));
1415 flowBuilder.setMatch(matchBuilder.build());
1416 flowBuilder.setPriority(0);
1417 flowBuilder.setBarrier(true);
1418 flowBuilder.setTableId((short) 0);
1419 flowBuilder.setKey(key);
1420 flowBuilder.setFlowName(flowId);
1421 flowBuilder.setHardTimeout(0);
1422 flowBuilder.setIdleTimeout(0);
1423 writeFlow(flowBuilder, nodeBuilder);
1427 * (Table:0) Ingress Tunnel Traffic
1428 * Match: OpenFlow InPort and Tunnel ID
1429 * Action: GOTO Local Table (10)
1430 * table=0,tun_id=0x5,in_port=10, actions=goto_table:2
1433 private void handleTunnelIn(Long dpidLong, Short writeTable,
1434 Short goToTableId, String segmentationId,
1435 Long ofPort, boolean write) {
1436 classifierProvider.programTunnelIn(dpidLong, segmentationId, ofPort, write);
1440 * (Table:0) Ingress VLAN Traffic
1441 * Match: OpenFlow InPort and vlan ID
1442 * Action: GOTO Local Table (20)
1443 * table=0,vlan_id=0x5,in_port=10, actions=goto_table:2
1446 private void handleVlanIn(Long dpidLong, Short writeTable, Short goToTableId,
1447 String segmentationId, Long ethPort, boolean write) {
1448 classifierProvider.programVlanIn(dpidLong, segmentationId, ethPort, write);
1452 * (Table:0) Egress VM Traffic Towards TEP
1453 * Match: Destination Ethernet Addr and OpenFlow InPort
1454 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1455 * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
1456 * actions=set_field:5->tun_id,goto_table=1"
1459 private void handleLocalInPort(Long dpidLong, Short writeTable, Short goToTableId,
1460 String segmentationId, Long inPort, String attachedMac,
1462 classifierProvider.programLocalInPort(dpidLong, segmentationId, inPort, attachedMac, write);
1466 * (Table:0) Egress VM Traffic Towards TEP
1467 * Match: Source Ethernet Addr and OpenFlow InPort
1468 * Instruction: Set VLANID and GOTO Table Egress (n)
1469 * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
1470 * actions=push_vlan, set_field:5->vlan_id,goto_table=1"
1473 private void handleLocalInPortSetVlan(Long dpidLong, Short writeTable,
1474 Short goToTableId, String segmentationId,
1475 Long inPort, String attachedMac,
1477 classifierProvider.programLocalInPortSetVlan(dpidLong, segmentationId, inPort, attachedMac, write);
1481 * (Table:0) Drop frames source from a VM that do not
1482 * match the associated MAC address of the local VM.
1483 * Match: Low priority anything not matching the VM SMAC
1485 * table=0,priority=16384,in_port=1 actions=drop"
1488 private void handleDropSrcIface(Long dpidLong, Long inPort, boolean write) {
1489 classifierProvider.programDropSrcIface(dpidLong, inPort, write);
1493 * (Table:1) Egress Tunnel Traffic
1494 * Match: Destination Ethernet Addr and Local InPort
1495 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1496 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
1497 * actions=output:10,goto_table:2"
1499 private void handleTunnelOut(Long dpidLong, Short writeTable,
1500 Short goToTableId, String segmentationId,
1501 Long OFPortOut, String attachedMac,
1503 l2ForwardingProvider.programTunnelOut(dpidLong, segmentationId, OFPortOut, attachedMac, write);
1507 * (Table:1) Egress VLAN Traffic
1508 * Match: Destination Ethernet Addr and VLAN id
1509 * Instruction: GOTO Table Table 2
1510 * table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
1511 * actions= goto_table:2"
1514 private void handleVlanOut(Long dpidLong, Short writeTable,
1515 Short goToTableId, String segmentationId,
1516 Long ethPort, String attachedMac, boolean write) {
1517 l2ForwardingProvider.programVlanOut(dpidLong, segmentationId, ethPort, attachedMac, write);
1521 * (Table:1) Egress Tunnel Traffic
1522 * Match: Destination Ethernet Addr and Local InPort
1523 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1524 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1525 * actions=output:10,output:11,goto_table:2
1528 private void handleTunnelFloodOut(Long dpidLong, Short writeTable,
1529 Short localTable, String segmentationId,
1530 Long OFPortOut, boolean write) {
1531 l2ForwardingProvider.programTunnelFloodOut(dpidLong, segmentationId, OFPortOut, write);
1535 * (Table:1) Egress VLAN Traffic
1536 * Match: Destination Ethernet Addr and VLAN id
1537 * Instruction: GOTO table 2 and Output port eth interface
1538 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1539 * actions=output:eth1,goto_table:2
1542 private void handleVlanFloodOut(Long dpidLong, Short writeTable,
1543 Short localTable, String segmentationId,
1544 Long localPort, Long ethPort, boolean write) {
1545 //l2ForwardingProvider.programVlanFloodOut(dpidLong, segmentationId, localPort, ethPort, write);
1549 * (Table:1) Table Drain w/ Catch All
1551 * Action: GOTO Local Table (10)
1552 * table=2,priority=8192,tun_id=0x5 actions=drop
1555 private void handleTunnelMiss(Long dpidLong, Short writeTable,
1556 Short goToTableId, String segmentationId,
1558 l2ForwardingProvider.programTunnelMiss(dpidLong, segmentationId, write);
1563 * (Table:1) Table Drain w/ Catch All
1565 * Action: Output port eth interface
1566 * table=1,priority=8192,vlan_id=0x5 actions= output port:eth1
1567 * table=110,priority=8192,dl_vlan=2001 actions=output:2
1570 private void handleVlanMiss(Long dpidLong, Short writeTable,
1571 Short goToTableId, String segmentationId,
1572 Long ethPort, boolean write) {
1573 l2ForwardingProvider.programVlanMiss(dpidLong, segmentationId, ethPort, write);
1577 * (Table:1) Local Broadcast Flood
1578 * Match: Tunnel ID and dMAC
1579 * Action: Output Port
1580 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
1583 private void handleLocalUcastOut(Long dpidLong, Short writeTable,
1584 String segmentationId, Long localPort,
1585 String attachedMac, boolean write) {
1586 l2ForwardingProvider.programLocalUcastOut(dpidLong, segmentationId, localPort, attachedMac, write);
1590 * (Table:2) Local VLAN unicast
1591 * Match: VLAN ID and dMAC
1592 * Action: Output Port
1593 * table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
1596 private void handleLocalVlanUcastOut(Long dpidLong, Short writeTable,
1597 String segmentationId, Long localPort,
1598 String attachedMac, boolean write) {
1599 l2ForwardingProvider.programLocalVlanUcastOut(dpidLong, segmentationId, localPort, attachedMac, write);
1603 * (Table:2) Local Broadcast Flood
1604 * Match: Tunnel ID and dMAC (::::FF:FF)
1605 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1606 * actions=output:2,3,4,5
1609 private void handleLocalBcastOut(Long dpidLong, Short writeTable,
1610 String segmentationId, Long localPort,
1612 l2ForwardingProvider.programLocalBcastOut(dpidLong, segmentationId, localPort, write);
1616 * (Table:2) Local VLAN Broadcast Flood
1617 * Match: vlan ID and dMAC (::::FF:FF)
1618 * table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1619 * actions=strip_vlan, output:2,3,4,5
1620 * table=110,dl_vlan=2001,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=output:2,pop_vlan,output:1,output:3,output:4
1623 private void handleLocalVlanBcastOut(Long dpidLong, Short writeTable, String segmentationId,
1624 Long localPort, Long ethPort, boolean write) {
1625 l2ForwardingProvider.programLocalVlanBcastOut(dpidLong, segmentationId, localPort, ethPort, write);
1629 * (Table:1) Local Table Miss
1630 * Match: Any Remaining Flows w/a TunID
1631 * Action: Drop w/ a low priority
1632 * table=2,priority=8192,tun_id=0x5 actions=drop
1635 private void handleLocalTableMiss(Long dpidLong, Short writeTable,
1636 String segmentationId, boolean write) {
1637 l2ForwardingProvider.programLocalTableMiss(dpidLong, segmentationId, write);
1641 * (Table:1) Local Table Miss
1642 * Match: Any Remaining Flows w/a VLAN ID
1643 * Action: Drop w/ a low priority
1644 * table=2,priority=8192,vlan_id=0x5 actions=drop
1647 private void handleLocalVlanTableMiss(Long dpidLong, Short writeTable,
1648 String segmentationId, boolean write) {
1649 l2ForwardingProvider.programLocalVlanTableMiss(dpidLong, segmentationId, write);
1652 private Group getGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
1653 Preconditions.checkNotNull(mdsalConsumer);
1654 if (mdsalConsumer == null) {
1655 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
1659 dataBroker = mdsalConsumer.getDataBroker();
1660 if (dataBroker == null) {
1661 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1665 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1666 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
1667 new GroupKey(groupBuilder.getGroupId())).build();
1668 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
1670 Optional<Group> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
1671 if (data.isPresent()) {
1674 } catch (InterruptedException|ExecutionException e) {
1675 logger.error(e.getMessage(), e);
1678 logger.debug("Cannot find data for Group " + groupBuilder.getGroupName());
1682 private void writeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
1683 Preconditions.checkNotNull(mdsalConsumer);
1684 if (mdsalConsumer == null) {
1685 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
1689 dataBroker = mdsalConsumer.getDataBroker();
1690 if (dataBroker == null) {
1691 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1695 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
1696 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1697 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
1698 new GroupKey(groupBuilder.getGroupId())).build();
1699 modification.put(LogicalDatastoreType.CONFIGURATION, path1, groupBuilder.build(), true /*createMissingParents*/);
1701 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
1703 commitFuture.get(); // TODO: Make it async (See bug 1362)
1704 logger.debug("Transaction success for write of Group "+groupBuilder.getGroupName());
1705 } catch (InterruptedException|ExecutionException e) {
1706 logger.error(e.getMessage(), e);
1710 private void removeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
1711 Preconditions.checkNotNull(mdsalConsumer);
1712 if (mdsalConsumer == null) {
1713 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
1717 dataBroker = mdsalConsumer.getDataBroker();
1718 if (dataBroker == null) {
1719 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1723 WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
1724 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1725 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
1726 new GroupKey(groupBuilder.getGroupId())).build();
1727 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
1728 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
1731 commitFuture.get(); // TODO: Make it async (See bug 1362)
1732 logger.debug("Transaction success for deletion of Group "+groupBuilder.getGroupName());
1733 } catch (InterruptedException|ExecutionException e) {
1734 logger.error(e.getMessage(), e);
1737 private Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
1738 Preconditions.checkNotNull(mdsalConsumer);
1739 if (mdsalConsumer == null) {
1740 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
1744 dataBroker = mdsalConsumer.getDataBroker();
1745 if (dataBroker == null) {
1746 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1750 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1751 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
1752 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
1754 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
1756 Optional<Flow> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
1757 if (data.isPresent()) {
1760 } catch (InterruptedException|ExecutionException e) {
1761 logger.error(e.getMessage(), e);
1764 logger.debug("Cannot find data for Flow " + flowBuilder.getFlowName());
1768 private void writeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
1769 Preconditions.checkNotNull(mdsalConsumer);
1770 if (mdsalConsumer == null) {
1771 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
1775 dataBroker = mdsalConsumer.getDataBroker();
1776 if (dataBroker == null) {
1777 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1781 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
1782 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1783 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
1784 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
1786 //modification.put(LogicalDatastoreType.OPERATIONAL, path1, flowBuilder.build());
1787 modification.put(LogicalDatastoreType.CONFIGURATION, path1, flowBuilder.build(), true /*createMissingParents*/);
1790 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
1792 commitFuture.get(); // TODO: Make it async (See bug 1362)
1793 logger.debug("Transaction success for write of Flow "+flowBuilder.getFlowName());
1794 } catch (InterruptedException|ExecutionException e) {
1795 logger.error(e.getMessage(), e);
1799 private void removeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
1800 Preconditions.checkNotNull(mdsalConsumer);
1801 if (mdsalConsumer == null) {
1802 logger.error("ERROR finding MDSAL Service.");
1806 dataBroker = mdsalConsumer.getDataBroker();
1807 if (dataBroker == null) {
1808 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
1812 WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
1813 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
1814 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
1815 .rev130819.nodes.Node.class, nodeBuilder.getKey())
1816 .augmentation(FlowCapableNode.class).child(Table.class,
1817 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
1818 //modification.delete(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder));
1819 //modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
1820 //modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder));
1821 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
1823 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
1825 commitFuture.get(); // TODO: Make it async (See bug 1362)
1826 logger.debug("Transaction success for deletion of Flow "+flowBuilder.getFlowName());
1827 } catch (InterruptedException|ExecutionException e) {
1828 logger.error(e.getMessage(), e);
1833 * Create Output Port Group Instruction
1835 * @param ib Map InstructionBuilder without any instructions
1836 * @param dpidLong Long the datapath ID of a switch/node
1837 * @param port Long representing a port on a switch/node
1838 * @return ib InstructionBuilder Map with instructions
1840 protected InstructionBuilder createOutputGroupInstructions(NodeBuilder nodeBuilder,
1841 InstructionBuilder ib,
1842 Long dpidLong, Long port ,
1843 List<Instruction> instructions) {
1844 NodeConnectorId ncid = new NodeConnectorId(Constants.OPENFLOW_NODE_PREFIX + dpidLong + ":" + port);
1845 logger.debug("createOutputGroupInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
1847 List<Action> actionList = Lists.newArrayList();
1848 ActionBuilder ab = new ActionBuilder();
1850 List<Action> existingActions;
1851 if (instructions != null) {
1852 for (Instruction in : instructions) {
1853 if (in.getInstruction() instanceof ApplyActionsCase) {
1854 existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
1855 actionList.addAll(existingActions);
1860 GroupBuilder groupBuilder = new GroupBuilder();
1863 /* Create output action for this port*/
1864 OutputActionBuilder oab = new OutputActionBuilder();
1865 oab.setOutputNodeConnector(ncid);
1866 ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
1867 logger.debug("createOutputGroupInstructions(): output action {}", ab.build());
1868 boolean addNew = true;
1869 boolean groupActionAdded = false;
1871 /* Find the group action and get the group */
1872 for (Action action : actionList) {
1873 if (action.getAction() instanceof GroupActionCase) {
1874 groupActionAdded = true;
1875 GroupActionCase groupAction = (GroupActionCase) action.getAction();
1876 Long id = groupAction.getGroupAction().getGroupId();
1877 String groupName = groupAction.getGroupAction().getGroup();
1878 GroupKey key = new GroupKey(new GroupId(id));
1880 groupBuilder.setGroupId(new GroupId(id));
1881 groupBuilder.setGroupName(groupName);
1882 groupBuilder.setGroupType(GroupTypes.GroupAll);
1883 groupBuilder.setKey(key);
1884 group = getGroup(groupBuilder, nodeBuilder);
1885 logger.debug("createOutputGroupInstructions: group {}", group);
1890 logger.debug("createOutputGroupInstructions: groupActionAdded {}", groupActionAdded);
1891 if (groupActionAdded) {
1892 /* modify the action bucket in group */
1893 groupBuilder = new GroupBuilder(group);
1894 Buckets buckets = groupBuilder.getBuckets();
1895 for (Bucket bucket : buckets.getBucket()) {
1896 List<Action> bucketActions = bucket.getAction();
1897 logger.debug("createOutputGroupInstructions: bucketActions {}", bucketActions);
1898 for (Action action : bucketActions) {
1899 if (action.getAction() instanceof OutputActionCase) {
1900 OutputActionCase opAction = (OutputActionCase)action.getAction();
1901 /* If output port action already in the action list of one of the buckets, skip */
1902 if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
1909 logger.debug("createOutputGroupInstructions: addNew {}", addNew);
1911 /* the new output action is not in the bucket, add to bucket */
1912 if (!buckets.getBucket().isEmpty()) {
1913 Bucket bucket = buckets.getBucket().get(0);
1914 List<Action> bucketActionList = Lists.newArrayList();
1915 bucketActionList.addAll(bucket.getAction());
1916 /* set order for new action and add to action list */
1917 ab.setOrder(bucketActionList.size());
1918 ab.setKey(new ActionKey(bucketActionList.size()));
1919 bucketActionList.add(ab.build());
1921 /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
1922 BucketsBuilder bucketsBuilder = new BucketsBuilder();
1923 List<Bucket> bucketList = Lists.newArrayList();
1924 BucketBuilder bucketBuilder = new BucketBuilder();
1925 bucketBuilder.setBucketId(new BucketId((long) 1));
1926 bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
1927 bucketBuilder.setAction(bucketActionList);
1928 bucketList.add(bucketBuilder.build());
1929 bucketsBuilder.setBucket(bucketList);
1930 groupBuilder.setBuckets(bucketsBuilder.build());
1931 logger.debug("createOutputGroupInstructions: bucketList {}", bucketList);
1936 groupBuilder = new GroupBuilder();
1937 groupBuilder.setGroupType(GroupTypes.GroupAll);
1938 groupBuilder.setGroupId(new GroupId(groupId));
1939 groupBuilder.setKey(new GroupKey(new GroupId(groupId)));
1940 groupBuilder.setGroupName("Output port group " + groupId);
1941 groupBuilder.setBarrier(false);
1943 BucketsBuilder bucketBuilder = new BucketsBuilder();
1944 List<Bucket> bucketList = Lists.newArrayList();
1945 BucketBuilder bucket = new BucketBuilder();
1946 bucket.setBucketId(new BucketId((long) 1));
1947 bucket.setKey(new BucketKey(new BucketId((long) 1)));
1949 /* put output action to the bucket */
1950 List<Action> bucketActionList = Lists.newArrayList();
1951 /* set order for new action and add to action list */
1952 ab.setOrder(bucketActionList.size());
1953 ab.setKey(new ActionKey(bucketActionList.size()));
1954 bucketActionList.add(ab.build());
1956 bucket.setAction(bucketActionList);
1957 bucketList.add(bucket.build());
1958 bucketBuilder.setBucket(bucketList);
1959 groupBuilder.setBuckets(bucketBuilder.build());
1961 /* Add new group action */
1962 GroupActionBuilder groupActionB = new GroupActionBuilder();
1963 groupActionB.setGroupId(groupId);
1964 groupActionB.setGroup("Output port group " + groupId);
1965 ab = new ActionBuilder();
1966 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1967 ab.setOrder(actionList.size());
1968 ab.setKey(new ActionKey(actionList.size()));
1969 actionList.add(ab.build());
1973 logger.debug("createOutputGroupInstructions: group {}", groupBuilder.build());
1974 logger.debug("createOutputGroupInstructions: actionList {}", actionList);
1977 /* rewrite the group to group table */
1978 writeGroup(groupBuilder, nodeBuilder);
1981 // Create an Apply Action
1982 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1983 aab.setAction(actionList);
1984 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1990 * Remove Output Port from action list in group bucket
1992 * @param ib Map InstructionBuilder without any instructions
1993 * @param dpidLong Long the datapath ID of a switch/node
1994 * @param port Long representing a port on a switch/node
1995 * @return ib InstructionBuilder Map with instructions
1997 protected boolean removeOutputPortFromGroup(NodeBuilder nodeBuilder, InstructionBuilder ib,
1998 Long dpidLong, Long port , List<Instruction> instructions) {
2000 NodeConnectorId ncid = new NodeConnectorId(Constants.OPENFLOW_NODE_PREFIX + dpidLong + ":" + port);
2001 logger.debug("removeOutputPortFromGroup() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
2003 List<Action> actionList = Lists.newArrayList();
2006 List<Action> existingActions;
2007 if (instructions != null) {
2008 for (Instruction in : instructions) {
2009 if (in.getInstruction() instanceof ApplyActionsCase) {
2010 existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
2011 actionList.addAll(existingActions);
2017 GroupBuilder groupBuilder = new GroupBuilder();
2019 boolean groupActionAdded = false;
2020 /* Find the group action and get the group */
2021 for (Action action : actionList) {
2022 if (action.getAction() instanceof GroupActionCase) {
2023 groupActionAdded = true;
2024 GroupActionCase groupAction = (GroupActionCase) action.getAction();
2025 Long id = groupAction.getGroupAction().getGroupId();
2026 String groupName = groupAction.getGroupAction().getGroup();
2027 GroupKey key = new GroupKey(new GroupId(id));
2029 groupBuilder.setGroupId(new GroupId(id));
2030 groupBuilder.setGroupName(groupName);
2031 groupBuilder.setGroupType(GroupTypes.GroupAll);
2032 groupBuilder.setKey(key);
2033 group = getGroup(groupBuilder, nodeBuilder);
2038 if (groupActionAdded) {
2039 /* modify the action bucket in group */
2040 groupBuilder = new GroupBuilder(group);
2041 Buckets buckets = groupBuilder.getBuckets();
2042 List<Action> bucketActions = Lists.newArrayList();
2043 for (Bucket bucket : buckets.getBucket()) {
2045 boolean isPortDeleted = false;
2046 bucketActions = bucket.getAction();
2047 for (Action action : bucketActions) {
2048 if (action.getAction() instanceof OutputActionCase) {
2049 OutputActionCase opAction = (OutputActionCase)action.getAction();
2050 if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
2051 /* Find the output port in action list and remove */
2052 index = bucketActions.indexOf(action);
2053 bucketActions.remove(action);
2054 isPortDeleted = true;
2059 if (isPortDeleted && !bucketActions.isEmpty()) {
2060 for (int i = index; i< bucketActions.size(); i++) {
2061 Action action = bucketActions.get(i);
2062 if (action.getOrder() != i) {
2063 /* Shift the action order */
2064 ab = new ActionBuilder();
2065 ab.setAction(action.getAction());
2067 ab.setKey(new ActionKey(i));
2068 Action actionNewOrder = ab.build();
2069 bucketActions.remove(action);
2070 bucketActions.add(i, actionNewOrder);
2074 } else if (bucketActions.isEmpty()) {
2075 /* remove bucket with empty action list */
2076 buckets.getBucket().remove(bucket);
2080 if (!buckets.getBucket().isEmpty()) {
2081 /* rewrite the group to group table */
2082 /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
2083 BucketsBuilder bucketsBuilder = new BucketsBuilder();
2084 List<Bucket> bucketList = Lists.newArrayList();
2085 BucketBuilder bucketBuilder = new BucketBuilder();
2086 bucketBuilder.setBucketId(new BucketId((long) 1));
2087 bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
2088 bucketBuilder.setAction(bucketActions);
2089 bucketList.add(bucketBuilder.build());
2090 bucketsBuilder.setBucket(bucketList);
2091 groupBuilder.setBuckets(bucketsBuilder.build());
2092 logger.debug("removeOutputPortFromGroup: bucketList {}", bucketList);
2094 writeGroup(groupBuilder, nodeBuilder);
2095 ApplyActionsBuilder aab = new ApplyActionsBuilder();
2096 aab.setAction(actionList);
2097 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2100 /* remove group with empty bucket. return true to delete flow */
2101 removeGroup(groupBuilder, nodeBuilder);
2105 /* no group for port list. flow can be removed */
2111 public void initializeOFFlowRules(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node openflowNode) {
2112 /* TODO SB_MIGRATION */
2113 Preconditions.checkNotNull(connectionService);
2114 List<Node> ovsNodes = connectionService.getNodes();
2115 if (ovsNodes == null) return;
2116 for (Node ovsNode : ovsNodes) {
2117 Long brIntDpid = this.getIntegrationBridgeOFDPID(ovsNode);
2118 Long brExDpid = this.getExternalBridgeDpid(ovsNode);
2119 logger.debug("Compare openflowNode to OVS node {} vs {} and {}",
2120 openflowNode.getId().getValue(), brIntDpid, brExDpid);
2121 String openflowID = openflowNode.getId().getValue();
2122 if (openflowID.contains(brExDpid.toString())) {
2123 this.initializeFlowRules(ovsNode, configurationService.getExternalBridgeName());
2124 this.triggerInterfaceUpdates(ovsNode);
2126 if (openflowID.contains(brIntDpid.toString())) {
2127 this.initializeFlowRules(ovsNode, configurationService.getIntegrationBridgeName());
2128 this.triggerInterfaceUpdates(ovsNode);
2134 public void notifyFlowCapableNodeEvent(Long dpid, org.opendaylight.ovsdb.openstack.netvirt.api.Action action) {
2135 mdsalConsumer.notifyFlowCapableNodeCreateEvent(Constants.OPENFLOW_NODE_PREFIX + dpid, action);
2138 public static NodeBuilder createNodeBuilder(String nodeId) {
2139 NodeBuilder builder = new NodeBuilder();
2140 builder.setId(new NodeId(nodeId));
2141 builder.setKey(new NodeKey(builder.getId()));
2145 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeBuilderToInstanceId(NodeBuilder
2147 return InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
2148 node.getKey()).toInstance();
2151 private String getInternalBridgeUUID (Node node, String bridgeName) {
2152 /* TODO SB_MIGRATION */
2153 Preconditions.checkNotNull(ovsdbConfigurationService);
2155 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
2156 if (bridgeTable == null) return null;
2157 for (String key : bridgeTable.keySet()) {
2158 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
2159 if (bridge.getName().equals(bridgeName)) return key;
2161 } catch (Exception e) {
2162 logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);