2 * Copyright © 2017 Ericsson India Global Services Pvt Ltd. 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.netvirt.elanmanager.api;
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.stream.Collectors;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
18 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.common.Uint64;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public final class ElanHelper {
32 private static final Logger LOG = LoggerFactory.getLogger(ElanHelper.class);
34 private ElanHelper() {
35 throw new AssertionError(ElanHelper.class.getName() + " cannot be initialized.");
38 public static InstanceIdentifier<ElanInstance> getElanInstanceConfigurationDataPath(String elanInstanceName) {
39 return InstanceIdentifier.builder(ElanInstances.class)
40 .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
43 public static Uint64 getElanMetadataLabel(long elanTag) {
44 return MetaDataUtil.getElanTagMetadata(elanTag);
47 public static Uint64 getElanMetadataLabel(long elanTag, int lportTag) {
48 return Uint64.fromLongBits(getElanMetadataLabel(elanTag).longValue()
49 | MetaDataUtil.getLportTagMetaData(lportTag).longValue());
52 public static Uint64 getElanMetadataMask() {
53 return Uint64.fromLongBits(MetaDataUtil.METADATA_MASK_SERVICE.longValue()
54 | MetaDataUtil.METADATA_MASK_LPORT_TAG.longValue());
57 public static List<String> getDpnInterfacesInElanInstance(DataBroker broker, String elanInstanceName) {
59 InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
61 ElanDpnInterfacesList existingElanDpnInterfaces = SingleTransactionDataBroker.syncRead(broker,
62 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
63 if (existingElanDpnInterfaces != null) {
64 return existingElanDpnInterfaces.getDpnInterfaces().stream().flatMap(v -> v.getInterfaces().stream())
65 .collect(Collectors.toList());
67 } catch (ReadFailedException e) {
68 LOG.warn("Failed to read ElanDpnInterfacesList with error {}", e.getMessage());
70 return Collections.emptyList();
73 public static InstanceIdentifier<ElanDpnInterfacesList> getElanDpnOperationDataPath(String elanInstanceName) {
74 return InstanceIdentifier.builder(ElanDpnInterfaces.class)
75 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName)).build();