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.impl.UnimgrUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Optional;
28 public class EvcCreateCommand extends AbstractCreateCommand {
30 private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class);
32 public EvcCreateCommand(DataBroker dataBroker,
33 Map<InstanceIdentifier<?>, DataObject> changes) {
34 super.dataBroker = dataBroker;
35 super.changes = changes;
39 public void execute() {
40 for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
41 if (created.getValue() != null && created.getValue() instanceof EvcAugmentation) {
42 EvcAugmentation evc = (EvcAugmentation) created.getValue();
43 InstanceIdentifier<?> evcKey = created.getKey();
44 // For now, we assume that there is 1 uni per source/destination
45 if (evc.getUniDest() == null || evc.getUniDest().isEmpty()) {
46 LOG.error("Destination UNI cannot be null.");
49 if (evc.getUniSource() == null || evc.getUniSource().isEmpty()) {
50 LOG.error("Source UNI cannot be null.");
53 LOG.trace("New EVC created, source IP: {} destination IP {}.",
54 evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
55 evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
56 InstanceIdentifier<Node> sourceUniIid;
57 InstanceIdentifier<Node> destinationUniIid;
58 //FIXME we are assuming that there is only 1 UNI source and destination
60 InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
61 if (iidSource != null) {
62 sourceUniIid = iidSource.firstIdentifierOf(Node.class);
64 sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
65 evc.getUniSource().iterator().next().getIpAddress(),
66 LogicalDatastoreType.OPERATIONAL);
68 InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
69 if (iidDest != null) {
70 destinationUniIid = iidDest.firstIdentifierOf(Node.class);
72 destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
73 evc.getUniDest().iterator().next().getIpAddress(),
74 LogicalDatastoreType.OPERATIONAL);
76 Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
77 LogicalDatastoreType.OPERATIONAL,
79 Optional<Node> optionalUniDestination = UnimgrUtils.readNode(dataBroker,
80 LogicalDatastoreType.OPERATIONAL,
84 // Retrieve the source and destination Unis
85 if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
86 uniSource = optionalUniSource.get();
87 uniDestination = optionalUniDestination.get();
88 // Set source and destination
89 UniAugmentation sourceUniAugmentation =
90 uniSource.getAugmentation(UniAugmentation.class);
91 UniAugmentation destinationUniAugmentation =
92 uniDestination.getAugmentation(UniAugmentation.class);
93 Optional<Node> optionalSourceOvsdbNode =
94 UnimgrUtils.readNode(dataBroker,
95 LogicalDatastoreType.OPERATIONAL,
99 Optional<Node> optionalDestinationOvsdbNode =
100 UnimgrUtils.readNode(dataBroker,
101 LogicalDatastoreType.OPERATIONAL,
102 destinationUniAugmentation
105 if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
106 InstanceIdentifier<Node> sourceBridgeIid =
107 UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
108 Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
109 LogicalDatastoreType.OPERATIONAL,
111 InstanceIdentifier<Node> destinationBridgeIid =
112 UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
113 Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
114 LogicalDatastoreType.OPERATIONAL,
115 destinationBridgeIid);
118 if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
119 sourceBr = optionalSourceBr.get();
120 destinationBr = optionalDestinationBr.get();
121 UnimgrUtils.createTerminationPointNode(dataBroker,
122 uniSource.getAugmentation(UniAugmentation.class),
124 UnimgrConstants.DEFAULT_BRIDGE_NAME,
125 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
126 UnimgrUtils.createGreTunnel(dataBroker,
127 uniSource.getAugmentation(UniAugmentation.class),
128 uniDestination.getAugmentation(UniAugmentation.class),
130 UnimgrConstants.DEFAULT_BRIDGE_NAME,
131 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
132 UnimgrUtils.createTerminationPointNode(dataBroker,
133 uniSource.getAugmentation(UniAugmentation.class),
135 UnimgrConstants.DEFAULT_BRIDGE_NAME,
136 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
137 UnimgrUtils.createGreTunnel(dataBroker,
138 uniDestination.getAugmentation(UniAugmentation.class),
139 uniSource.getAugmentation(UniAugmentation.class), destinationBr,
140 UnimgrConstants.DEFAULT_BRIDGE_NAME,
141 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
142 UnimgrUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
148 UnimgrUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
155 LOG.info("Unable to retrieve the source and/or destination bridge.");
158 LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
161 LOG.info("Unable to retrieve the source and/or destination Uni.");