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 com.google.common.base.Optional;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
20 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
21 import org.opendaylight.controller.sal.core.Node;
22 import org.opendaylight.controller.sal.utils.HexEncode;
23 import org.opendaylight.controller.sal.utils.Status;
24 import org.opendaylight.controller.sal.utils.StatusCode;
25 import org.opendaylight.ovsdb.lib.notation.Row;
26 import org.opendaylight.ovsdb.lib.notation.UUID;
27 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
28 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
29 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
30 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
31 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
32 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
33 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
34 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
35 import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
36 import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
37 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
38 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
39 import org.opendaylight.ovsdb.schema.openvswitch.Port;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketKey;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
86 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
88 import com.google.common.base.Preconditions;
89 import com.google.common.collect.Lists;
90 import com.google.common.collect.Maps;
91 import org.slf4j.Logger;
92 import org.slf4j.LoggerFactory;
94 import java.math.BigInteger;
95 import java.net.InetAddress;
96 import java.util.List;
99 import java.util.concurrent.ExecutionException;
102 * Open vSwitch OpenFlow 1.3 Networking Provider for OpenStack Neutron
104 public class OF13Provider implements NetworkingProvider {
105 private static final Logger logger = LoggerFactory.getLogger(OF13Provider.class);
106 private DataBroker dataBroker;
107 private static final short TABLE_0_DEFAULT_INGRESS = 0;
108 private static final short TABLE_1_ISOLATE_TENANT = 10;
109 private static final short TABLE_2_LOCAL_FORWARD = 20;
110 private static final String OPENFLOW = "openflow:";
111 private static Long groupId = 1L;
113 private volatile org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService configurationService;
114 private volatile BridgeConfigurationManager bridgeConfigurationManager;
115 private volatile TenantNetworkManager tenantNetworkManager;
116 private volatile OvsdbConfigurationService ovsdbConfigurationService;
117 private volatile OvsdbConnectionService connectionService;
118 private volatile MdsalConsumer mdsalConsumer;
120 public static final String NAME = "OF13Provider";
122 public OF13Provider(){
127 public String getName() {
132 public boolean supportsServices() {
137 public boolean hasPerTenantTunneling() {
141 private Status getTunnelReadinessStatus (Node node, String tunnelKey) {
142 InetAddress srcTunnelEndPoint = configurationService.getTunnelEndPoint(node);
143 if (srcTunnelEndPoint == null) {
144 logger.error("Tunnel Endpoint not configured for Node {}", node);
145 return new Status(StatusCode.NOTFOUND, "Tunnel Endpoint not configured for "+ node);
148 if (!bridgeConfigurationManager.isNodeNeutronReady(node)) {
149 logger.error(node+" is not Overlay ready");
150 return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
153 if (!tenantNetworkManager.isTenantNetworkPresentInNode(node, tunnelKey)) {
154 logger.debug(node+" has no VM corresponding to segment "+ tunnelKey);
155 return new Status(StatusCode.NOTACCEPTABLE, node+" has no VM corresponding to segment "+ tunnelKey);
157 return new Status(StatusCode.SUCCESS);
160 private String getTunnelName(String tunnelType, InetAddress dst) {
161 return tunnelType+"-"+dst.getHostAddress();
164 private boolean isTunnelPresent(Node node, String tunnelName, String bridgeUUID) throws Exception {
165 Preconditions.checkNotNull(ovsdbConfigurationService);
166 Row bridgeRow = ovsdbConfigurationService
167 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
168 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
169 if (bridge != null) {
170 Set<UUID> ports = bridge.getPortsColumn().getData();
171 for (UUID portUUID : ports) {
172 Row portRow = ovsdbConfigurationService
173 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID.toString());
174 Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
175 if (port != null && tunnelName.equalsIgnoreCase(port.getName())) return true;
181 private String getPortUuid(Node node, String name, String bridgeUUID) throws Exception {
182 Preconditions.checkNotNull(ovsdbConfigurationService);
183 Row bridgeRow = ovsdbConfigurationService
184 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
185 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
186 if (bridge != null) {
187 Set<UUID> ports = bridge.getPortsColumn().getData();
188 for (UUID portUUID : ports) {
189 Row portRow = ovsdbConfigurationService
190 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID.toString());
191 Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
192 if (port != null && name.equalsIgnoreCase(port.getName())) return portUUID.toString();
198 private Status addTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst) {
199 Preconditions.checkNotNull(ovsdbConfigurationService);
201 String bridgeUUID = null;
202 String tunnelBridgeName = configurationService.getIntegrationBridgeName();
203 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
204 if (bridgeTable != null) {
205 for (String uuid : bridgeTable.keySet()) {
206 Bridge bridge = ovsdbConfigurationService.getTypedRow(node,Bridge.class, bridgeTable.get(uuid));
207 if (bridge.getName().equals(tunnelBridgeName)) {
213 if (bridgeUUID == null) {
214 logger.error("Could not find Bridge {} in {}", tunnelBridgeName, node);
215 return new Status(StatusCode.NOTFOUND, "Could not find "+tunnelBridgeName+" in "+node);
217 String portName = getTunnelName(tunnelType, dst);
219 if (this.isTunnelPresent(node, portName, bridgeUUID)) {
220 logger.trace("Tunnel {} is present in {} of {}", portName, tunnelBridgeName, node);
221 return new Status(StatusCode.SUCCESS);
224 Port tunnelPort = ovsdbConfigurationService.createTypedRow(node, Port.class);
225 tunnelPort.setName(portName);
226 StatusWithUuid statusWithUuid = ovsdbConfigurationService
227 .insertRow(node, ovsdbConfigurationService.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
228 if (!statusWithUuid.isSuccess()) {
229 logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
230 return statusWithUuid;
233 String tunnelPortUUID = statusWithUuid.getUuid().toString();
234 String interfaceUUID = null;
236 while ((interfaceUUID == null) && (timeout > 0)) {
237 Row portRow = ovsdbConfigurationService
238 .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), tunnelPortUUID);
239 tunnelPort = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
240 Set<UUID> interfaces = tunnelPort.getInterfacesColumn().getData();
241 if (interfaces == null || interfaces.size() == 0) {
242 // Wait for the OVSDB update to sync up the Local cache.
247 interfaceUUID = interfaces.toArray()[0].toString();
248 Row intfRow = ovsdbConfigurationService
249 .getRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), interfaceUUID);
250 Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, intfRow);
251 if (intf == null) interfaceUUID = null;
254 if (interfaceUUID == null) {
255 logger.error("Cannot identify Tunnel Interface for port {}/{}", portName, tunnelPortUUID);
256 return new Status(StatusCode.INTERNALERROR);
259 Interface tunInterface = ovsdbConfigurationService.createTypedRow(node, Interface.class);
260 tunInterface.setType(tunnelType);
261 Map<String, String> options = Maps.newHashMap();
262 options.put("key", "flow");
263 options.put("local_ip", src.getHostAddress());
264 options.put("remote_ip", dst.getHostAddress());
265 tunInterface.setOptions(options);
266 Status status = ovsdbConfigurationService
267 .updateRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
268 logger.debug("Tunnel {} add status : {}", tunInterface, status);
270 } catch (Exception e) {
271 logger.error("Exception in addTunnelPort", e);
272 return new Status(StatusCode.INTERNALERROR);
276 /* delete port from ovsdb port table */
277 private Status deletePort(Node node, String bridgeName, String portName) {
278 Preconditions.checkNotNull(ovsdbConfigurationService);
280 String bridgeUUID = null;
281 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
282 if (bridgeTable != null) {
283 for (String uuid : bridgeTable.keySet()) {
284 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
285 if (bridge.getName().equals(bridgeName)) {
291 if (bridgeUUID == null) {
292 logger.debug("Could not find Bridge {} in {}", bridgeName, node);
293 return new Status(StatusCode.SUCCESS);
296 String portUUID = this.getPortUuid(node, portName, bridgeUUID);
297 Status status = new Status(StatusCode.SUCCESS);
298 if (portUUID != null) {
299 status = ovsdbConfigurationService
300 .deleteRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID);
301 if (!status.isSuccess()) {
302 logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
306 logger.debug("Port {} delete status : {}", portName, status);
309 } catch (Exception e) {
310 logger.error("Exception in deletePort", e);
311 return new Status(StatusCode.INTERNALERROR);
315 private Status deleteTunnelPort(Node node, String tunnelType, InetAddress src, InetAddress dst) {
316 String tunnelBridgeName = configurationService.getIntegrationBridgeName();
317 String portName = getTunnelName(tunnelType, dst);
318 return deletePort(node, tunnelBridgeName, portName);
321 private Status deletePhysicalPort(Node node, String phyIntfName) {
322 String intBridgeName = configurationService.getIntegrationBridgeName();
323 return deletePort(node, intBridgeName, phyIntfName);
326 private void programLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
330 * Match: VM sMac and Local Ingress Port
331 * Action:Action: Set Tunnel ID and GOTO Local Table (5)
334 handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, true);
339 * Match: Drop any remaining Ingress Local VM Packets
340 * Action: Drop w/ a low priority
343 handleDropSrcIface(dpid, localPort, true);
348 * Match: Match TunID and Destination DL/dMAC Addr
349 * Action: Output Port
350 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
353 handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, true);
358 * Match: Tunnel ID and dMAC (::::FF:FF)
359 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
360 * actions=output:2,3,4,5
363 handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
366 * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
371 * Match: Any remaining Ingress Local VM Packets
372 * Action: Drop w/ a low priority
373 * -------------------------------------------
374 * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
377 handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, true);
382 * Match: Any Remaining Flows w/a TunID
383 * Action: Drop w/ a low priority
384 * table=2,priority=8192,tun_id=0x5 actions=drop
387 handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, true);
390 private void removeLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
394 * Match: VM sMac and Local Ingress Port
395 * Action:Action: Set Tunnel ID and GOTO Local Table (5)
398 handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, false);
403 * Match: Drop any remaining Ingress Local VM Packets
404 * Action: Drop w/ a low priority
407 handleDropSrcIface(dpid, localPort, false);
412 * Match: Match TunID and Destination DL/dMAC Addr
413 * Action: Output Port
414 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
417 handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, false);
422 * Match: Tunnel ID and dMAC (::::FF:FF)
423 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
424 * actions=output:2,3,4,5
427 handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
430 private void programLocalIngressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
434 * Match: Ingress Port, Tunnel ID
435 * Action: GOTO Local Table (20)
438 handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
443 * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
444 * Action: Flood to selected destination TEPs
445 * -------------------------------------------
446 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
447 * actions=output:10,output:11,goto_table:2
450 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
454 private void programRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
458 * Match: Drop any remaining Ingress Local VM Packets
459 * Action: Drop w/ a low priority
460 * -------------------------------------------
461 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
462 * actions=output:11,goto_table:2
465 handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, true);
468 private void removeRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
472 * Match: Drop any remaining Ingress Local VM Packets
473 * Action: Drop w/ a low priority
474 * -------------------------------------------
475 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
476 * actions=output:11,goto_table:2
479 handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, false);
482 /* Remove tunnel rules if last node in this tenant network */
483 private void removePerTunnelRules(Node node, Long dpid, String segmentationId, long tunnelOFPort) {
485 * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
490 * Match: Any remaining Ingress Local VM Packets
491 * Action: Drop w/ a low priority
492 * -------------------------------------------
493 * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
496 handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, false);
501 * Match: Any Remaining Flows w/a TunID
502 * Action: Drop w/ a low priority
503 * table=2,priority=8192,tun_id=0x5 actions=drop
506 handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, false);
511 * Match: Ingress Port, Tunnel ID
512 * Action: GOTO Local Table (10)
515 handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
520 * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
521 * Action: Flood to selected destination TEPs
522 * -------------------------------------------
523 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
524 * actions=output:10,output:11,goto_table:2
527 handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
530 private void programLocalVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
534 * Match: VM sMac and Local Ingress Port
535 * Action: Set VLAN ID and GOTO Local Table 1
538 handleLocalInPortSetVlan(dpid, TABLE_0_DEFAULT_INGRESS,
539 TABLE_1_ISOLATE_TENANT, segmentationId, localPort,
545 * Match: Drop any remaining Ingress Local VM Packets
546 * Action: Drop w/ a low priority
549 handleDropSrcIface(dpid, localPort, true);
554 * Match: Match VLAN ID and Destination DL/dMAC Addr
555 * Action: strip vlan, output to local port
556 * Example: table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions= strip vlan, output:2
559 handleLocalVlanUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
560 localPort, attachedMac, true);
565 * Match: VLAN ID and dMAC (::::FF:FF)
566 * Action: strip vlan, output to all local ports in this vlan
567 * Example: table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
568 * actions= strip_vlan, output:2,3,4,5
571 handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
577 * Match: Any Remaining Flows w/a VLAN ID
578 * Action: Drop w/ a low priority
579 * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
582 handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
586 private void removeLocalVlanRules(Node node, Long dpid,
587 String segmentationId, String attachedMac,
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,
633 private void programLocalIngressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
637 * Match: Ingress port = physical interface, Vlan ID
638 * Action: GOTO Local Table 2
641 handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
642 segmentationId, ethPort, true);
647 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
648 * Action: Flood to local and remote VLAN members
649 * -------------------------------------------
650 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
651 * actions=output:10 (eth port),goto_table:2
654 handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
655 segmentationId, ethPort, true);
658 private void programRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
662 * Match: Destination MAC is local VM MAC and vlan id
663 * Action: go to table 2
664 * -------------------------------------------
665 * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
666 * actions=goto_table:2
669 handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
670 segmentationId, ethPort, attachedMac, true);
676 * Action: Go to table 2
677 * -------------------------------------------
678 * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
681 handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
682 segmentationId, ethPort, true);
685 private void removeRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
689 * Match: Destination MAC is local VM MAC and vlan id
690 * Action: go to table 2
691 * -------------------------------------------
692 * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
693 * actions=goto_table:2
696 handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
697 segmentationId, ethPort, attachedMac, false);
700 private void removePerVlanRules(Node node, Long dpid, String segmentationId, long ethPort) {
704 * Match: Any Remaining Flows w/a VLAN ID
705 * Action: Drop w/ a low priority
706 * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
709 handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
715 * Match: Ingress port = physical interface, Vlan ID
716 * Action: GOTO Local Table 2
719 handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
720 segmentationId, ethPort, false);
725 * Match: Match VLAN ID and L2 ::::FF:FF Flooding
726 * Action: Flood to local and remote VLAN members
727 * -------------------------------------------
728 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
729 * actions=output:10 (eth port),goto_table:2
732 handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
733 segmentationId, ethPort, false);
739 * Action: Go to table 2
740 * -------------------------------------------
741 * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
744 handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
745 segmentationId, ethPort, false);
747 private Long getDpid (Node node, String bridgeUuid) {
748 Preconditions.checkNotNull(ovsdbConfigurationService);
750 Row bridgeRow = ovsdbConfigurationService
751 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUuid);
752 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
753 Set<String> dpids = bridge.getDatapathIdColumn().getData();
754 if (dpids == null || dpids.size() == 0) return 0L;
755 return HexEncode.stringToLong((String) dpids.toArray()[0]);
756 } catch (Exception e) {
757 logger.error("Error finding Bridge's OF DPID", e);
762 private Long getIntegrationBridgeOFDPID (Node node) {
764 String bridgeName = configurationService.getIntegrationBridgeName();
765 String brIntId = this.getInternalBridgeUUID(node, bridgeName);
766 if (brIntId == null) {
767 logger.error("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
771 return getDpid(node, brIntId);
772 } catch (Exception e) {
773 logger.error("Error finding Integration Bridge's OF DPID", e);
778 private Long getExternalBridgeDpid (Node node) {
780 String bridgeName = configurationService.getExternalBridgeName();
781 String brUuid = this.getInternalBridgeUUID(node, bridgeName);
782 if (brUuid == null) {
783 logger.error("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
787 return getDpid(node, brUuid);
788 } catch (Exception e) {
789 logger.error("Error finding External Bridge's OF DPID", e);
794 private void programLocalRules (String networkType, String segmentationId, Node node, Interface intf) {
796 Long dpid = this.getIntegrationBridgeOFDPID(node);
798 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
802 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
803 if (of_ports == null || of_ports.size() <= 0) {
804 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
807 long localPort = (Long)of_ports.toArray()[0];
809 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
810 if (externalIds == null) {
811 logger.error("No external_ids seen in {}", intf);
815 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
816 if (attachedMac == null) {
817 logger.error("No AttachedMac seen in {}", intf);
821 /* Program local rules based on network type */
822 if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
823 logger.debug("Program local vlan rules for interface {}", intf.getName());
824 programLocalVlanRules(node, dpid, segmentationId, attachedMac, localPort);
825 } else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
826 networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
827 logger.debug("Program local bridge rules for interface {}", intf.getName());
828 programLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
830 } catch (Exception e) {
831 logger.error("Exception in programming Local Rules for "+intf+" on "+node, e);
835 private void removeLocalRules (String networkType, String segmentationId, Node node, Interface intf) {
837 Long dpid = this.getIntegrationBridgeOFDPID(node);
839 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
843 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
844 if (of_ports == null || of_ports.size() <= 0) {
845 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
848 long localPort = (Long)of_ports.toArray()[0];
850 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
851 if (externalIds == null) {
852 logger.error("No external_ids seen in {}", intf);
856 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
857 if (attachedMac == null) {
858 logger.error("No AttachedMac seen in {}", intf);
862 /* Program local rules based on network type */
863 if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
864 logger.debug("Remove local vlan rules for interface {}", intf.getName());
865 removeLocalVlanRules(node, dpid, segmentationId, attachedMac, localPort);
866 } else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
867 networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
868 logger.debug("Remove local bridge rules for interface {}", intf.getName());
869 removeLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
871 } catch (Exception e) {
872 logger.error("Exception in removing Local Rules for "+intf+" on "+node, e);
876 private void programTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
877 Interface intf, boolean local) {
879 Preconditions.checkNotNull(ovsdbConfigurationService);
883 Long dpid = this.getIntegrationBridgeOFDPID(node);
885 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
889 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
890 if (of_ports == null || of_ports.size() <= 0) {
891 logger.debug("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
894 long localPort = (Long)of_ports.toArray()[0];
896 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
897 if (externalIds == null) {
898 logger.error("No external_ids seen in {}", intf);
902 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
903 if (attachedMac == null) {
904 logger.error("No AttachedMac seen in {}", intf);
908 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
910 for (Row row : intfs.values()) {
911 Interface tunIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
912 if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
913 of_ports = tunIntf.getOpenFlowPortColumn().getData();
914 if (of_ports == null || of_ports.size() <= 0) {
915 logger.debug("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
918 long tunnelOFPort = (Long)of_ports.toArray()[0];
920 if (tunnelOFPort == -1) {
921 logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
924 logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
927 programRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
929 logger.trace("program local ingress tunnel rules: node" + node.getNodeIDString() + " intf " + intf.getName());
931 programLocalIngressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
937 } catch (Exception e) {
942 private void removeTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
943 Interface intf, boolean local, boolean isLastInstanceOnNode) {
945 Preconditions.checkNotNull(ovsdbConfigurationService);
948 Long dpid = this.getIntegrationBridgeOFDPID(node);
950 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
954 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
955 if (of_ports == null || of_ports.size() <= 0) {
956 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
959 long localPort = (Long)of_ports.toArray()[0];
961 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
962 if (externalIds == null) {
963 logger.error("No external_ids seen in {}", intf);
967 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
968 if (attachedMac == null) {
969 logger.error("No AttachedMac seen in {}", intf);
973 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
975 for (Row row : intfs.values()) {
976 Interface tunIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
977 if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
978 of_ports = tunIntf.getOpenFlowPortColumn().getData();
979 if (of_ports == null || of_ports.size() <= 0) {
980 logger.error("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
983 long tunnelOFPort = (Long)of_ports.toArray()[0];
985 if (tunnelOFPort == -1) {
986 logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
989 logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
992 removeRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
994 if (local && isLastInstanceOnNode) {
995 removePerTunnelRules(node, dpid, segmentationId, tunnelOFPort);
1001 } catch (Exception e) {
1002 logger.error("", e);
1006 private void programVlanRules (NeutronNetwork network, Node node, Interface intf) {
1007 Preconditions.checkNotNull(ovsdbConfigurationService);
1008 logger.debug("Program vlan rules for interface {}", intf.getName());
1011 Long dpid = this.getIntegrationBridgeOFDPID(node);
1013 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1017 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
1019 while ((of_ports == null) && (timeout > 0)) {
1020 of_ports = intf.getOpenFlowPortColumn().getData();
1021 if (of_ports == null || of_ports.size() <= 0) {
1022 // Wait for the OVSDB update to sync up the Local cache.
1027 if (of_ports == null || of_ports.size() <= 0) {
1028 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
1032 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
1033 if (externalIds == null) {
1034 logger.error("No external_ids seen in {}", intf);
1038 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
1039 if (attachedMac == null) {
1040 logger.error("No AttachedMac seen in {}", intf);
1044 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1045 if (intfs != null) {
1046 for (Row row : intfs.values()) {
1047 Interface ethIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1048 if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork()))) {
1049 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1051 while ((of_ports == null) && (timeout > 0)) {
1052 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1053 if (of_ports == null || of_ports.size() <= 0) {
1054 // Wait for the OVSDB update to sync up the Local cache.
1060 if (of_ports == null || of_ports.size() <= 0) {
1061 logger.error("Could NOT Identify eth port {} on {}", ethIntf.getName(), node);
1064 long ethOFPort = (Long)of_ports.toArray()[0];
1066 if (ethOFPort == -1) {
1067 logger.error("Could NOT Identify eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1068 throw new Exception("port number < 0");
1070 logger.debug("Identified eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1072 programRemoteEgressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, ethOFPort);
1073 programLocalIngressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, ethOFPort);
1078 } catch (Exception e) {
1079 logger.error("", e);
1083 private void removeVlanRules (NeutronNetwork network, Node node,
1084 Interface intf, boolean isLastInstanceOnNode) {
1085 Preconditions.checkNotNull(ovsdbConfigurationService);
1086 logger.debug("Remove vlan rules for interface {}", intf.getName());
1090 Long dpid = this.getIntegrationBridgeOFDPID(node);
1092 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1096 Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
1097 if (of_ports == null || of_ports.size() <= 0) {
1098 logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
1102 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
1103 if (externalIds == null) {
1104 logger.error("No external_ids seen in {}", intf);
1108 String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
1109 if (attachedMac == null) {
1110 logger.error("No AttachedMac seen in {}", intf);
1114 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1115 if (intfs != null) {
1116 for (Row row : intfs.values()) {
1117 Interface ethIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1118 if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node,
1119 network.getProviderPhysicalNetwork()))) {
1120 of_ports = ethIntf.getOpenFlowPortColumn().getData();
1121 if (of_ports == null || of_ports.size() <= 0) {
1122 logger.error("Could NOT Identify eth port {} on {}", ethIntf.getName(), node);
1125 long ethOFPort = (Long)of_ports.toArray()[0];
1127 if (ethOFPort == -1) {
1128 logger.error("Could NOT Identify eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1129 throw new Exception("port number < 0");
1131 logger.debug("Identified eth port {} -> OF ({}) on {}", ethIntf.getName(), ethOFPort, node);
1133 removeRemoteEgressVlanRules(node, dpid, network.getProviderSegmentationID(), attachedMac, ethOFPort);
1134 if (isLastInstanceOnNode) {
1135 removePerVlanRules(node, dpid, network.getProviderSegmentationID(), ethOFPort);
1141 } catch (Exception e) {
1142 logger.error("", e);
1147 public Status handleInterfaceUpdate(NeutronNetwork network, Node srcNode, Interface intf) {
1148 Preconditions.checkNotNull(connectionService);
1149 List<Node> nodes = connectionService.getNodes();
1150 nodes.remove(srcNode);
1151 this.programLocalRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), srcNode, intf);
1153 if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
1154 this.programVlanRules(network, srcNode, intf);
1155 } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
1156 || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)){
1157 for (Node dstNode : nodes) {
1158 InetAddress src = configurationService.getTunnelEndPoint(srcNode);
1159 InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
1160 Status status = addTunnelPort(srcNode, network.getProviderNetworkType(), src, dst);
1161 if (status.isSuccess()) {
1162 this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, intf, true);
1164 addTunnelPort(dstNode, network.getProviderNetworkType(), dst, src);
1165 if (status.isSuccess()) {
1166 this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, intf, false);
1171 return new Status(StatusCode.SUCCESS);
1174 private Status triggerInterfaceUpdates(Node node) {
1175 Preconditions.checkNotNull(ovsdbConfigurationService);
1177 Map<String, Row> intfs = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
1178 if (intfs != null) {
1179 for (Row row : intfs.values()) {
1180 Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
1181 NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
1182 logger.debug("Trigger Interface update for {}", intf);
1183 if (network != null) {
1184 this.handleInterfaceUpdate(network, node, intf);
1188 } catch (Exception e) {
1189 logger.error("Error Triggering the lost interface updates for "+ node, e);
1190 return new Status(StatusCode.INTERNALERROR, e.getLocalizedMessage());
1192 return new Status(StatusCode.SUCCESS);
1195 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
1196 // TODO Auto-generated method stub
1201 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node srcNode, Interface intf,
1202 boolean isLastInstanceOnNode) {
1203 Preconditions.checkNotNull(connectionService);
1204 Status status = new Status(StatusCode.SUCCESS);
1205 List<Node> nodes = connectionService.getNodes();
1206 nodes.remove(srcNode);
1208 logger.info("Delete intf " + intf.getName() + " isLastInstanceOnNode " + isLastInstanceOnNode);
1209 List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(srcNode);
1210 if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)
1211 || intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
1212 /* Delete tunnel port */
1214 Map<String, String> options = intf.getOptionsColumn().getData();
1215 InetAddress src = InetAddress.getByName(options.get("local_ip"));
1216 InetAddress dst = InetAddress.getByName(options.get("remote_ip"));
1217 status = deleteTunnelPort(srcNode, intf.getTypeColumn().getData(), src, dst);
1218 } catch (Exception e) {
1219 logger.error(e.getMessage(), e);
1221 } else if (phyIfName.contains(intf.getName())) {
1222 deletePhysicalPort(srcNode, intf.getName());
1224 /* delete all other interfaces */
1225 this.removeLocalRules(network.getProviderNetworkType(), network.getProviderSegmentationID(),
1228 if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
1229 this.removeVlanRules(network, srcNode,
1230 intf, isLastInstanceOnNode);
1231 } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
1232 || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
1234 for (Node dstNode : nodes) {
1235 InetAddress src = configurationService.getTunnelEndPoint(srcNode);
1236 InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
1237 logger.info("Remove tunnel rules for interface " + intf.getName() + " on srcNode " + srcNode.getNodeIDString());
1238 this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
1239 dst, srcNode, intf, true, isLastInstanceOnNode);
1240 logger.info("Remove tunnel rules for interface " + intf.getName() + " on dstNode " + dstNode.getNodeIDString());
1241 this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
1242 src, dstNode, intf, false, isLastInstanceOnNode);
1250 public void initializeFlowRules(Node node) {
1251 this.initializeFlowRules(node, configurationService.getIntegrationBridgeName());
1252 this.initializeFlowRules(node, configurationService.getExternalBridgeName());
1253 this.triggerInterfaceUpdates(node);
1256 private void initializeFlowRules(Node node, String bridgeName) {
1257 String bridgeUuid = this.getInternalBridgeUUID(node, bridgeName);
1258 if (bridgeUuid == null) {
1262 Long dpid = getDpid(node, bridgeUuid);
1265 logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
1272 * Match: LLDP (0x88CCL)
1273 * Action: Packet_In to Controller Reserved Port
1276 writeLLDPRule(dpid);
1277 if (bridgeName.equals(configurationService.getExternalBridgeName())) {
1278 writeNormalRule(dpid);
1283 * Create an LLDP Flow Rule to encapsulate into
1284 * a packet_in that is sent to the controller
1285 * for topology handling.
1286 * Match: Ethertype 0x88CCL
1287 * Action: Punt to Controller in a Packet_In msg
1290 private void writeLLDPRule(Long dpidLong) {
1292 String nodeName = OPENFLOW + dpidLong;
1293 EtherType etherType = new EtherType(0x88CCL);
1295 MatchBuilder matchBuilder = new MatchBuilder();
1296 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1297 FlowBuilder flowBuilder = new FlowBuilder();
1299 // Create Match(es) and Set them in the FlowBuilder Object
1300 flowBuilder.setMatch(MatchUtils.createEtherTypeMatch(matchBuilder, etherType).build());
1302 // Create the OF Actions and Instructions
1303 InstructionBuilder ib = new InstructionBuilder();
1304 InstructionsBuilder isb = new InstructionsBuilder();
1306 // Instructions List Stores Individual Instructions
1307 List<Instruction> instructions = Lists.newArrayList();
1309 // Call the InstructionBuilder Methods Containing Actions
1310 InstructionUtils.createSendToControllerInstructions(ib);
1312 ib.setKey(new InstructionKey(0));
1313 instructions.add(ib.build());
1315 // Add InstructionBuilder to the Instruction(s)Builder List
1316 isb.setInstruction(instructions);
1318 // Add InstructionsBuilder to FlowBuilder
1319 flowBuilder.setInstructions(isb.build());
1321 String flowId = "LLDP";
1322 flowBuilder.setId(new FlowId(flowId));
1323 FlowKey key = new FlowKey(new FlowId(flowId));
1324 flowBuilder.setBarrier(true);
1325 flowBuilder.setTableId((short) 0);
1326 flowBuilder.setKey(key);
1327 flowBuilder.setFlowName(flowId);
1328 flowBuilder.setHardTimeout(0);
1329 flowBuilder.setIdleTimeout(0);
1330 writeFlow(flowBuilder, nodeBuilder);
1334 * Create a NORMAL Table Miss Flow Rule
1336 * Action: forward to NORMAL pipeline
1339 private void writeNormalRule(Long dpidLong) {
1341 String nodeName = OPENFLOW + dpidLong;
1343 MatchBuilder matchBuilder = new MatchBuilder();
1344 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1345 FlowBuilder flowBuilder = new FlowBuilder();
1347 // Create the OF Actions and Instructions
1348 InstructionBuilder ib = new InstructionBuilder();
1349 InstructionsBuilder isb = new InstructionsBuilder();
1351 // Instructions List Stores Individual Instructions
1352 List<Instruction> instructions = Lists.newArrayList();
1354 // Call the InstructionBuilder Methods Containing Actions
1355 InstructionUtils.createNormalInstructions(ib);
1357 ib.setKey(new InstructionKey(0));
1358 instructions.add(ib.build());
1360 // Add InstructionBuilder to the Instruction(s)Builder List
1361 isb.setInstruction(instructions);
1363 // Add InstructionsBuilder to FlowBuilder
1364 flowBuilder.setInstructions(isb.build());
1366 String flowId = "NORMAL";
1367 flowBuilder.setId(new FlowId(flowId));
1368 FlowKey key = new FlowKey(new FlowId(flowId));
1369 flowBuilder.setMatch(matchBuilder.build());
1370 flowBuilder.setPriority(0);
1371 flowBuilder.setBarrier(true);
1372 flowBuilder.setTableId((short) 0);
1373 flowBuilder.setKey(key);
1374 flowBuilder.setFlowName(flowId);
1375 flowBuilder.setHardTimeout(0);
1376 flowBuilder.setIdleTimeout(0);
1377 writeFlow(flowBuilder, nodeBuilder);
1381 * (Table:0) Ingress Tunnel Traffic
1382 * Match: OpenFlow InPort and Tunnel ID
1383 * Action: GOTO Local Table (10)
1384 * table=0,tun_id=0x5,in_port=10, actions=goto_table:2
1387 private void handleTunnelIn(Long dpidLong, Short writeTable,
1388 Short goToTableId, String segmentationId,
1389 Long ofPort, boolean write) {
1391 String nodeName = OPENFLOW + dpidLong;
1393 BigInteger tunnelId = new BigInteger(segmentationId);
1394 MatchBuilder matchBuilder = new MatchBuilder();
1395 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1396 FlowBuilder flowBuilder = new FlowBuilder();
1398 // Create Match(es) and Set them in the FlowBuilder Object
1399 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, tunnelId).build());
1400 flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ofPort).build());
1403 // Create the OF Actions and Instructions
1404 InstructionBuilder ib = new InstructionBuilder();
1405 InstructionsBuilder isb = new InstructionsBuilder();
1407 // Instructions List Stores Individual Instructions
1408 List<Instruction> instructions = Lists.newArrayList();
1410 // Call the InstructionBuilder Methods Containing Actions
1411 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1413 ib.setKey(new InstructionKey(0));
1414 instructions.add(ib.build());
1416 // Add InstructionBuilder to the Instruction(s)Builder List
1417 isb.setInstruction(instructions);
1419 // Add InstructionsBuilder to FlowBuilder
1420 flowBuilder.setInstructions(isb.build());
1423 String flowId = "TunnelIn_"+segmentationId+"_"+ofPort;
1424 // Add Flow Attributes
1425 flowBuilder.setId(new FlowId(flowId));
1426 FlowKey key = new FlowKey(new FlowId(flowId));
1427 flowBuilder.setStrict(true);
1428 flowBuilder.setBarrier(false);
1429 flowBuilder.setTableId(writeTable);
1430 flowBuilder.setKey(key);
1431 flowBuilder.setFlowName(flowId);
1432 flowBuilder.setHardTimeout(0);
1433 flowBuilder.setIdleTimeout(0);
1436 writeFlow(flowBuilder, nodeBuilder);
1438 removeFlow(flowBuilder, nodeBuilder);
1443 * (Table:0) Ingress VLAN Traffic
1444 * Match: OpenFlow InPort and vlan ID
1445 * Action: GOTO Local Table (20)
1446 * table=0,vlan_id=0x5,in_port=10, actions=goto_table:2
1449 private void handleVlanIn(Long dpidLong, Short writeTable, Short goToTableId,
1450 String segmentationId, Long ethPort, boolean write) {
1452 String nodeName = OPENFLOW + dpidLong;
1454 MatchBuilder matchBuilder = new MatchBuilder();
1455 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1456 FlowBuilder flowBuilder = new FlowBuilder();
1458 // Create Match(es) and Set them in the FlowBuilder Object
1459 flowBuilder.setMatch(
1460 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)))
1462 .setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ethPort)
1466 // Create the OF Actions and Instructions
1467 InstructionBuilder ib = new InstructionBuilder();
1468 InstructionsBuilder isb = new InstructionsBuilder();
1470 // Instructions List Stores Individual Instructions
1471 List<Instruction> instructions = Lists.newArrayList();
1473 // Call the InstructionBuilder Methods Containing Actions
1474 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1476 ib.setKey(new InstructionKey(0));
1477 instructions.add(ib.build());
1479 // Add InstructionBuilder to the Instruction(s)Builder List
1480 isb.setInstruction(instructions);
1482 // Add InstructionsBuilder to FlowBuilder
1483 flowBuilder.setInstructions(isb.build());
1486 String flowId = "VlanIn_"+segmentationId+"_"+ethPort;
1487 // Add Flow Attributes
1488 flowBuilder.setId(new FlowId(flowId));
1489 FlowKey key = new FlowKey(new FlowId(flowId));
1490 flowBuilder.setStrict(true);
1491 flowBuilder.setBarrier(false);
1492 flowBuilder.setTableId(writeTable);
1493 flowBuilder.setKey(key);
1494 flowBuilder.setFlowName(flowId);
1495 flowBuilder.setHardTimeout(0);
1496 flowBuilder.setIdleTimeout(0);
1498 writeFlow(flowBuilder, nodeBuilder);
1500 removeFlow(flowBuilder, nodeBuilder);
1505 * (Table:0) Egress VM Traffic Towards TEP
1506 * Match: Destination Ethernet Addr and OpenFlow InPort
1507 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1508 * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
1509 * actions=set_field:5->tun_id,goto_table=1"
1512 private void handleLocalInPort(Long dpidLong, Short writeTable, Short goToTableId,
1513 String segmentationId, Long inPort, String attachedMac,
1516 String nodeName = OPENFLOW + dpidLong;
1518 MatchBuilder matchBuilder = new MatchBuilder();
1519 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1520 FlowBuilder flowBuilder = new FlowBuilder();
1522 // Create the OF Match using MatchBuilder
1523 flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
1524 // TODO Broken In_Port Match
1525 flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
1527 String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
1528 // Add Flow Attributes
1529 flowBuilder.setId(new FlowId(flowId));
1530 FlowKey key = new FlowKey(new FlowId(flowId));
1531 flowBuilder.setStrict(true);
1532 flowBuilder.setBarrier(false);
1533 flowBuilder.setTableId(writeTable);
1534 flowBuilder.setKey(key);
1535 flowBuilder.setFlowName(flowId);
1536 flowBuilder.setHardTimeout(0);
1537 flowBuilder.setIdleTimeout(0);
1540 // Instantiate the Builders for the OF Actions and Instructions
1541 InstructionBuilder ib = new InstructionBuilder();
1542 InstructionsBuilder isb = new InstructionsBuilder();
1544 // Instructions List Stores Individual Instructions
1545 List<Instruction> instructions = Lists.newArrayList();
1547 // GOTO Instructions Need to be added first to the List
1548 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1550 ib.setKey(new InstructionKey(0));
1551 instructions.add(ib.build());
1552 // TODO Broken SetTunID
1553 InstructionUtils.createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
1555 ib.setKey(new InstructionKey(1));
1556 instructions.add(ib.build());
1558 // Add InstructionBuilder to the Instruction(s)Builder List
1559 isb.setInstruction(instructions);
1561 // Add InstructionsBuilder to FlowBuilder
1562 flowBuilder.setInstructions(isb.build());
1564 writeFlow(flowBuilder, nodeBuilder);
1566 removeFlow(flowBuilder, nodeBuilder);
1571 * (Table:0) Egress VM Traffic Towards TEP
1572 * Match: Source Ethernet Addr and OpenFlow InPort
1573 * Instruction: Set VLANID and GOTO Table Egress (n)
1574 * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
1575 * actions=push_vlan, set_field:5->vlan_id,goto_table=1"
1578 private void handleLocalInPortSetVlan(Long dpidLong, Short writeTable,
1579 Short goToTableId, String segmentationId,
1580 Long inPort, String attachedMac,
1583 String nodeName = OPENFLOW + dpidLong;
1585 MatchBuilder matchBuilder = new MatchBuilder();
1586 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1587 FlowBuilder flowBuilder = new FlowBuilder();
1589 // Create the OF Match using MatchBuilder
1590 flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
1591 flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
1593 String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
1594 // Add Flow Attributes
1595 flowBuilder.setId(new FlowId(flowId));
1596 FlowKey key = new FlowKey(new FlowId(flowId));
1597 flowBuilder.setStrict(true);
1598 flowBuilder.setBarrier(false);
1599 flowBuilder.setTableId(writeTable);
1600 flowBuilder.setKey(key);
1601 flowBuilder.setFlowName(flowId);
1602 flowBuilder.setHardTimeout(0);
1603 flowBuilder.setIdleTimeout(0);
1606 // Instantiate the Builders for the OF Actions and Instructions
1607 InstructionBuilder ib = new InstructionBuilder();
1608 InstructionsBuilder isb = new InstructionsBuilder();
1610 // Instructions List Stores Individual Instructions
1611 List<Instruction> instructions = Lists.newArrayList();
1613 // GOTO Instructions Need to be added first to the List
1614 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1616 ib.setKey(new InstructionKey(0));
1617 instructions.add(ib.build());
1618 // Set VLAN ID Instruction
1619 InstructionUtils.createSetVlanInstructions(ib, new VlanId(Integer.valueOf(segmentationId)));
1621 ib.setKey(new InstructionKey(1));
1622 instructions.add(ib.build());
1624 // Add InstructionBuilder to the Instruction(s)Builder List
1625 isb.setInstruction(instructions);
1627 // Add InstructionsBuilder to FlowBuilder
1628 flowBuilder.setInstructions(isb.build());
1630 writeFlow(flowBuilder, nodeBuilder);
1632 removeFlow(flowBuilder, nodeBuilder);
1637 * (Table:0) Drop frames source from a VM that do not
1638 * match the associated MAC address of the local VM.
1639 * Match: Low priority anything not matching the VM SMAC
1641 * table=0,priority=16384,in_port=1 actions=drop"
1644 private void handleDropSrcIface(Long dpidLong, Long inPort, boolean write) {
1646 String nodeName = OPENFLOW + dpidLong;
1648 MatchBuilder matchBuilder = new MatchBuilder();
1649 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1650 FlowBuilder flowBuilder = new FlowBuilder();
1652 // Create the OF Match using MatchBuilder
1653 flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
1656 // Instantiate the Builders for the OF Actions and Instructions
1657 InstructionBuilder ib = new InstructionBuilder();
1658 InstructionsBuilder isb = new InstructionsBuilder();
1660 // Instructions List Stores Individual Instructions
1661 List<Instruction> instructions = Lists.newArrayList();
1663 // Call the InstructionBuilder Methods Containing Actions
1664 InstructionUtils.createDropInstructions(ib);
1666 ib.setKey(new InstructionKey(0));
1667 instructions.add(ib.build());
1669 // Add InstructionBuilder to the Instruction(s)Builder List
1670 isb.setInstruction(instructions);
1672 // Add InstructionsBuilder to FlowBuilder
1673 flowBuilder.setInstructions(isb.build());
1676 String flowId = "DropFilter_"+inPort;
1677 // Add Flow Attributes
1678 flowBuilder.setId(new FlowId(flowId));
1679 FlowKey key = new FlowKey(new FlowId(flowId));
1680 flowBuilder.setStrict(true);
1681 flowBuilder.setBarrier(false);
1682 flowBuilder.setTableId(TABLE_0_DEFAULT_INGRESS);
1683 flowBuilder.setKey(key);
1684 flowBuilder.setFlowName(flowId);
1685 flowBuilder.setPriority(8192);
1686 flowBuilder.setHardTimeout(0);
1687 flowBuilder.setIdleTimeout(0);
1689 writeFlow(flowBuilder, nodeBuilder);
1691 removeFlow(flowBuilder, nodeBuilder);
1696 * (Table:1) Egress Tunnel Traffic
1697 * Match: Destination Ethernet Addr and Local InPort
1698 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1699 * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
1700 * actions=output:10,goto_table:2"
1702 private void handleTunnelOut(Long dpidLong, Short writeTable,
1703 Short goToTableId, String segmentationId,
1704 Long OFPortOut, String attachedMac,
1707 String nodeName = OPENFLOW + dpidLong;
1709 MatchBuilder matchBuilder = new MatchBuilder();
1710 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1711 FlowBuilder flowBuilder = new FlowBuilder();
1713 // Create the OF Match using MatchBuilder
1714 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
1715 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
1717 String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+attachedMac;
1718 // Add Flow Attributes
1719 flowBuilder.setId(new FlowId(flowId));
1720 FlowKey key = new FlowKey(new FlowId(flowId));
1721 flowBuilder.setStrict(true);
1722 flowBuilder.setBarrier(false);
1723 flowBuilder.setTableId(writeTable);
1724 flowBuilder.setKey(key);
1725 flowBuilder.setFlowName(flowId);
1726 flowBuilder.setHardTimeout(0);
1727 flowBuilder.setIdleTimeout(0);
1730 // Instantiate the Builders for the OF Actions and Instructions
1731 InstructionBuilder ib = new InstructionBuilder();
1732 InstructionsBuilder isb = new InstructionsBuilder();
1734 // Instructions List Stores Individual Instructions
1735 List<Instruction> instructions = Lists.newArrayList();
1737 // GOTO Instructions
1738 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1740 ib.setKey(new InstructionKey(0));
1741 instructions.add(ib.build());
1742 // Set the Output Port/Iface
1743 InstructionUtils.createOutputPortInstructions(ib, dpidLong, OFPortOut);
1745 ib.setKey(new InstructionKey(1));
1746 instructions.add(ib.build());
1748 // Add InstructionBuilder to the Instruction(s)Builder List
1749 isb.setInstruction(instructions);
1751 // Add InstructionsBuilder to FlowBuilder
1752 flowBuilder.setInstructions(isb.build());
1754 writeFlow(flowBuilder, nodeBuilder);
1756 removeFlow(flowBuilder, nodeBuilder);
1761 * (Table:1) Egress VLAN Traffic
1762 * Match: Destination Ethernet Addr and VLAN id
1763 * Instruction: GOTO Table Table 2
1764 * table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
1765 * actions= goto_table:2"
1768 private void handleVlanOut(Long dpidLong, Short writeTable,
1769 Short goToTableId, String segmentationId,
1770 Long ethPort, String attachedMac, boolean write) {
1772 String nodeName = OPENFLOW + dpidLong;
1774 MatchBuilder matchBuilder = new MatchBuilder();
1775 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1776 FlowBuilder flowBuilder = new FlowBuilder();
1778 // Create the OF Match using MatchBuilder
1779 flowBuilder.setMatch(
1780 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
1781 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
1783 String flowId = "VlanOut_"+segmentationId+"_"+ethPort+"_"+attachedMac;
1784 // Add Flow Attributes
1785 flowBuilder.setId(new FlowId(flowId));
1786 FlowKey key = new FlowKey(new FlowId(flowId));
1787 flowBuilder.setStrict(true);
1788 flowBuilder.setBarrier(false);
1789 flowBuilder.setTableId(writeTable);
1790 flowBuilder.setKey(key);
1791 flowBuilder.setFlowName(flowId);
1792 flowBuilder.setHardTimeout(0);
1793 flowBuilder.setIdleTimeout(0);
1796 // Instantiate the Builders for the OF Actions and Instructions
1797 InstructionBuilder ib = new InstructionBuilder();
1798 InstructionsBuilder isb = new InstructionsBuilder();
1800 // Instructions List Stores Individual Instructions
1801 List<Instruction> instructions = Lists.newArrayList();
1803 // GOTO Instructions
1804 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
1806 ib.setKey(new InstructionKey(0));
1807 instructions.add(ib.build());
1809 // Add InstructionBuilder to the Instruction(s)Builder List
1810 isb.setInstruction(instructions);
1812 // Add InstructionsBuilder to FlowBuilder
1813 flowBuilder.setInstructions(isb.build());
1815 writeFlow(flowBuilder, nodeBuilder);
1817 removeFlow(flowBuilder, nodeBuilder);
1822 * (Table:1) Egress Tunnel Traffic
1823 * Match: Destination Ethernet Addr and Local InPort
1824 * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
1825 * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1826 * actions=output:10,output:11,goto_table:2
1829 private void handleTunnelFloodOut(Long dpidLong, Short writeTable,
1830 Short localTable, String segmentationId,
1831 Long OFPortOut, boolean write) {
1833 String nodeName = OPENFLOW + dpidLong;
1835 MatchBuilder matchBuilder = new MatchBuilder();
1836 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1837 FlowBuilder flowBuilder = new FlowBuilder();
1839 // Create the OF Match using MatchBuilder
1841 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
1844 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
1845 new MacAddress("01:00:00:00:00:00")).build());
1847 String flowId = "TunnelFloodOut_"+segmentationId;
1848 // Add Flow Attributes
1849 flowBuilder.setId(new FlowId(flowId));
1850 FlowKey key = new FlowKey(new FlowId(flowId));
1851 flowBuilder.setBarrier(true);
1852 flowBuilder.setTableId(writeTable);
1853 flowBuilder.setKey(key);
1854 flowBuilder.setPriority(16384);
1855 flowBuilder.setFlowName(flowId);
1856 flowBuilder.setHardTimeout(0);
1857 flowBuilder.setIdleTimeout(0);
1859 Flow flow = this.getFlow(flowBuilder, nodeBuilder);
1860 // Instantiate the Builders for the OF Actions and Instructions
1861 InstructionBuilder ib = new InstructionBuilder();
1862 InstructionsBuilder isb = new InstructionsBuilder();
1863 List<Instruction> instructions = Lists.newArrayList();
1864 List<Instruction> existingInstructions = null;
1866 Instructions ins = flow.getInstructions();
1868 existingInstructions = ins.getInstruction();
1874 InstructionUtils.createGotoTableInstructions(ib, localTable);
1876 ib.setKey(new InstructionKey(0));
1877 instructions.add(ib.build());
1878 // Set the Output Port/Iface
1879 //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, OFPortOut, existingInstructions);
1880 createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
1882 ib.setKey(new InstructionKey(1));
1883 instructions.add(ib.build());
1885 // Add InstructionBuilder to the Instruction(s)Builder List
1886 isb.setInstruction(instructions);
1888 // Add InstructionsBuilder to FlowBuilder
1889 flowBuilder.setInstructions(isb.build());
1891 writeFlow(flowBuilder, nodeBuilder);
1893 /* remove port from action list */
1894 boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
1895 OFPortOut, existingInstructions);
1897 /* if all port are removed, remove the flow too. */
1898 removeFlow(flowBuilder, nodeBuilder);
1900 /* Install instruction with new output port list*/
1902 ib.setKey(new InstructionKey(0));
1903 instructions.add(ib.build());
1905 // Add InstructionBuilder to the Instruction(s)Builder List
1906 isb.setInstruction(instructions);
1908 // Add InstructionsBuilder to FlowBuilder
1909 flowBuilder.setInstructions(isb.build());
1915 * (Table:1) Egress VLAN Traffic
1916 * Match: Destination Ethernet Addr and VLAN id
1917 * Instruction: GOTO table 2 and Output port eth interface
1918 * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
1919 * actions=output:eth1,goto_table:2
1922 private void handleVlanFloodOut(Long dpidLong, Short writeTable,
1923 Short localTable, String segmentationId,
1924 Long ethPort, boolean write) {
1926 String nodeName = OPENFLOW + dpidLong;
1928 MatchBuilder matchBuilder = new MatchBuilder();
1929 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1930 FlowBuilder flowBuilder = new FlowBuilder();
1932 // Create the OF Match using MatchBuilder
1934 flowBuilder.setMatch(
1935 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
1937 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
1938 new MacAddress("01:00:00:00:00:00")).build());
1940 String flowId = "VlanFloodOut_"+segmentationId;
1941 // Add Flow Attributes
1942 flowBuilder.setId(new FlowId(flowId));
1943 FlowKey key = new FlowKey(new FlowId(flowId));
1944 flowBuilder.setBarrier(true);
1945 flowBuilder.setTableId(writeTable);
1946 flowBuilder.setKey(key);
1947 flowBuilder.setPriority(16384);
1948 flowBuilder.setFlowName(flowId);
1949 flowBuilder.setHardTimeout(0);
1950 flowBuilder.setIdleTimeout(0);
1952 //ToDo: Is there something to be done with result of the call to getFlow?
1954 Flow flow = this.getFlow(flowBuilder, nodeBuilder);
1955 // Instantiate the Builders for the OF Actions and Instructions
1956 InstructionBuilder ib = new InstructionBuilder();
1957 InstructionsBuilder isb = new InstructionsBuilder();
1958 List<Instruction> instructions = Lists.newArrayList();
1962 InstructionUtils.createGotoTableInstructions(ib, localTable);
1964 ib.setKey(new InstructionKey(0));
1965 instructions.add(ib.build());
1966 // Set the Output Port/Iface
1967 InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
1969 ib.setKey(new InstructionKey(1));
1970 instructions.add(ib.build());
1972 // Add InstructionBuilder to the Instruction(s)Builder List
1973 isb.setInstruction(instructions);
1975 // Add InstructionsBuilder to FlowBuilder
1976 flowBuilder.setInstructions(isb.build());
1978 writeFlow(flowBuilder, nodeBuilder);
1980 removeFlow(flowBuilder, nodeBuilder);
1985 * (Table:1) Table Drain w/ Catch All
1987 * Action: GOTO Local Table (10)
1988 * table=2,priority=8192,tun_id=0x5 actions=drop
1991 private void handleTunnelMiss(Long dpidLong, Short writeTable,
1992 Short goToTableId, String segmentationId,
1995 String nodeName = OPENFLOW + dpidLong;
1997 MatchBuilder matchBuilder = new MatchBuilder();
1998 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
1999 FlowBuilder flowBuilder = new FlowBuilder();
2001 // Create Match(es) and Set them in the FlowBuilder Object
2002 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
2005 // Create the OF Actions and Instructions
2006 InstructionBuilder ib = new InstructionBuilder();
2007 InstructionsBuilder isb = new InstructionsBuilder();
2009 // Instructions List Stores Individual Instructions
2010 List<Instruction> instructions = Lists.newArrayList();
2012 // Call the InstructionBuilder Methods Containing Actions
2013 InstructionUtils.createGotoTableInstructions(ib, goToTableId);
2015 ib.setKey(new InstructionKey(0));
2016 instructions.add(ib.build());
2018 // Add InstructionBuilder to the Instruction(s)Builder List
2019 isb.setInstruction(instructions);
2021 // Add InstructionsBuilder to FlowBuilder
2022 flowBuilder.setInstructions(isb.build());
2025 String flowId = "TunnelMiss_"+segmentationId;
2026 // Add Flow Attributes
2027 flowBuilder.setId(new FlowId(flowId));
2028 FlowKey key = new FlowKey(new FlowId(flowId));
2029 flowBuilder.setStrict(true);
2030 flowBuilder.setBarrier(false);
2031 flowBuilder.setTableId(writeTable);
2032 flowBuilder.setKey(key);
2033 flowBuilder.setPriority(8192);
2034 flowBuilder.setFlowName(flowId);
2035 flowBuilder.setHardTimeout(0);
2036 flowBuilder.setIdleTimeout(0);
2038 writeFlow(flowBuilder, nodeBuilder);
2040 removeFlow(flowBuilder, nodeBuilder);
2046 * (Table:1) Table Drain w/ Catch All
2048 * Action: Output port eth interface
2049 * table=1,priority=8192,vlan_id=0x5 actions= output port:eth1
2052 private void handleVlanMiss(Long dpidLong, Short writeTable,
2053 Short goToTableId, String segmentationId,
2054 Long ethPort, boolean write) {
2056 String nodeName = OPENFLOW + dpidLong;
2058 MatchBuilder matchBuilder = new MatchBuilder();
2059 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2060 FlowBuilder flowBuilder = new FlowBuilder();
2062 // Create Match(es) and Set them in the FlowBuilder Object
2063 flowBuilder.setMatch(
2064 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
2067 // Create the OF Actions and Instructions
2068 InstructionBuilder ib = new InstructionBuilder();
2069 InstructionsBuilder isb = new InstructionsBuilder();
2071 // Instructions List Stores Individual Instructions
2072 List<Instruction> instructions = Lists.newArrayList();
2074 // Call the InstructionBuilder Methods Containing Actions
2075 //createGotoTableInstructions(ib, goToTableId);
2077 //ib.setKey(new InstructionKey(0));
2078 //instructions.add(ib.build());
2079 // Set the Output Port/Iface
2080 InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
2082 ib.setKey(new InstructionKey(1));
2083 instructions.add(ib.build());
2085 // Add InstructionBuilder to the Instruction(s)Builder List
2086 isb.setInstruction(instructions);
2088 // Add InstructionsBuilder to FlowBuilder
2089 flowBuilder.setInstructions(isb.build());
2092 String flowId = "VlanMiss_"+segmentationId;
2093 // Add Flow Attributes
2094 flowBuilder.setId(new FlowId(flowId));
2095 FlowKey key = new FlowKey(new FlowId(flowId));
2096 flowBuilder.setStrict(true);
2097 flowBuilder.setBarrier(false);
2098 flowBuilder.setTableId(writeTable);
2099 flowBuilder.setKey(key);
2100 flowBuilder.setPriority(8192);
2101 flowBuilder.setFlowName(flowId);
2102 flowBuilder.setHardTimeout(0);
2103 flowBuilder.setIdleTimeout(0);
2105 writeFlow(flowBuilder, nodeBuilder);
2107 removeFlow(flowBuilder, nodeBuilder);
2112 * (Table:1) Local Broadcast Flood
2113 * Match: Tunnel ID and dMAC
2114 * Action: Output Port
2115 * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
2118 private void handleLocalUcastOut(Long dpidLong, Short writeTable,
2119 String segmentationId, Long localPort,
2120 String attachedMac, boolean write) {
2122 String nodeName = OPENFLOW + dpidLong;
2124 MatchBuilder matchBuilder = new MatchBuilder();
2125 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2126 FlowBuilder flowBuilder = new FlowBuilder();
2128 // Create the OF Match using MatchBuilder
2129 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
2130 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
2132 String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
2133 // Add Flow Attributes
2134 flowBuilder.setId(new FlowId(flowId));
2135 FlowKey key = new FlowKey(new FlowId(flowId));
2136 flowBuilder.setStrict(true);
2137 flowBuilder.setBarrier(false);
2138 flowBuilder.setTableId(writeTable);
2139 flowBuilder.setKey(key);
2140 flowBuilder.setFlowName(flowId);
2141 flowBuilder.setHardTimeout(0);
2142 flowBuilder.setIdleTimeout(0);
2145 // Instantiate the Builders for the OF Actions and Instructions
2146 InstructionBuilder ib = new InstructionBuilder();
2147 InstructionsBuilder isb = new InstructionsBuilder();
2149 // Instructions List Stores Individual Instructions
2150 List<Instruction> instructions = Lists.newArrayList();
2152 // Set the Output Port/Iface
2153 InstructionUtils.createOutputPortInstructions(ib, dpidLong, localPort);
2155 ib.setKey(new InstructionKey(0));
2156 instructions.add(ib.build());
2158 // Add InstructionBuilder to the Instruction(s)Builder List
2159 isb.setInstruction(instructions);
2161 // Add InstructionsBuilder to FlowBuilder
2162 flowBuilder.setInstructions(isb.build());
2163 writeFlow(flowBuilder, nodeBuilder);
2165 removeFlow(flowBuilder, nodeBuilder);
2170 * (Table:2) Local VLAN unicast
2171 * Match: VLAN ID and dMAC
2172 * Action: Output Port
2173 * table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
2176 private void handleLocalVlanUcastOut(Long dpidLong, Short writeTable,
2177 String segmentationId, Long localPort,
2178 String attachedMac, boolean write) {
2180 String nodeName = OPENFLOW + dpidLong;
2182 MatchBuilder matchBuilder = new MatchBuilder();
2183 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2184 FlowBuilder flowBuilder = new FlowBuilder();
2186 // Create the OF Match using MatchBuilder
2187 flowBuilder.setMatch(
2188 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
2189 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
2191 String flowId = "VlanUcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
2192 // Add Flow Attributes
2193 flowBuilder.setId(new FlowId(flowId));
2194 FlowKey key = new FlowKey(new FlowId(flowId));
2195 flowBuilder.setStrict(true);
2196 flowBuilder.setBarrier(false);
2197 flowBuilder.setTableId(writeTable);
2198 flowBuilder.setKey(key);
2199 flowBuilder.setFlowName(flowId);
2200 flowBuilder.setHardTimeout(0);
2201 flowBuilder.setIdleTimeout(0);
2204 // Instantiate the Builders for the OF Actions and Instructions
2205 InstructionBuilder ib = new InstructionBuilder();
2206 InstructionsBuilder isb = new InstructionsBuilder();
2208 // Instructions List Stores Individual Instructions
2209 List<Instruction> instructions = Lists.newArrayList();
2210 List<Instruction> instructions_tmp = Lists.newArrayList();
2212 /* Strip vlan and store to tmp instruction space*/
2213 InstructionUtils.createPopVlanInstructions(ib);
2215 ib.setKey(new InstructionKey(0));
2216 instructions_tmp.add(ib.build());
2218 // Set the Output Port/Iface
2219 ib = new InstructionBuilder();
2220 InstructionUtils.addOutputPortInstructions(ib, dpidLong, localPort, instructions_tmp);
2222 ib.setKey(new InstructionKey(0));
2223 instructions.add(ib.build());
2225 // Add InstructionBuilder to the Instruction(s)Builder List
2226 isb.setInstruction(instructions);
2228 // Add InstructionsBuilder to FlowBuilder
2229 flowBuilder.setInstructions(isb.build());
2230 writeFlow(flowBuilder, nodeBuilder);
2232 removeFlow(flowBuilder, nodeBuilder);
2237 * (Table:2) Local Broadcast Flood
2238 * Match: Tunnel ID and dMAC (::::FF:FF)
2239 * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
2240 * actions=output:2,3,4,5
2243 private void handleLocalBcastOut(Long dpidLong, Short writeTable,
2244 String segmentationId, Long localPort,
2247 String nodeName = OPENFLOW + dpidLong;
2249 MatchBuilder matchBuilder = new MatchBuilder();
2250 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2251 FlowBuilder flowBuilder = new FlowBuilder();
2253 // Create the OF Match using MatchBuilder
2254 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
2255 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
2256 new MacAddress("01:00:00:00:00:00")).build());
2258 String flowId = "BcastOut_"+segmentationId;
2259 // Add Flow Attributes
2260 flowBuilder.setId(new FlowId(flowId));
2261 FlowKey key = new FlowKey(new FlowId(flowId));
2262 flowBuilder.setStrict(true);
2263 flowBuilder.setBarrier(false);
2264 flowBuilder.setTableId(writeTable);
2265 flowBuilder.setKey(key);
2266 flowBuilder.setPriority(16384);
2267 flowBuilder.setFlowName(flowId);
2268 flowBuilder.setHardTimeout(0);
2269 flowBuilder.setIdleTimeout(0);
2270 Flow flow = this.getFlow(flowBuilder, nodeBuilder);
2271 // Instantiate the Builders for the OF Actions and Instructions
2272 InstructionBuilder ib = new InstructionBuilder();
2273 InstructionsBuilder isb = new InstructionsBuilder();
2274 List<Instruction> instructions = Lists.newArrayList();
2275 List<Instruction> existingInstructions = null;
2277 Instructions ins = flow.getInstructions();
2279 existingInstructions = ins.getInstruction();
2284 // Create output port list
2285 createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
2287 ib.setKey(new InstructionKey(0));
2288 instructions.add(ib.build());
2290 // Add InstructionBuilder to the Instruction(s)Builder List
2291 isb.setInstruction(instructions);
2293 // Add InstructionsBuilder to FlowBuilder
2294 flowBuilder.setInstructions(isb.build());
2296 writeFlow(flowBuilder, nodeBuilder);
2298 boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong, localPort,
2299 existingInstructions);
2301 /* if all ports are removed, remove flow */
2302 removeFlow(flowBuilder, nodeBuilder);
2304 /* Install instruction with new output port list*/
2306 ib.setKey(new InstructionKey(0));
2307 instructions.add(ib.build());
2309 // Add InstructionBuilder to the Instruction(s)Builder List
2310 isb.setInstruction(instructions);
2312 // Add InstructionsBuilder to FlowBuilder
2313 flowBuilder.setInstructions(isb.build());
2315 writeFlow(flowBuilder, nodeBuilder);
2321 * (Table:2) Local VLAN Broadcast Flood
2322 * Match: vlan ID and dMAC (::::FF:FF)
2323 * table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
2324 * actions=strip_vlan, output:2,3,4,5
2327 private void handleLocalVlanBcastOut(Long dpidLong, Short writeTable,
2328 String segmentationId, Long localPort,
2331 String nodeName = OPENFLOW + dpidLong;
2333 MatchBuilder matchBuilder = new MatchBuilder();
2334 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2335 FlowBuilder flowBuilder = new FlowBuilder();
2337 // Create the OF Match using MatchBuilder
2338 flowBuilder.setMatch(
2339 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
2340 flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
2341 new MacAddress("01:00:00:00:00:00")).build());
2343 String flowId = "VlanBcastOut_"+segmentationId;
2344 // Add Flow Attributes
2345 flowBuilder.setId(new FlowId(flowId));
2346 FlowKey key = new FlowKey(new FlowId(flowId));
2347 flowBuilder.setStrict(true);
2348 flowBuilder.setBarrier(false);
2349 flowBuilder.setTableId(writeTable);
2350 flowBuilder.setKey(key);
2351 flowBuilder.setPriority(16384);
2352 flowBuilder.setFlowName(flowId);
2353 flowBuilder.setHardTimeout(0);
2354 flowBuilder.setIdleTimeout(0);
2355 Flow flow = this.getFlow(flowBuilder, nodeBuilder);
2356 // Instantiate the Builders for the OF Actions and Instructions
2357 InstructionBuilder ib = new InstructionBuilder();
2358 InstructionsBuilder isb = new InstructionsBuilder();
2359 List<Instruction> instructions = Lists.newArrayList();
2360 List<Instruction> existingInstructions = null;
2361 boolean add_pop_vlan = true;
2363 Instructions ins = flow.getInstructions();
2365 existingInstructions = ins.getInstruction();
2370 if (existingInstructions != null) {
2371 /* Check if pop vlan is already the first action in action list */
2372 List<Action> existingActions;
2373 for (Instruction in : existingInstructions) {
2374 if (in.getInstruction() instanceof ApplyActionsCase) {
2375 existingActions = (((ApplyActionsCase)
2376 in.getInstruction()).getApplyActions().getAction());
2377 if (existingActions.get(0).getAction() instanceof PopVlanActionCase) {
2378 add_pop_vlan = false;
2384 existingInstructions = Lists.newArrayList();
2389 InstructionUtils.createPopVlanInstructions(ib);
2391 ib.setKey(new InstructionKey(0));
2392 existingInstructions.add(ib.build());
2393 ib = new InstructionBuilder();
2397 //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, localPort, existingInstructions);
2398 createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
2400 ib.setKey(new InstructionKey(0));
2401 instructions.add(ib.build());
2403 // Add InstructionBuilder to the Instruction(s)Builder List
2404 isb.setInstruction(instructions);
2406 // Add InstructionsBuilder to FlowBuilder
2407 flowBuilder.setInstructions(isb.build());
2409 writeFlow(flowBuilder, nodeBuilder);
2411 //boolean flowRemove = removeOutputPortFromGroup(nodeBuilder, ib, dpidLong,
2412 // localPort, existingInstructions);
2413 boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
2414 localPort, existingInstructions);
2416 /* if all ports are removed, remove flow */
2417 removeFlow(flowBuilder, nodeBuilder);
2419 /* Install instruction with new output port list*/
2421 ib.setKey(new InstructionKey(0));
2422 instructions.add(ib.build());
2424 // Add InstructionBuilder to the Instruction(s)Builder List
2425 isb.setInstruction(instructions);
2427 // Add InstructionsBuilder to FlowBuilder
2428 flowBuilder.setInstructions(isb.build());
2429 writeFlow(flowBuilder, nodeBuilder);
2435 * (Table:1) Local Table Miss
2436 * Match: Any Remaining Flows w/a TunID
2437 * Action: Drop w/ a low priority
2438 * table=2,priority=8192,tun_id=0x5 actions=drop
2441 private void handleLocalTableMiss(Long dpidLong, Short writeTable,
2442 String segmentationId, boolean write) {
2444 String nodeName = OPENFLOW + dpidLong;
2446 MatchBuilder matchBuilder = new MatchBuilder();
2447 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2448 FlowBuilder flowBuilder = new FlowBuilder();
2450 // Create Match(es) and Set them in the FlowBuilder Object
2451 flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
2454 // Create the OF Actions and Instructions
2455 InstructionBuilder ib = new InstructionBuilder();
2456 InstructionsBuilder isb = new InstructionsBuilder();
2458 // Instructions List Stores Individual Instructions
2459 List<Instruction> instructions = Lists.newArrayList();
2461 // Call the InstructionBuilder Methods Containing Actions
2462 InstructionUtils.createDropInstructions(ib);
2464 ib.setKey(new InstructionKey(0));
2465 instructions.add(ib.build());
2467 // Add InstructionBuilder to the Instruction(s)Builder List
2468 isb.setInstruction(instructions);
2470 // Add InstructionsBuilder to FlowBuilder
2471 flowBuilder.setInstructions(isb.build());
2474 String flowId = "LocalTableMiss_"+segmentationId;
2475 // Add Flow Attributes
2476 flowBuilder.setId(new FlowId(flowId));
2477 FlowKey key = new FlowKey(new FlowId(flowId));
2478 flowBuilder.setStrict(true);
2479 flowBuilder.setBarrier(false);
2480 flowBuilder.setTableId(writeTable);
2481 flowBuilder.setKey(key);
2482 flowBuilder.setPriority(8192);
2483 flowBuilder.setFlowName(flowId);
2484 flowBuilder.setHardTimeout(0);
2485 flowBuilder.setIdleTimeout(0);
2487 writeFlow(flowBuilder, nodeBuilder);
2489 removeFlow(flowBuilder, nodeBuilder);
2494 * (Table:1) Local Table Miss
2495 * Match: Any Remaining Flows w/a VLAN ID
2496 * Action: Drop w/ a low priority
2497 * table=2,priority=8192,vlan_id=0x5 actions=drop
2500 private void handleLocalVlanTableMiss(Long dpidLong, Short writeTable,
2501 String segmentationId, boolean write) {
2503 String nodeName = OPENFLOW + dpidLong;
2505 MatchBuilder matchBuilder = new MatchBuilder();
2506 NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
2507 FlowBuilder flowBuilder = new FlowBuilder();
2509 // Create Match(es) and Set them in the FlowBuilder Object
2510 flowBuilder.setMatch(
2511 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
2514 // Create the OF Actions and Instructions
2515 InstructionBuilder ib = new InstructionBuilder();
2516 InstructionsBuilder isb = new InstructionsBuilder();
2518 // Instructions List Stores Individual Instructions
2519 List<Instruction> instructions = Lists.newArrayList();
2521 // Call the InstructionBuilder Methods Containing Actions
2522 InstructionUtils.createDropInstructions(ib);
2524 ib.setKey(new InstructionKey(0));
2525 instructions.add(ib.build());
2527 // Add InstructionBuilder to the Instruction(s)Builder List
2528 isb.setInstruction(instructions);
2530 // Add InstructionsBuilder to FlowBuilder
2531 flowBuilder.setInstructions(isb.build());
2534 String flowId = "LocalTableMiss_"+segmentationId;
2535 // Add Flow Attributes
2536 flowBuilder.setId(new FlowId(flowId));
2537 FlowKey key = new FlowKey(new FlowId(flowId));
2538 flowBuilder.setStrict(true);
2539 flowBuilder.setBarrier(false);
2540 flowBuilder.setTableId(writeTable);
2541 flowBuilder.setKey(key);
2542 flowBuilder.setPriority(8192);
2543 flowBuilder.setFlowName(flowId);
2544 flowBuilder.setHardTimeout(0);
2545 flowBuilder.setIdleTimeout(0);
2547 writeFlow(flowBuilder, nodeBuilder);
2549 removeFlow(flowBuilder, nodeBuilder);
2553 private Group getGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
2554 Preconditions.checkNotNull(mdsalConsumer);
2555 if (mdsalConsumer == null) {
2556 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
2560 dataBroker = mdsalConsumer.getDataBroker();
2561 if (dataBroker == null) {
2562 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2566 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2567 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
2568 new GroupKey(groupBuilder.getGroupId())).build();
2569 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
2571 Optional<Group> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
2572 if (data.isPresent()) {
2575 } catch (InterruptedException|ExecutionException e) {
2576 logger.error(e.getMessage(), e);
2579 logger.debug("Cannot find data for Group " + groupBuilder.getGroupName());
2583 private void writeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
2584 Preconditions.checkNotNull(mdsalConsumer);
2585 if (mdsalConsumer == null) {
2586 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
2590 dataBroker = mdsalConsumer.getDataBroker();
2591 if (dataBroker == null) {
2592 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2596 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
2597 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2598 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
2599 new GroupKey(groupBuilder.getGroupId())).build();
2600 modification.put(LogicalDatastoreType.CONFIGURATION, path1, groupBuilder.build(), true /*createMissingParents*/);
2602 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
2604 commitFuture.get(); // TODO: Make it async (See bug 1362)
2605 logger.debug("Transaction success for write of Group "+groupBuilder.getGroupName());
2606 } catch (InterruptedException|ExecutionException e) {
2607 logger.error(e.getMessage(), e);
2611 private void removeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
2612 Preconditions.checkNotNull(mdsalConsumer);
2613 if (mdsalConsumer == null) {
2614 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
2618 dataBroker = mdsalConsumer.getDataBroker();
2619 if (dataBroker == null) {
2620 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2624 WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
2625 InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2626 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
2627 new GroupKey(groupBuilder.getGroupId())).build();
2628 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
2629 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
2632 commitFuture.get(); // TODO: Make it async (See bug 1362)
2633 logger.debug("Transaction success for deletion of Group "+groupBuilder.getGroupName());
2634 } catch (InterruptedException|ExecutionException e) {
2635 logger.error(e.getMessage(), e);
2638 private Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
2639 Preconditions.checkNotNull(mdsalConsumer);
2640 if (mdsalConsumer == null) {
2641 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
2645 dataBroker = mdsalConsumer.getDataBroker();
2646 if (dataBroker == null) {
2647 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2651 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2652 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
2653 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
2655 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
2657 Optional<Flow> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
2658 if (data.isPresent()) {
2661 } catch (InterruptedException|ExecutionException e) {
2662 logger.error(e.getMessage(), e);
2665 logger.debug("Cannot find data for Flow " + flowBuilder.getFlowName());
2669 private void writeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
2670 Preconditions.checkNotNull(mdsalConsumer);
2671 if (mdsalConsumer == null) {
2672 logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
2676 dataBroker = mdsalConsumer.getDataBroker();
2677 if (dataBroker == null) {
2678 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2682 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
2683 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2684 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
2685 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
2687 //modification.put(LogicalDatastoreType.OPERATIONAL, path1, flowBuilder.build());
2688 modification.put(LogicalDatastoreType.CONFIGURATION, path1, flowBuilder.build(), true /*createMissingParents*/);
2691 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
2693 commitFuture.get(); // TODO: Make it async (See bug 1362)
2694 logger.debug("Transaction success for write of Flow "+flowBuilder.getFlowName());
2695 } catch (InterruptedException|ExecutionException e) {
2696 logger.error(e.getMessage(), e);
2700 private void removeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
2701 Preconditions.checkNotNull(mdsalConsumer);
2702 if (mdsalConsumer == null) {
2703 logger.error("ERROR finding MDSAL Service.");
2707 dataBroker = mdsalConsumer.getDataBroker();
2708 if (dataBroker == null) {
2709 logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
2713 WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
2714 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
2715 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
2716 .rev130819.nodes.Node.class, nodeBuilder.getKey())
2717 .augmentation(FlowCapableNode.class).child(Table.class,
2718 new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
2719 //modification.delete(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder));
2720 //modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
2721 //modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder));
2722 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
2724 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
2726 commitFuture.get(); // TODO: Make it async (See bug 1362)
2727 logger.debug("Transaction success for deletion of Flow "+flowBuilder.getFlowName());
2728 } catch (InterruptedException|ExecutionException e) {
2729 logger.error(e.getMessage(), e);
2734 * Create Output Port Group Instruction
2736 * @param ib Map InstructionBuilder without any instructions
2737 * @param dpidLong Long the datapath ID of a switch/node
2738 * @param port Long representing a port on a switch/node
2739 * @return ib InstructionBuilder Map with instructions
2741 protected InstructionBuilder createOutputPortInstructions(InstructionBuilder ib,
2742 Long dpidLong, Long port ,
2743 List<Instruction> instructions) {
2744 NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
2745 logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
2747 List<Action> actionList = Lists.newArrayList();
2748 ActionBuilder ab = new ActionBuilder();
2750 List<Action> existingActions;
2751 if (instructions != null) {
2752 for (Instruction in : instructions) {
2753 if (in.getInstruction() instanceof ApplyActionsCase) {
2754 existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
2755 actionList.addAll(existingActions);
2759 /* Create output action for this port*/
2760 OutputActionBuilder oab = new OutputActionBuilder();
2761 oab.setOutputNodeConnector(ncid);
2762 ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
2763 boolean addNew = true;
2765 /* Find the group action and get the group */
2766 for (Action action : actionList) {
2767 if (action.getAction() instanceof OutputActionCase) {
2768 OutputActionCase opAction = (OutputActionCase)action.getAction();
2769 /* If output port action already in the action list of one of the buckets, skip */
2770 if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
2777 ab.setOrder(actionList.size());
2778 ab.setKey(new ActionKey(actionList.size()));
2779 actionList.add(ab.build());
2781 // Create an Apply Action
2782 ApplyActionsBuilder aab = new ApplyActionsBuilder();
2783 aab.setAction(actionList);
2784 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2785 logger.debug("createOutputPortInstructions() : applyAction {}", aab.build());
2790 * Create Output Port Group Instruction
2792 * @param ib Map InstructionBuilder without any instructions
2793 * @param dpidLong Long the datapath ID of a switch/node
2794 * @param port Long representing a port on a switch/node
2795 * @return ib InstructionBuilder Map with instructions
2797 protected InstructionBuilder createOutputGroupInstructions(NodeBuilder nodeBuilder,
2798 InstructionBuilder ib,
2799 Long dpidLong, Long port ,
2800 List<Instruction> instructions) {
2801 NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
2802 logger.debug("createOutputGroupInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
2804 List<Action> actionList = Lists.newArrayList();
2805 ActionBuilder ab = new ActionBuilder();
2807 List<Action> existingActions;
2808 if (instructions != null) {
2809 for (Instruction in : instructions) {
2810 if (in.getInstruction() instanceof ApplyActionsCase) {
2811 existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
2812 actionList.addAll(existingActions);
2817 GroupBuilder groupBuilder = new GroupBuilder();
2820 /* Create output action for this port*/
2821 OutputActionBuilder oab = new OutputActionBuilder();
2822 oab.setOutputNodeConnector(ncid);
2823 ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
2824 logger.debug("createOutputGroupInstructions(): output action {}", ab.build());
2825 boolean addNew = true;
2826 boolean groupActionAdded = false;
2828 /* Find the group action and get the group */
2829 for (Action action : actionList) {
2830 if (action.getAction() instanceof GroupActionCase) {
2831 groupActionAdded = true;
2832 GroupActionCase groupAction = (GroupActionCase) action.getAction();
2833 Long id = groupAction.getGroupAction().getGroupId();
2834 String groupName = groupAction.getGroupAction().getGroup();
2835 GroupKey key = new GroupKey(new GroupId(id));
2837 groupBuilder.setGroupId(new GroupId(id));
2838 groupBuilder.setGroupName(groupName);
2839 groupBuilder.setGroupType(GroupTypes.GroupAll);
2840 groupBuilder.setKey(key);
2841 group = getGroup(groupBuilder, nodeBuilder);
2842 logger.debug("createOutputGroupInstructions: group {}", group);
2847 logger.debug("createOutputGroupInstructions: groupActionAdded {}", groupActionAdded);
2848 if (groupActionAdded) {
2849 /* modify the action bucket in group */
2850 groupBuilder = new GroupBuilder(group);
2851 Buckets buckets = groupBuilder.getBuckets();
2852 for (Bucket bucket : buckets.getBucket()) {
2853 List<Action> bucketActions = bucket.getAction();
2854 logger.debug("createOutputGroupInstructions: bucketActions {}", bucketActions);
2855 for (Action action : bucketActions) {
2856 if (action.getAction() instanceof OutputActionCase) {
2857 OutputActionCase opAction = (OutputActionCase)action.getAction();
2858 /* If output port action already in the action list of one of the buckets, skip */
2859 if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
2866 logger.debug("createOutputGroupInstructions: addNew {}", addNew);
2868 /* the new output action is not in the bucket, add to bucket */
2869 if (!buckets.getBucket().isEmpty()) {
2870 Bucket bucket = buckets.getBucket().get(0);
2871 List<Action> bucketActionList = Lists.newArrayList();
2872 bucketActionList.addAll(bucket.getAction());
2873 /* set order for new action and add to action list */
2874 ab.setOrder(bucketActionList.size());
2875 ab.setKey(new ActionKey(bucketActionList.size()));
2876 bucketActionList.add(ab.build());
2878 /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
2879 BucketsBuilder bucketsBuilder = new BucketsBuilder();
2880 List<Bucket> bucketList = Lists.newArrayList();
2881 BucketBuilder bucketBuilder = new BucketBuilder();
2882 bucketBuilder.setBucketId(new BucketId((long) 1));
2883 bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
2884 bucketBuilder.setAction(bucketActionList);
2885 bucketList.add(bucketBuilder.build());
2886 bucketsBuilder.setBucket(bucketList);
2887 groupBuilder.setBuckets(bucketsBuilder.build());
2888 logger.debug("createOutputGroupInstructions: bucketList {}", bucketList);
2893 groupBuilder = new GroupBuilder();
2894 groupBuilder.setGroupType(GroupTypes.GroupAll);
2895 groupBuilder.setGroupId(new GroupId(groupId));
2896 groupBuilder.setKey(new GroupKey(new GroupId(groupId)));
2897 groupBuilder.setGroupName("Output port group " + groupId);
2898 groupBuilder.setBarrier(false);
2900 BucketsBuilder bucketBuilder = new BucketsBuilder();
2901 List<Bucket> bucketList = Lists.newArrayList();
2902 BucketBuilder bucket = new BucketBuilder();
2903 bucket.setBucketId(new BucketId((long) 1));
2904 bucket.setKey(new BucketKey(new BucketId((long) 1)));
2906 /* put output action to the bucket */
2907 List<Action> bucketActionList = Lists.newArrayList();
2908 /* set order for new action and add to action list */
2909 ab.setOrder(bucketActionList.size());
2910 ab.setKey(new ActionKey(bucketActionList.size()));
2911 bucketActionList.add(ab.build());
2913 bucket.setAction(bucketActionList);
2914 bucketList.add(bucket.build());
2915 bucketBuilder.setBucket(bucketList);
2916 groupBuilder.setBuckets(bucketBuilder.build());
2918 /* Add new group action */
2919 GroupActionBuilder groupActionB = new GroupActionBuilder();
2920 groupActionB.setGroupId(groupId);
2921 groupActionB.setGroup("Output port group " + groupId);
2922 ab = new ActionBuilder();
2923 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
2924 ab.setOrder(actionList.size());
2925 ab.setKey(new ActionKey(actionList.size()));
2926 actionList.add(ab.build());
2930 logger.debug("createOutputGroupInstructions: group {}", groupBuilder.build());
2931 logger.debug("createOutputGroupInstructions: actionList {}", actionList);
2934 /* rewrite the group to group table */
2935 writeGroup(groupBuilder, nodeBuilder);
2938 // Create an Apply Action
2939 ApplyActionsBuilder aab = new ApplyActionsBuilder();
2940 aab.setAction(actionList);
2941 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2947 * Remove Output Port from action list in group bucket
2949 * @param ib Map InstructionBuilder without any instructions
2950 * @param dpidLong Long the datapath ID of a switch/node
2951 * @param port Long representing a port on a switch/node
2952 * @return ib InstructionBuilder Map with instructions
2954 protected boolean removeOutputPortFromGroup(NodeBuilder nodeBuilder, InstructionBuilder ib,
2955 Long dpidLong, Long port , List<Instruction> instructions) {
2957 NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
2958 logger.debug("removeOutputPortFromGroup() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
2960 List<Action> actionList = Lists.newArrayList();
2963 List<Action> existingActions;
2964 if (instructions != null) {
2965 for (Instruction in : instructions) {
2966 if (in.getInstruction() instanceof ApplyActionsCase) {
2967 existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
2968 actionList.addAll(existingActions);
2974 GroupBuilder groupBuilder = new GroupBuilder();
2976 boolean groupActionAdded = false;
2977 /* Find the group action and get the group */
2978 for (Action action : actionList) {
2979 if (action.getAction() instanceof GroupActionCase) {
2980 groupActionAdded = true;
2981 GroupActionCase groupAction = (GroupActionCase) action.getAction();
2982 Long id = groupAction.getGroupAction().getGroupId();
2983 String groupName = groupAction.getGroupAction().getGroup();
2984 GroupKey key = new GroupKey(new GroupId(id));
2986 groupBuilder.setGroupId(new GroupId(id));
2987 groupBuilder.setGroupName(groupName);
2988 groupBuilder.setGroupType(GroupTypes.GroupAll);
2989 groupBuilder.setKey(key);
2990 group = getGroup(groupBuilder, nodeBuilder);
2995 if (groupActionAdded) {
2996 /* modify the action bucket in group */
2997 groupBuilder = new GroupBuilder(group);
2998 Buckets buckets = groupBuilder.getBuckets();
2999 List<Action> bucketActions = Lists.newArrayList();
3000 for (Bucket bucket : buckets.getBucket()) {
3002 boolean isPortDeleted = false;
3003 bucketActions = bucket.getAction();
3004 for (Action action : bucketActions) {
3005 if (action.getAction() instanceof OutputActionCase) {
3006 OutputActionCase opAction = (OutputActionCase)action.getAction();
3007 if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
3008 /* Find the output port in action list and remove */
3009 index = bucketActions.indexOf(action);
3010 bucketActions.remove(action);
3011 isPortDeleted = true;
3016 if (isPortDeleted && !bucketActions.isEmpty()) {
3017 for (int i = index; i< bucketActions.size(); i++) {
3018 Action action = bucketActions.get(i);
3019 if (action.getOrder() != i) {
3020 /* Shift the action order */
3021 ab = new ActionBuilder();
3022 ab.setAction(action.getAction());
3024 ab.setKey(new ActionKey(i));
3025 Action actionNewOrder = ab.build();
3026 bucketActions.remove(action);
3027 bucketActions.add(i, actionNewOrder);
3031 } else if (bucketActions.isEmpty()) {
3032 /* remove bucket with empty action list */
3033 buckets.getBucket().remove(bucket);
3037 if (!buckets.getBucket().isEmpty()) {
3038 /* rewrite the group to group table */
3039 /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
3040 BucketsBuilder bucketsBuilder = new BucketsBuilder();
3041 List<Bucket> bucketList = Lists.newArrayList();
3042 BucketBuilder bucketBuilder = new BucketBuilder();
3043 bucketBuilder.setBucketId(new BucketId((long) 1));
3044 bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
3045 bucketBuilder.setAction(bucketActions);
3046 bucketList.add(bucketBuilder.build());
3047 bucketsBuilder.setBucket(bucketList);
3048 groupBuilder.setBuckets(bucketsBuilder.build());
3049 logger.debug("removeOutputPortFromGroup: bucketList {}", bucketList);
3051 writeGroup(groupBuilder, nodeBuilder);
3052 ApplyActionsBuilder aab = new ApplyActionsBuilder();
3053 aab.setAction(actionList);
3054 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
3057 /* remove group with empty bucket. return true to delete flow */
3058 removeGroup(groupBuilder, nodeBuilder);
3062 /* no group for port list. flow can be removed */
3068 public void initializeOFFlowRules(Node openflowNode) {
3069 Preconditions.checkNotNull(connectionService);
3070 List<Node> ovsNodes = connectionService.getNodes();
3071 if (ovsNodes == null) return;
3072 for (Node ovsNode : ovsNodes) {
3073 Long brIntDpid = this.getIntegrationBridgeOFDPID(ovsNode);
3074 Long brExDpid = this.getExternalBridgeDpid(ovsNode);
3075 logger.debug("Compare openflowNode to OVS node {} vs {} and {}", openflowNode.getID(), brIntDpid, brExDpid);
3076 String openflowID = openflowNode.getID().toString();
3077 if (openflowID.contains(brExDpid.toString())) {
3078 this.initializeFlowRules(ovsNode, configurationService.getExternalBridgeName());
3079 this.triggerInterfaceUpdates(ovsNode);
3081 if (openflowID.contains(brIntDpid.toString())) {
3082 this.initializeFlowRules(ovsNode, configurationService.getIntegrationBridgeName());
3083 this.triggerInterfaceUpdates(ovsNode);
3088 public static NodeBuilder createNodeBuilder(String nodeId) {
3089 NodeBuilder builder = new NodeBuilder();
3090 builder.setId(new NodeId(nodeId));
3091 builder.setKey(new NodeKey(builder.getId()));
3095 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeBuilderToInstanceId(NodeBuilder
3097 return InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
3098 node.getKey()).toInstance();
3101 private String getInternalBridgeUUID (Node node, String bridgeName) {
3102 Preconditions.checkNotNull(ovsdbConfigurationService);
3104 Map<String, Row> bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
3105 if (bridgeTable == null) return null;
3106 for (String key : bridgeTable.keySet()) {
3107 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
3108 if (bridge.getName().equals(bridgeName)) return key;
3110 } catch (Exception e) {
3111 logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);