2 * Copyright (c) 2015 CableLabs and others. All rights reserved.
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 package org.opendaylight.unimgr.command;
11 import java.util.Map.Entry;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.unimgr.impl.UnimgrConstants;
16 import org.opendaylight.unimgr.impl.UnimgrMapper;
17 import org.opendaylight.unimgr.utils.EvcUtils;
18 import org.opendaylight.unimgr.utils.MdsalUtils;
19 import org.opendaylight.unimgr.utils.OvsdbUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.base.Optional;
30 public class EvcCreateCommand extends AbstractCreateCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class);
34 public EvcCreateCommand(DataBroker dataBroker,
35 Map<InstanceIdentifier<?>, DataObject> changes) {
36 super.dataBroker = dataBroker;
37 super.changes = changes;
41 public void execute() {
42 for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
43 if ((created.getValue() != null) && (created.getValue() instanceof EvcAugmentation)) {
44 EvcAugmentation evc = (EvcAugmentation) created.getValue();
45 InstanceIdentifier<?> evcKey = created.getKey();
46 // For now, we assume that there is 1 uni per source/destination
47 if ((evc.getUniDest() == null) || evc.getUniDest().isEmpty()) {
48 LOG.error("Destination UNI cannot be null.");
51 if ((evc.getUniSource() == null) || evc.getUniSource().isEmpty()) {
52 LOG.error("Source UNI cannot be null.");
55 LOG.info("New EVC created, source IP: {} destination IP {}.",
56 evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
57 evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
58 InstanceIdentifier<Node> sourceUniIid;
59 InstanceIdentifier<Node> destinationUniIid;
60 //FIXME we are assuming that there is only 1 UNI source and destination
62 InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
63 if (iidSource != null) {
64 sourceUniIid = iidSource.firstIdentifierOf(Node.class);
66 sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
67 evc.getUniSource().iterator().next().getIpAddress(),
68 LogicalDatastoreType.OPERATIONAL);
70 InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
71 if (iidDest != null) {
72 destinationUniIid = iidDest.firstIdentifierOf(Node.class);
74 destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
75 evc.getUniDest().iterator().next().getIpAddress(),
76 LogicalDatastoreType.OPERATIONAL);
78 Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
79 LogicalDatastoreType.OPERATIONAL,
81 Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
82 LogicalDatastoreType.OPERATIONAL,
86 // Retrieve the source and destination Unis
87 if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
88 uniSource = optionalUniSource.get();
89 uniDestination = optionalUniDestination.get();
90 // Set source and destination
91 UniAugmentation sourceUniAugmentation =
92 uniSource.getAugmentation(UniAugmentation.class);
93 UniAugmentation destinationUniAugmentation =
94 uniDestination.getAugmentation(UniAugmentation.class);
95 Optional<Node> optionalSourceOvsdbNode =
96 MdsalUtils.readNode(dataBroker,
97 LogicalDatastoreType.OPERATIONAL,
101 Optional<Node> optionalDestinationOvsdbNode =
102 MdsalUtils.readNode(dataBroker,
103 LogicalDatastoreType.OPERATIONAL,
104 destinationUniAugmentation
107 if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
108 InstanceIdentifier<Node> sourceBridgeIid =
109 UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
110 Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
111 LogicalDatastoreType.OPERATIONAL,
113 InstanceIdentifier<Node> destinationBridgeIid =
114 UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
115 Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
116 LogicalDatastoreType.OPERATIONAL,
117 destinationBridgeIid);
118 //update ovsdb qos-entry and queues with max-rate to match evc ingress BW
119 OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
122 if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
123 sourceBr = optionalSourceBr.get();
124 destinationBr = optionalDestinationBr.get();
125 OvsdbUtils.createTerminationPointNode(dataBroker,
126 uniSource.getAugmentation(UniAugmentation.class),
128 UnimgrConstants.DEFAULT_BRIDGE_NAME,
129 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
130 OvsdbUtils.createGreTunnel(dataBroker,
131 uniSource.getAugmentation(UniAugmentation.class),
132 uniDestination.getAugmentation(UniAugmentation.class),
134 UnimgrConstants.DEFAULT_BRIDGE_NAME,
135 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
136 OvsdbUtils.createTerminationPointNode(dataBroker,
137 uniDestination.getAugmentation(UniAugmentation.class),
139 UnimgrConstants.DEFAULT_BRIDGE_NAME,
140 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
141 OvsdbUtils.createGreTunnel(dataBroker,
142 uniDestination.getAugmentation(UniAugmentation.class),
143 uniSource.getAugmentation(UniAugmentation.class), destinationBr,
144 UnimgrConstants.DEFAULT_BRIDGE_NAME,
145 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
146 EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
152 EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
159 LOG.info("Unable to retrieve the source and/or destination bridge.");
162 LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
165 LOG.info("Unable to retrieve the source and/or destination Uni.");