Adding vxlan tunnel id allocator.
[honeycomb.git] / vbd / impl / src / main / java / io / fd / honeycomb / vbd / impl / VbdUtil.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  * <p>
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
7  */
8 package io.fd.honeycomb.vbd.impl;
9
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
14 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17
18 public class VbdUtil {
19
20     private static final String TUNNEL_ID_PREFIX = "vxlan_tunnel";
21
22
23     private VbdUtil() {
24         throw new UnsupportedOperationException("Can't instantiate util class");
25     }
26
27     static DataBroker resolveDataBrokerForMountPoint(final InstanceIdentifier<Node> iiToMountPoint, final MountPointService mountService) {
28         final Optional<MountPoint> vppMountPointOpt = mountService.getMountPoint(iiToMountPoint);
29         if (vppMountPointOpt.isPresent()) {
30             final MountPoint vppMountPoint = vppMountPointOpt.get();
31             final Optional<DataBroker> dataBrokerOpt = vppMountPoint.getService(DataBroker.class);
32             if (dataBrokerOpt.isPresent()) {
33                 return dataBrokerOpt.get();
34             }
35         }
36         return null;
37     }
38
39     static String provideVxlanId(final int vxlanTunnelId) {
40         return TUNNEL_ID_PREFIX + vxlanTunnelId;
41     }
42
43
44 }