+
+ public static void setOpStateForInterface(DataBroker broker, String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus opStatus) {
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> interfaceId = IfmUtil.buildStateInterfaceId(interfaceName);
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setKey(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(interfaceName));
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceData = ifaceBuilder.setOperStatus(opStatus).build();
+ MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, interfaceData);
+ }
+
+ public static void updateTunnelMonitorDetailsInConfigDS(DataBroker broker, String interfaceName, boolean monitorEnabled, long monitorInterval) {
+ InstanceIdentifier<Interface> id = IfmUtil.buildId(interfaceName);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder();
+ ifaceBuilder.setKey(new InterfaceKey(interfaceName));
+ IfTunnelBuilder ifTunnelBuilder = new IfTunnelBuilder();
+ ifTunnelBuilder.setMonitorEnabled(monitorEnabled);
+ ifTunnelBuilder.setMonitorInterval(monitorInterval);
+ ifaceBuilder.addAugmentation(IfTunnel.class, ifTunnelBuilder.build());
+
+ LOG.trace("Updating trunk interface {} in Config DS", interfaceName);
+ MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, id, ifaceBuilder.build());
+ }
+
+ public static void createInterfaceChildEntry( WriteTransaction t,
+ String parentInterface, String childInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> intfId =
+ InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
+ .setChildInterface(childInterface);
+ t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
+ }
+
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus
+ updateStateEntry(Interface interfaceNew, DataBroker dataBroker, WriteTransaction transaction,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus;
+ if (!interfaceNew.isEnabled()) {
+ operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
+ } else {
+ String ncStr = ifState.getLowerLayerIf().get(0);
+ NodeConnectorId nodeConnectorId = new NodeConnectorId(ncStr);
+ NodeConnector nodeConnector =
+ InterfaceManagerCommonUtils.getNodeConnectorFromInventoryOperDS(nodeConnectorId, dataBroker);
+ FlowCapableNodeConnector flowCapableNodeConnector =
+ nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
+ //State state = flowCapableNodeConnector.getState();
+ operStatus = flowCapableNodeConnector == null ? org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down : org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up;
+ }
+
+ String ifName = interfaceNew.getName();
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ IfmUtil.buildStateInterfaceId(interfaceNew.getName());
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
+ ifaceBuilder.setOperStatus(operStatus);
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(ifName));
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+ return operStatus;
+ }
+
+ public static void updateOperStatus(String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
+ WriteTransaction transaction) {
+ LOG.debug("updating operational status for interface {}",interfaceName);
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
+ IfmUtil.buildStateInterfaceId(interfaceName);
+ InterfaceBuilder ifaceBuilderChild = new InterfaceBuilder();
+ ifaceBuilderChild.setOperStatus(operStatus);
+ ifaceBuilderChild.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, ifChildStateId, ifaceBuilderChild.build());
+ }
+
+ public static void addStateEntry(String interfaceName, WriteTransaction transaction, DataBroker dataBroker, IdManagerService idManager,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
+ LOG.debug("adding interface state for {}",interfaceName);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus = ifState.getOperStatus();
+ PhysAddress physAddress = ifState.getPhysAddress();
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus = ifState.getAdminStatus();
+ NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
+ InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface interfaceInfo =
+ InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
+
+ if (interfaceInfo != null && !interfaceInfo.isEnabled()) {
+ operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
+ }
+
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ IfmUtil.buildStateInterfaceId(interfaceName);
+ List<String> childLowerLayerIfList = new ArrayList<>();
+ childLowerLayerIfList.add(0, nodeConnectorId.getValue());
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus)
+ .setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
+
+ Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceName);
+ ifaceBuilder.setIfIndex(ifIndex);
+
+ if(interfaceInfo != null){
+ ifaceBuilder.setType(interfaceInfo.getType());
+ }
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
+ transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
+
+ // create lportTag Interface Map
+ InterfaceMetaUtils.createLportTagInterfaceMap(transaction, interfaceName, ifIndex);
+
+ // install ingress flow
+ BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
+ long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
+ if(interfaceInfo.isEnabled() && ifState.getOperStatus() == org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up) {
+ List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceInfo);
+ FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceInfo, transaction, matches, ifIndex);
+ }
+ }
+
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface
+ addStateEntry(Interface interfaceInfo, String portName, WriteTransaction transaction, IdManagerService idManager,
+ PhysAddress physAddress, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus,
+ NodeConnectorId nodeConnectorId) {
+ LOG.debug("adding interface state for {}",portName);
+ if (interfaceInfo != null && !interfaceInfo.isEnabled()) {
+ operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
+ }
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ IfmUtil.buildStateInterfaceId(portName);
+ List<String> childLowerLayerIfList = new ArrayList<>();
+ childLowerLayerIfList.add(0, nodeConnectorId.getValue());
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus)
+ .setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
+
+ Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, portName);
+ ifaceBuilder.setIfIndex(ifIndex);
+
+ if(interfaceInfo != null){
+ ifaceBuilder.setType(interfaceInfo.getType());
+ }
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(portName));
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = ifaceBuilder.build();
+ transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId,ifState , true);
+
+ // allocate lport tag and set in if-index
+ InterfaceMetaUtils.createLportTagInterfaceMap(transaction, portName, ifIndex);
+ return ifState;
+ }
+
+ public static void deleteStateEntry(String interfaceName, WriteTransaction transaction) {
+ LOG.debug("removing interface state for {}",interfaceName);
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
+ IfmUtil.buildStateInterfaceId(interfaceName);
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
+ }
+
+ // For trunk interfaces, binding to a parent interface which is already bound to another trunk interface should not
+ // be allowed
+ public static boolean createInterfaceChildEntryIfNotPresent( DataBroker dataBroker, WriteTransaction t,
+ String parentInterface, String childInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
+ InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ InterfaceParentEntry interfaceParentEntry =
+ InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
+
+ if(interfaceParentEntry != null){
+ LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
+ return false;
+ }
+
+ LOG.info("First vlan trunk {} bound on parent-interface {}", childInterface, parentInterface);
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> intfId =
+ InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
+ .setChildInterface(childInterface);
+ t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
+ return true;
+ }
+
+ public static boolean deleteParentInterfaceEntry( WriteTransaction t, String parentInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier);
+ return true;
+ }
+
+ public static void deleteInterfaceChildEntry(WriteTransaction transaction, DataBroker dataBroker, String parentInterface, String childInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid =
+ InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ InterfaceParentEntry interfaceParentEntry =
+ InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid, dataBroker);
+
+ if(interfaceParentEntry == null){
+ return;
+ }
+
+ List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
+ if (interfaceChildEntries.size() <= 1) {
+ transaction.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIid);
+ } else {
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid =
+ InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ transaction.delete(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryIid);
+ }
+ }
+
+ /*
+ * update operational state of interface based on events like tunnel monitoring
+ */
+ public static void updateOpState(WriteTransaction transaction, String interfaceName,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus){
+ LOG.debug("updating tep interface state for {}", interfaceName);
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ IfmUtil.buildStateInterfaceId(interfaceName);
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(operStatus);
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+ }
+