2 * Copyright (c) 2016 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.genius.interfacemanager;
11 import com.google.common.base.Optional;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.Future;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
21 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
25 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
26 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
27 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
28 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
29 import org.opendaylight.genius.interfacemanager.exceptions.InterfaceAlreadyExistsException;
30 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
31 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo.InterfaceAdminState;
32 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
33 import org.opendaylight.genius.interfacemanager.listeners.AlivenessMonitorListener;
34 import org.opendaylight.genius.interfacemanager.listeners.CacheInterfaceConfigListener;
35 import org.opendaylight.genius.interfacemanager.listeners.CacheInterfaceStateListener;
36 import org.opendaylight.genius.interfacemanager.listeners.HwVTEPConfigListener;
37 import org.opendaylight.genius.interfacemanager.listeners.HwVTEPTunnelsStateListener;
38 import org.opendaylight.genius.interfacemanager.listeners.InterfaceConfigListener;
39 import org.opendaylight.genius.interfacemanager.listeners.InterfaceInventoryStateListener;
40 import org.opendaylight.genius.interfacemanager.listeners.InterfaceTopologyStateListener;
41 import org.opendaylight.genius.interfacemanager.listeners.TerminationPointStateListener;
42 import org.opendaylight.genius.interfacemanager.listeners.VlanMemberConfigListener;
43 import org.opendaylight.genius.interfacemanager.pmcounters.NodeConnectorStatsImpl;
44 import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.InterfaceBatchHandler;
45 import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.BatchingUtils;
46 import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.IfmClusterUtils;
47 import org.opendaylight.genius.interfacemanager.rpcservice.InterfaceManagerRpcService;
48 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.listeners.FlowBasedServicesConfigListener;
49 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.listeners.FlowBasedServicesInterfaceStateListener;
50 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
51 import org.opendaylight.genius.interfacemanager.statusanddiag.InterfaceStatusMonitor;
52 import org.opendaylight.genius.mdsalutil.ActionInfo;
53 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfExternal;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfExternalBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInputBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceBindings;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfoKey;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesKey;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
98 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
99 import org.opendaylight.yangtools.yang.common.RpcResult;
100 import org.slf4j.Logger;
101 import org.slf4j.LoggerFactory;
104 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
106 private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
107 private static final InterfaceStatusMonitor interfaceStatusMonitor = InterfaceStatusMonitor.getInstance();
109 private RpcProviderRegistry rpcProviderRegistry;
110 private IdManagerService idManager;
111 private NotificationService notificationService;
112 private AlivenessMonitorService alivenessManager;
113 private IMdsalApiManager mdsalManager;
114 private InterfaceConfigListener interfaceConfigListener;
115 private InterfaceTopologyStateListener topologyStateListener;
116 private TerminationPointStateListener terminationPointStateListener;
117 private HwVTEPTunnelsStateListener hwVTEPTunnelsStateListener;
118 private InterfaceInventoryStateListener interfaceInventoryStateListener;
119 private FlowBasedServicesInterfaceStateListener flowBasedServicesInterfaceStateListener;
120 private FlowBasedServicesConfigListener flowBasedServicesConfigListener;
121 private VlanMemberConfigListener vlanMemberConfigListener;
122 private HwVTEPConfigListener hwVTEPConfigListener;
123 private AlivenessMonitorListener alivenessMonitorListener;
124 private DataBroker dataBroker;
125 private InterfaceManagerRpcService interfaceManagerRpcService;
126 private BindingAwareBroker.RpcRegistration<OdlInterfaceRpcService> rpcRegistration;
127 private NodeConnectorStatsImpl nodeConnectorStatsManager;
128 private CacheInterfaceConfigListener cacheInterfaceConfigListener;
129 private CacheInterfaceStateListener cacheInterfaceStateListener;
130 private EntityOwnershipService entityOwnershipService;
132 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
133 this.rpcProviderRegistry = rpcProviderRegistry;
134 interfaceStatusMonitor.registerMbean();
137 public void setMdsalManager(IMdsalApiManager mdsalManager) {
138 this.mdsalManager = mdsalManager;
141 public void setEntityOwnershipService(
142 EntityOwnershipService entityOwnershipService) {
143 this.entityOwnershipService = entityOwnershipService;
146 public EntityOwnershipService getEntityOwnershipService() {
147 return entityOwnershipService;
150 public void setNotificationService(NotificationService notificationService) {
151 this.notificationService = notificationService;
154 public DataBroker getDataBroker(){
155 return this.dataBroker;
159 public void onSessionInitiated(ProviderContext session) {
160 LOG.info("InterfacemgrProvider Session Initiated");
161 interfaceStatusMonitor.reportStatus("STARTING");
163 dataBroker = session.getSALService(DataBroker.class);
164 idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
167 IfmClusterUtils.registerEntityForOwnership(this, entityOwnershipService);
168 BatchingUtils.registerWithBatchManager(new InterfaceBatchHandler(), this.dataBroker);
169 alivenessManager = rpcProviderRegistry.getRpcService(AlivenessMonitorService.class);
170 interfaceManagerRpcService = new InterfaceManagerRpcService(dataBroker, mdsalManager);
171 rpcRegistration = getRpcProviderRegistry().addRpcImplementation(
172 OdlInterfaceRpcService.class, interfaceManagerRpcService);
174 interfaceConfigListener = new InterfaceConfigListener(dataBroker, idManager, alivenessManager, mdsalManager);
175 interfaceConfigListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
177 interfaceInventoryStateListener = new InterfaceInventoryStateListener(dataBroker, idManager, mdsalManager, alivenessManager);
178 interfaceInventoryStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
180 topologyStateListener = new InterfaceTopologyStateListener(dataBroker);
181 topologyStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
183 hwVTEPTunnelsStateListener = new HwVTEPTunnelsStateListener(dataBroker);
184 hwVTEPTunnelsStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
186 terminationPointStateListener = new TerminationPointStateListener(dataBroker);
187 terminationPointStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
189 flowBasedServicesConfigListener = new FlowBasedServicesConfigListener(this);
190 flowBasedServicesConfigListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
192 flowBasedServicesInterfaceStateListener =
193 new FlowBasedServicesInterfaceStateListener(this);
194 flowBasedServicesInterfaceStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
196 vlanMemberConfigListener =
197 new VlanMemberConfigListener(dataBroker, idManager, alivenessManager, mdsalManager);
198 vlanMemberConfigListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
200 hwVTEPConfigListener = new HwVTEPConfigListener(dataBroker);
201 hwVTEPConfigListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
203 alivenessMonitorListener = new org.opendaylight.genius.interfacemanager.listeners.AlivenessMonitorListener(dataBroker);
204 notificationService.registerNotificationListener(alivenessMonitorListener);
206 cacheInterfaceConfigListener = new CacheInterfaceConfigListener(dataBroker);
208 cacheInterfaceStateListener = new CacheInterfaceStateListener(dataBroker);
210 //Initialize nodeconnectorstatsimpl
211 nodeConnectorStatsManager = new NodeConnectorStatsImpl(dataBroker, notificationService,
212 session.getRpcService(OpendaylightPortStatisticsService.class), session.getRpcService(OpendaylightFlowTableStatisticsService.class));
215 interfaceStatusMonitor.reportStatus("OPERATIONAL");
216 } catch (Exception e) {
217 LOG.error("Error initializing services", e);
218 interfaceStatusMonitor.reportStatus("ERROR");
222 private void createIdPool() {
223 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
224 .setPoolName(IfmConstants.IFM_IDPOOL_NAME)
225 .setLow(IfmConstants.IFM_ID_POOL_START)
226 .setHigh(IfmConstants.IFM_ID_POOL_END)
228 //TODO: Error handling
229 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
231 if ((result != null) && (result.get().isSuccessful())) {
232 LOG.debug("Created IdPool for InterfaceMgr");
234 } catch (InterruptedException | ExecutionException e) {
235 LOG.error("Failed to create idPool for InterfaceMgr", e);
240 public void close() throws Exception {
241 LOG.info("InterfacemgrProvider Closed");
242 interfaceConfigListener.close();
243 rpcRegistration.close();
244 cacheInterfaceConfigListener.close();
245 cacheInterfaceStateListener.close();
246 topologyStateListener.close();
247 interfaceInventoryStateListener.close();
248 hwVTEPConfigListener.close();
249 hwVTEPTunnelsStateListener.close();
250 vlanMemberConfigListener.close();
251 flowBasedServicesConfigListener.close();
252 flowBasedServicesInterfaceStateListener.close();
253 terminationPointStateListener.close();
256 public RpcProviderRegistry getRpcProviderRegistry() {
257 return rpcProviderRegistry;
261 public Long getPortForInterface(String ifName) {
262 GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(ifName).build();
263 Future<RpcResult<GetPortFromInterfaceOutput>> output = interfaceManagerRpcService.getPortFromInterface(input);
265 RpcResult<GetPortFromInterfaceOutput> port = output.get();
266 if (port.isSuccessful()) {
267 return port.getResult().getPortno();
269 } catch (NullPointerException | InterruptedException | ExecutionException e) {
270 LOG.warn("Exception when getting port for interface", e);
276 public Long getPortForInterface(Interface intf) {
277 GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(intf.getName()).build();
278 Future<RpcResult<GetPortFromInterfaceOutput>> output = interfaceManagerRpcService.getPortFromInterface(input);
280 RpcResult<GetPortFromInterfaceOutput> port = output.get();
281 if (port.isSuccessful()) {
282 return port.getResult().getPortno();
284 } catch (NullPointerException | InterruptedException | ExecutionException e) {
285 LOG.warn("Exception when getting port for interface", e);
291 public InterfaceInfo getInterfaceInfo(String interfaceName) {
293 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface
294 ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
296 if (ifState == null) {
297 LOG.error("Interface {} is not present", interfaceName);
301 Integer lportTag = ifState.getIfIndex();
302 Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
304 LOG.error("Interface {} doesn't exist in config datastore", interfaceName);
308 NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(intf.getName(), dataBroker);
309 InterfaceInfo.InterfaceType interfaceType = IfmUtil.getInterfaceType(intf);
310 InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName);
311 BigInteger dpId = org.opendaylight.genius.interfacemanager.globals.IfmConstants.INVALID_DPID;
312 Integer portNo = org.opendaylight.genius.interfacemanager.globals.IfmConstants.INVALID_PORT_NO;
314 dpId = IfmUtil.getDpnFromNodeConnectorId(ncId);
315 portNo = Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId));
317 if (interfaceType == InterfaceInfo.InterfaceType.VLAN_INTERFACE) {
318 interfaceInfo = IfmUtil.getVlanInterfaceInfo(interfaceName, intf, dpId);
319 } else if (interfaceType == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE ||
320 interfaceType == InterfaceInfo.InterfaceType.GRE_TRUNK_INTERFACE) {
321 // TODO : since there is no logical grouping for tunnel interfaces, there is no need
322 // for this code as of now. will be revisited once the support comes
325 LOG.error("Type of Interface {} is unknown", interfaceName);
328 InterfaceInfo.InterfaceOpState opState ;
329 if(ifState.getOperStatus() == OperStatus.Up)
331 opState = InterfaceInfo.InterfaceOpState.UP;
333 else if (ifState.getOperStatus() == OperStatus.Down)
335 opState = InterfaceInfo.InterfaceOpState.DOWN;
339 opState = InterfaceInfo.InterfaceOpState.UNKNOWN;
341 interfaceInfo.setDpId(dpId);
342 interfaceInfo.setPortNo(portNo);
343 interfaceInfo.setAdminState((intf.isEnabled() == true) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
344 interfaceInfo.setInterfaceName(interfaceName);
345 interfaceInfo.setInterfaceTag(lportTag);
346 interfaceInfo.setInterfaceType(interfaceType);
347 interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType));
348 interfaceInfo.setOpState(opState);
349 PhysAddress phyAddress = ifState.getPhysAddress();
350 if (phyAddress != null) {
351 interfaceInfo.setMacAddress(ifState.getPhysAddress().getValue());
354 return interfaceInfo;
359 public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName, InterfaceInfo.InterfaceType interfaceType) {
360 InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName);
361 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils
362 .getInterfaceStateFromOperDS(interfaceName, dataBroker);
363 if (ifState == null) {
364 LOG.error("Interface {} is not present", interfaceName);
367 Integer lportTag = ifState.getIfIndex();
368 NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState);
370 interfaceInfo.setDpId(IfmUtil.getDpnFromNodeConnectorId(ncId));
371 interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId)));
373 InterfaceInfo.InterfaceOpState opState ;
374 if(ifState.getOperStatus() == OperStatus.Up)
376 opState = InterfaceInfo.InterfaceOpState.UP;
378 else if (ifState.getOperStatus() == OperStatus.Down)
380 opState = InterfaceInfo.InterfaceOpState.DOWN;
384 opState = InterfaceInfo.InterfaceOpState.UNKNOWN;
386 interfaceInfo.setAdminState((ifState.getAdminStatus() == AdminStatus.Up) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
387 interfaceInfo.setInterfaceName(interfaceName);
388 interfaceInfo.setInterfaceTag(lportTag);
389 interfaceInfo.setInterfaceType(interfaceType);
390 interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType));
391 interfaceInfo.setOpState(opState);
392 PhysAddress phyAddress = ifState.getPhysAddress();
393 if (phyAddress != null) {
394 interfaceInfo.setMacAddress(ifState.getPhysAddress().getValue());
397 return interfaceInfo;
401 public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName) {
402 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils
403 .getInterfaceStateFromOperDS(interfaceName, dataBroker);
404 if (ifState == null) {
405 LOG.error("Interface {} is not present", interfaceName);
408 Integer lportTag = ifState.getIfIndex();
409 InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName);
410 NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState);
412 interfaceInfo.setPortName(IfmUtil.getPortName(dataBroker, ncId));
413 interfaceInfo.setDpId(IfmUtil.getDpnFromNodeConnectorId(ncId));
414 interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId)));
416 InterfaceInfo.InterfaceOpState opState ;
417 if(ifState.getOperStatus() == OperStatus.Up)
419 opState = InterfaceInfo.InterfaceOpState.UP;
421 else if (ifState.getOperStatus() == OperStatus.Down)
423 opState = InterfaceInfo.InterfaceOpState.DOWN;
427 opState = InterfaceInfo.InterfaceOpState.UNKNOWN;
429 interfaceInfo.setAdminState((ifState.getAdminStatus() == AdminStatus.Up) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
430 interfaceInfo.setInterfaceName(interfaceName);
431 interfaceInfo.setInterfaceTag(lportTag);
432 interfaceInfo.setOpState(opState);
433 PhysAddress phyAddress = ifState.getPhysAddress();
434 if (phyAddress != null) {
435 interfaceInfo.setMacAddress(ifState.getPhysAddress().getValue());
437 return interfaceInfo;
441 public Interface getInterfaceInfoFromConfigDataStore(String interfaceName) {
442 Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
447 public void createVLANInterface(String interfaceName, String portName, BigInteger dpId, Integer vlanId,
448 String description, IfL2vlan.L2vlanMode l2vlanMode) throws InterfaceAlreadyExistsException {
449 createVLANInterface(interfaceName, portName, dpId, vlanId, description, l2vlanMode, false);
452 public void createVLANInterface(String interfaceName, String portName, BigInteger dpId, Integer vlanId,
453 String description, IfL2vlan.L2vlanMode l2vlanMode, boolean isExternal) throws InterfaceAlreadyExistsException {
455 LOG.info("Create VLAN interface : {}", interfaceName);
456 InstanceIdentifier<Interface> interfaceInstanceIdentifier = InterfaceManagerCommonUtils.getInterfaceIdentifier(new InterfaceKey(interfaceName));
457 Interface interfaceOptional = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
458 if (interfaceOptional != null) {
459 LOG.debug("VLAN interface is already exist", interfaceOptional.getDescription());
460 throw new InterfaceAlreadyExistsException(interfaceOptional.getName());
462 IfL2vlanBuilder l2vlanBuilder = new IfL2vlanBuilder().setL2vlanMode(l2vlanMode);
463 if (vlanId != null && vlanId > 0) {
464 l2vlanBuilder.setVlanId(new VlanId(vlanId));
466 ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(portName).build();
467 InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setEnabled(true).setName(interfaceName).setType(L2vlan.class).
468 addAugmentation(IfL2vlan.class, l2vlanBuilder.build()).addAugmentation(ParentRefs.class, parentRefs).
469 setDescription(description);
471 interfaceBuilder.addAugmentation(IfExternal.class, new IfExternalBuilder().setExternal(true).build());
473 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
474 t.put(LogicalDatastoreType.CONFIGURATION, interfaceInstanceIdentifier, interfaceBuilder.build(), true);
479 public void bindService(String interfaceName, Class<? extends ServiceModeBase> serviceMode, BoundServices serviceInfo) {
480 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
481 IfmUtil.bindService(t, interfaceName, serviceInfo, serviceMode);
486 public void unbindService(String interfaceName, Class<? extends ServiceModeBase> serviceMode, BoundServices serviceInfo) {
487 IfmUtil.unbindService(dataBroker, interfaceName,
488 FlowBasedServicesUtils.buildServiceId(interfaceName, serviceInfo.getServicePriority(), serviceMode), interfaceName);
492 public BigInteger getDpnForInterface(String ifName) {
493 GetDpidFromInterfaceInput input = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
494 Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService.getDpidFromInterface(input);
496 RpcResult<GetDpidFromInterfaceOutput> dpn = output.get();
497 if (dpn.isSuccessful()) {
498 return dpn.getResult().getDpid();
500 } catch (NullPointerException | InterruptedException | ExecutionException e) {
501 LOG.warn("Exception when getting port for interface", e);
507 public String getEndpointIpForDpn(BigInteger dpnId) {
508 GetEndpointIpForDpnInput input = new GetEndpointIpForDpnInputBuilder().setDpid(dpnId).build();
509 Future<RpcResult<GetEndpointIpForDpnOutput>> output = interfaceManagerRpcService.getEndpointIpForDpn(input);
511 RpcResult<GetEndpointIpForDpnOutput> ipForDpnOutputRpcResult = output.get();
512 if (ipForDpnOutputRpcResult.isSuccessful()) {
513 List<IpAddress> localIps = ipForDpnOutputRpcResult.getResult().getLocalIps();
514 if (!localIps.isEmpty()) {
515 return localIps.get(0).getIpv4Address().getValue();
518 } catch (NullPointerException | InterruptedException | ExecutionException e) {
519 LOG.warn("Exception when getting port for interface", e);
525 public List<ActionInfo> getInterfaceEgressActions(String ifName) {
526 return IfmUtil.getEgressActionInfosForInterface(ifName, 0, dataBroker, false);
530 public BigInteger getDpnForInterface(Interface intrf) {
531 return getDpnForInterface(intrf.getName());
535 public List<Interface> getVlanInterfaces() {
536 List<Interface> vlanList = new ArrayList<>();
537 InstanceIdentifier<Interfaces> interfacesInstanceIdentifier = InstanceIdentifier.builder(Interfaces.class).build();
538 Optional<Interfaces> interfacesOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfacesInstanceIdentifier, dataBroker);
539 if (!interfacesOptional.isPresent()) {
542 Interfaces interfaces = interfacesOptional.get();
543 List<Interface> interfacesList = interfaces.getInterface();
544 for (Interface iface : interfacesList) {
545 if (IfmUtil.getInterfaceType(iface) == InterfaceInfo.InterfaceType.VLAN_INTERFACE) {
553 public List<Interface> getVxlanInterfaces() {
554 return InterfaceManagerCommonUtils.getAllTunnelInterfaces(dataBroker,
555 InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE);