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;
38 @SuppressWarnings("unchecked")
40 public void execute() {
41 for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
42 if (created.getValue() != null && created.getValue() instanceof EvcAugmentation) {
43 EvcAugmentation evc = (EvcAugmentation) created.getValue();
44 LOG.info("New EVC created, source IP: {} destination IP {}.",
45 evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
46 evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
47 // For now, we assume that there is 1 uni per source/destination
48 if (evc.getUniDest() == null || evc.getUniDest().isEmpty()) {
49 LOG.error("Destination UNI cannot be null.");
52 if (evc.getUniSource() == null || evc.getUniSource().isEmpty()) {
53 LOG.error("Source UNI cannot be null.");
56 InstanceIdentifier<Node> sourceUniIid;
57 InstanceIdentifier<Node> destinationUniIid;
58 if (evc.getUniSource().iterator().next().getUni() != null) {
59 sourceUniIid = (InstanceIdentifier<Node>) evc.getUniSource().iterator().next().getUni();
61 sourceUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress());
63 if (evc.getUniDest().iterator().next().getUni() != null) {
64 destinationUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());;
66 destinationUniIid = (InstanceIdentifier<Node>) evc.getUniDest().iterator().next().getUni();
68 // The user has specified the instance identifier of the
69 // uni source and uni destination
70 Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
71 LogicalDatastoreType.CONFIGURATION,
73 Optional<Node> optionalUniDestination = UnimgrUtils.readNode(dataBroker,
74 LogicalDatastoreType.CONFIGURATION,
78 // Retrieve the source and destination Unis
79 if (!optionalUniSource.isPresent() || !optionalUniDestination.isPresent()) {
80 LOG.info("Unable to retrieve the Source and/or Destination Unis.");
83 uniSource = optionalUniSource.get();
84 uniDestination = optionalUniDestination.get();
86 // Set source and destination
87 InstanceIdentifier<Node> sourceBridgeIid =
88 UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
89 UnimgrConstants.DEFAULT_BRIDGE_NAME);
90 Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
91 LogicalDatastoreType.CONFIGURATION,
93 InstanceIdentifier<Node> destinationBridgeIid =
94 UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
95 UnimgrConstants.DEFAULT_BRIDGE_NAME);
96 Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
97 LogicalDatastoreType.CONFIGURATION,
98 destinationBridgeIid);
99 if (!optionalSourceBr.isPresent() || !optionalDestinationBr.isPresent()) {
100 LOG.info("Unable to retrieve the source and/or destination bridge.");
103 Node sourceBr = optionalSourceBr.get();
104 Node destinationBr = optionalDestinationBr.get();
105 UnimgrUtils.createTerminationPointNode(dataBroker,
106 uniSource.getAugmentation(UniAugmentation.class),
108 UnimgrConstants.DEFAULT_BRIDGE_NAME,
109 UnimgrConstants.DEFAULT_TUNNEL_IFACE,
110 UnimgrConstants.DEFAULT_GRE_NAME);
111 UnimgrUtils.createGreTunnel(dataBroker,
112 uniSource.getAugmentation(UniAugmentation.class),
113 uniDestination.getAugmentation(UniAugmentation.class),
115 UnimgrConstants.DEFAULT_BRIDGE_NAME,
117 UnimgrUtils.createTerminationPointNode(dataBroker,
118 uniSource.getAugmentation(UniAugmentation.class),
120 UnimgrConstants.DEFAULT_BRIDGE_NAME,
121 UnimgrConstants.DEFAULT_TUNNEL_IFACE,
122 UnimgrConstants.DEFAULT_GRE_NAME);
123 UnimgrUtils.createGreTunnel(dataBroker,
124 uniDestination.getAugmentation(UniAugmentation.class),
125 uniSource.getAugmentation(UniAugmentation.class),
127 UnimgrConstants.DEFAULT_BRIDGE_NAME,