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;
13 import org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException;
14 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
15 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.Uint64;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public final class ElanHelper {
31 private static final Logger LOG = LoggerFactory.getLogger(ElanHelper.class);
33 private ElanHelper() {
34 throw new AssertionError(ElanHelper.class.getName() + " cannot be initialized.");
37 public static InstanceIdentifier<ElanInstance> getElanInstanceConfigurationDataPath(String elanInstanceName) {
38 return InstanceIdentifier.builder(ElanInstances.class)
39 .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
42 public static Uint64 getElanMetadataLabel(long elanTag) {
43 return MetaDataUtil.getElanTagMetadata(elanTag);
46 public static Uint64 getElanMetadataLabel(long elanTag, int lportTag) {
47 return Uint64.fromLongBits(getElanMetadataLabel(elanTag).longValue()
48 | MetaDataUtil.getLportTagMetaData(lportTag).longValue());
51 public static Uint64 getElanMetadataMask() {
52 return Uint64.fromLongBits(MetaDataUtil.METADATA_MASK_SERVICE.longValue()
53 | MetaDataUtil.METADATA_MASK_LPORT_TAG.longValue());
56 public static List<String> getDpnInterfacesInElanInstance(DataBroker broker, String elanInstanceName) {
58 InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
60 ElanDpnInterfacesList existingElanDpnInterfaces = SingleTransactionDataBroker.syncRead(broker,
61 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
62 if (existingElanDpnInterfaces != null) {
63 return existingElanDpnInterfaces.getDpnInterfaces().stream().flatMap(v -> v.getInterfaces().stream())
64 .collect(Collectors.toList());
66 } catch (ExpectedDataObjectNotFoundException e) {
67 LOG.warn("Failed to read ElanDpnInterfacesList with error {}", e.getMessage());
69 return Collections.emptyList();
72 public static InstanceIdentifier<ElanDpnInterfacesList> getElanDpnOperationDataPath(String elanInstanceName) {
73 return InstanceIdentifier.builder(ElanDpnInterfaces.class)
74 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName)).build();