+ interfaceConfigListener.close();
+ rpcRegistration.close();
+ }
+
+ public RpcProviderRegistry getRpcProviderRegistry() {
+ return rpcProviderRegistry;
+ }
+
+ @Override
+ public Long getPortForInterface(String ifName) {
+ GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(ifName).build();
+ Future<RpcResult<GetPortFromInterfaceOutput>> output = interfaceManagerRpcService.getPortFromInterface(input);
+ try {
+ RpcResult<GetPortFromInterfaceOutput> port = output.get();
+ if(port.isSuccessful()){
+ return port.getResult().getPortno();
+ }
+ }catch(NullPointerException | InterruptedException | ExecutionException e){
+ LOG.warn("Exception when getting port for interface",e);
+ }
+ return null;
+ }
+
+ @Override
+ public Long getPortForInterface(Interface intf) {
+ GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(intf.getName()).build();
+ Future<RpcResult<GetPortFromInterfaceOutput>> output = interfaceManagerRpcService.getPortFromInterface(input);
+ try {
+ RpcResult<GetPortFromInterfaceOutput> port = output.get();
+ if(port.isSuccessful()){
+ return port.getResult().getPortno();
+ }
+ }catch(NullPointerException | InterruptedException | ExecutionException e){
+ LOG.warn("Exception when getting port for interface",e);
+ }
+ return null;
+ }
+
+ @Override
+ public InterfaceInfo getInterfaceInfo(String interfaceName) {
+ //FIXME [ELANBE] This is not working yet, fix this
+
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface
+ ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName,dataBroker);
+
+ if(ifState == null) {
+ LOG.error("Interface {} is not present", interfaceName);
+ return null;
+ }
+
+ Integer lportTag = ifState.getIfIndex();
+ Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
+ if (intf == null) {
+ LOG.error("Interface {} doesn't exist in config datastore", interfaceName);
+ return null;
+ }
+
+ NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(intf, dataBroker);
+ InterfaceInfo.InterfaceType interfaceType = IfmUtil.getInterfaceType(intf);
+ InterfaceInfo interfaceInfo = null;
+ BigInteger dpId = org.opendaylight.vpnservice.interfacemgr.globals.IfmConstants.INVALID_DPID;
+ Integer portNo = org.opendaylight.vpnservice.interfacemgr.globals.IfmConstants.INVALID_PORT_NO;
+ if (ncId !=null ) {
+ dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(ncId));
+ portNo = Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId));
+ }
+
+ if(interfaceType == InterfaceInfo.InterfaceType.VLAN_INTERFACE){
+ interfaceInfo = IfmUtil.getVlanInterfaceInfo(interfaceName, intf, dpId);
+ } else if (interfaceType == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE || interfaceType == InterfaceInfo.InterfaceType.GRE_TRUNK_INTERFACE) {/*
+ trunkInterfaceInfo trunkInterfaceInfo = (TrunkInterfaceInfo) ConfigIfmUtil.getTrunkInterfaceInfo(ifName, ConfigIfmUtil.getInterfaceByIfName(dataBroker, ifName));
+ String higherLayerIf = inf.getHigherLayerIf().get(0);
+ Interface vlanInterface = ConfigIfmUtil.getInterfaceByIfName(dataBroker, higherLayerIf);
+ trunkInterfaceInfo.setPortName(vlanInterface.getAugmentation(BaseConfig.class).getParentInterface());
+ trunkInterfaceManager.updateTargetMacAddressInInterfaceInfo(trunkInterfaceInfo, trunkInterface);
+ if (trunkInterface.getPhysAddress() != null) {
+ trunkInterfaceInfo.setLocalMacAddress(trunkInterface.getPhysAddress().getValue());
+ }
+ interfaceInfo = trunkInterfaceInfo;
+ interfaceInfo.setL2domainGroupId(IfmUtil.getGroupId(OperationalIfmUtil.getInterfaceStateByIfName(dataBroker, higherLayerIf).getIfIndex(), InterfaceType.VLAN_INTERFACE));
+ */} else {
+ LOG.error("Type of Interface {} is unknown", interfaceName);
+ return null;
+ }
+ interfaceInfo.setDpId(dpId);
+ interfaceInfo.setPortNo(portNo);
+ interfaceInfo.setAdminState((intf.isEnabled() == true) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
+ interfaceInfo.setInterfaceName(interfaceName);
+ interfaceInfo.setInterfaceTag(lportTag);
+ interfaceInfo.setInterfaceType(interfaceType);
+ interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType));
+ interfaceInfo.setOpState((ifState.getOperStatus() == OperStatus.Up) ? InterfaceInfo.InterfaceOpState.UP : InterfaceInfo.InterfaceOpState.DOWN);
+
+
+ return interfaceInfo;
+
+ }
+
+ @Override
+ public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName, InterfaceInfo.InterfaceType interfaceType) {
+ InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils
+ .getInterfaceStateFromOperDS(interfaceName, dataBroker);
+ if (ifState == null) {
+ LOG.error("Interface {} is not present", interfaceName);
+ return null;
+ }
+ Integer lportTag = ifState.getIfIndex();
+ NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState);
+ if (ncId != null) {
+ interfaceInfo.setDpId(new BigInteger(IfmUtil.getDpnFromNodeConnectorId(ncId)));
+ interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId)));
+ }
+ interfaceInfo.setAdminState((ifState.getAdminStatus() == AdminStatus.Up) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
+ interfaceInfo.setInterfaceName(interfaceName);
+ interfaceInfo.setInterfaceTag(lportTag);
+ interfaceInfo.setInterfaceType(interfaceType);
+ interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType));
+ interfaceInfo.setOpState((ifState.getOperStatus() == OperStatus.Up) ? InterfaceInfo.InterfaceOpState.UP : InterfaceInfo.InterfaceOpState.DOWN);
+
+
+ return interfaceInfo;
+ }
+
+ @Override
+ public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils
+ .getInterfaceStateFromOperDS(interfaceName, dataBroker);
+ if (ifState == null) {
+ LOG.error("Interface {} is not present", interfaceName);
+ return null;
+ }
+ Integer lportTag = ifState.getIfIndex();
+ InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName);
+ NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState);
+ if (ncId != null) {
+ interfaceInfo.setPortName(IfmUtil.getPortName(dataBroker, ncId));
+ interfaceInfo.setDpId(new BigInteger(IfmUtil.getDpnFromNodeConnectorId(ncId)));
+ interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId)));
+ }
+ interfaceInfo.setAdminState((ifState.getAdminStatus() == AdminStatus.Up) ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED);
+ interfaceInfo.setInterfaceName(interfaceName);
+ interfaceInfo.setInterfaceTag(lportTag);
+ interfaceInfo.setOpState((ifState.getOperStatus() == OperStatus.Up) ? InterfaceInfo.InterfaceOpState.UP : InterfaceInfo.InterfaceOpState.DOWN);
+ return interfaceInfo;
+ }
+
+ public void createVLANInterface(String interfaceName, String portName, BigInteger dpId, Integer vlanId,
+ String description, IfL2vlan.L2vlanMode l2vlanMode) {
+ LOG.info("Create VLAN interface : {}",interfaceName);
+ InstanceIdentifier<Interface> interfaceInstanceIdentifier = InterfaceManagerCommonUtils.
+ getInterfaceIdentifier(new InterfaceKey(interfaceName));
+ IfL2vlanBuilder l2vlanBuilder = new IfL2vlanBuilder().setL2vlanMode(l2vlanMode);
+ if(vlanId > 0){
+ l2vlanBuilder.setVlanId(new VlanId(vlanId));
+ }
+ ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(portName).build();
+ Interface inf = new InterfaceBuilder().setEnabled(true).setName(interfaceName).setType(L2vlan.class).
+ addAugmentation(IfL2vlan.class, l2vlanBuilder.build()).addAugmentation(ParentRefs.class, parentRefs).
+ setDescription(description).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ t.put(LogicalDatastoreType.CONFIGURATION, interfaceInstanceIdentifier, inf, true);
+ }
+
+ public void bindService(String interfaceName, BoundServices serviceInfo){
+ LOG.info("Binding Service : {}",interfaceName);
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ InstanceIdentifier<BoundServices> boundServicesInstanceIdentifier = InstanceIdentifier.builder(ServiceBindings.class).child(ServicesInfo.class, new ServicesInfoKey(interfaceName))
+ .child(BoundServices.class, new BoundServicesKey(serviceInfo.getServicePriority())).build();
+ // List<BoundServices> services = (List<BoundServices>)serviceInfo.getBoundServices();
+ t.put(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier, serviceInfo, true);
+ t.submit();
+ }
+
+ public void unbindService(String interfaceName, BoundServices serviceInfo){
+ LOG.info("Unbinding Service : {}",interfaceName);
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ InstanceIdentifier<BoundServices> boundServicesInstanceIdentifier = InstanceIdentifier.builder(ServiceBindings.class).child(ServicesInfo.class, new ServicesInfoKey(interfaceName))
+ .child(BoundServices.class, new BoundServicesKey(serviceInfo.getServicePriority())).build();
+ t.delete(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier);
+ t.submit();
+ }
+
+ @Override
+ public BigInteger getDpnForInterface(String ifName) {
+ GetDpidFromInterfaceInput input = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
+ Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService.getDpidFromInterface(input);
+ try {
+ RpcResult<GetDpidFromInterfaceOutput> dpn = output.get();
+ if(dpn.isSuccessful()){
+ return dpn.getResult().getDpid();
+ }
+ }catch(NullPointerException | InterruptedException | ExecutionException e){
+ LOG.warn("Exception when getting port for interface",e);
+ }
+ return null;
+ }
+
+ @Override
+ public String getEndpointIpForDpn(BigInteger dpnId) {
+ GetEndpointIpForDpnInput input = new GetEndpointIpForDpnInputBuilder().setDpid(dpnId).build();
+ Future<RpcResult<GetEndpointIpForDpnOutput>> output = interfaceManagerRpcService.getEndpointIpForDpn(input);
+ try {
+ RpcResult<GetEndpointIpForDpnOutput> ipForDpnOutputRpcResult = output.get();
+ if(ipForDpnOutputRpcResult.isSuccessful()){
+ List<IpAddress> localIps = ipForDpnOutputRpcResult.getResult().getLocalIps();
+ if(!localIps.isEmpty()) {
+ return localIps.get(0).getIpv4Address().getValue();
+ }
+ }
+ }catch(NullPointerException | InterruptedException | ExecutionException e){
+ LOG.warn("Exception when getting port for interface",e);
+ }
+ return null;
+ }
+
+ @Override
+ public List<ActionInfo> getInterfaceEgressActions(String ifName) {
+ return IfmUtil.getEgressActionInfosForInterface(ifName, 0, dataBroker);
+ }
+
+ @Override
+ public BigInteger getDpnForInterface(Interface intrf) {
+ return getDpnForInterface(intrf.getName());
+ }
+
+ @Override
+ public List<Interface> getVlanInterfaces() {
+ List<Interface> vlanList = new ArrayList<Interface>();
+ InstanceIdentifier<Interfaces> interfacesInstanceIdentifier = InstanceIdentifier.builder(Interfaces.class).build();
+ Optional<Interfaces> interfacesOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfacesInstanceIdentifier, dataBroker);
+ if (!interfacesOptional.isPresent()) {
+ return vlanList;
+ }
+ Interfaces interfaces = interfacesOptional.get();
+ List<Interface> interfacesList = interfaces.getInterface();
+ for (Interface iface : interfacesList) {
+ if (IfmUtil.getInterfaceType(iface) == InterfaceInfo.InterfaceType.VLAN_INTERFACE) {
+ vlanList.add(iface);
+ }
+ }
+ return vlanList;