+
+ public static List<String> getPortNameAndSuffixFromInterfaceName(String intfName) {
+ List<String> strList = new ArrayList<>(2);
+ int index = intfName.indexOf(":");
+ if (index != -1) {
+ strList.add(0, intfName.substring(0, index));
+ strList.add(1, intfName.substring(index));
+ }
+ return strList;
+ }
+
+ public static long getGroupId(long ifIndex, InterfaceInfo.InterfaceType infType) {
+ if (infType == InterfaceInfo.InterfaceType.LOGICAL_GROUP_INTERFACE) {
+ return ifIndex + IfmConstants.LOGICAL_GROUP_START;
+ }
+ else if (infType == InterfaceInfo.InterfaceType.VLAN_INTERFACE) {
+ return ifIndex + IfmConstants.VLAN_GROUP_START;
+ } else {
+ return ifIndex + IfmConstants.TRUNK_GROUP_START;
+ }
+ }
+
+ public static List<String> getDpIdPortNameAndSuffixFromInterfaceName(String intfName) {
+ List<String> strList = new ArrayList<>(3);
+ int index1 = intfName.indexOf(":");
+ if (index1 != -1) {
+ int index2 = intfName.indexOf(":", index1 + 1 );
+ strList.add(0, intfName.substring(0, index1));
+ if (index2 != -1) {
+ strList.add(1, intfName.substring(index1, index2));
+ strList.add(2, intfName.substring(index2));
+ } else {
+ strList.add(1, intfName.substring(index1));
+ strList.add(2, "");
+ }
+ }
+ return strList;
+ }
+
+ public static <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path, DataBroker broker) {
+
+ ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ public static NodeId getNodeIdFromNodeConnectorId(NodeConnectorId ncId) {
+ return new NodeId(ncId.getValue().substring(0,ncId.getValue().lastIndexOf(":")));
+ }
+
+ public static BigInteger[] mergeOpenflowMetadataWriteInstructions(List<Instruction> instructions) {
+ BigInteger metadata = new BigInteger("0", 16);
+ BigInteger metadataMask = new BigInteger("0", 16);
+ if (instructions != null && !instructions.isEmpty()) {
+ // check if metadata write instruction is present
+ for (Instruction instruction : instructions) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction actualInstruction = instruction.getInstruction();
+ if (actualInstruction instanceof WriteMetadataCase) {
+ WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction ;
+ WriteMetadata availableMetaData = writeMetaDataInstruction.getWriteMetadata();
+ metadata = metadata.or(availableMetaData.getMetadata());
+ metadataMask = metadataMask.or(availableMetaData.getMetadataMask());
+ }
+ }
+ }
+ return new BigInteger[] { metadata, metadataMask };
+ }
+
+ public static Integer allocateId(IdManagerService idManager, String poolName, String idKey) {
+ AllocateIdInput getIdInput = new AllocateIdInputBuilder()
+ .setPoolName(poolName)
+ .setIdKey(idKey).build();
+ try {
+ Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
+ RpcResult<AllocateIdOutput> rpcResult = result.get();
+ if(rpcResult.isSuccessful()) {
+ return rpcResult.getResult().getIdValue().intValue();
+ } else {
+ LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.warn("Exception when getting Unique Id",e);
+ }
+ return INVALID_ID;
+ }
+
+ public static void releaseId(IdManagerService idManager, String poolName, String idKey) {
+ ReleaseIdInput idInput = new ReleaseIdInputBuilder()
+ .setPoolName(poolName)
+ .setIdKey(idKey).build();
+ try {
+ Future<RpcResult<Void>> result = idManager.releaseId(idInput);
+ RpcResult<Void> rpcResult = result.get();
+ if(!rpcResult.isSuccessful()) {
+ LOG.warn("RPC Call to release Id {} with Key {} returned with Errors {}",
+ idKey, rpcResult.getErrors());
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.warn("Exception when releasing Id for key {}", idKey, e);
+ }
+ }
+
+ public static BigInteger getDpnId(DatapathId datapathId){
+ if (datapathId != null) {
+ String dpIdStr = datapathId.getValue().replace(":", "");
+ return new BigInteger(dpIdStr, 16);
+ }
+ return null;
+ }
+
+ public static NodeConnectorId getNodeConnectorIdFromInterface(Interface iface, DataBroker dataBroker) {
+ return FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
+ }
+
+ public static InterfaceInfo.InterfaceType getInterfaceType(Interface iface) {
+ InterfaceInfo.InterfaceType interfaceType =
+ org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo.InterfaceType.UNKNOWN_INTERFACE;
+ Class<? extends org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType> ifType = iface.getType();
+
+ if (ifType.isAssignableFrom(L2vlan.class)) {
+ interfaceType = org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo.InterfaceType.VLAN_INTERFACE;
+ } else if (ifType.isAssignableFrom(Tunnel.class)) {
+ IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class);
+ Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase> tunnelType = ifTunnel.getTunnelInterfaceType();
+ if (tunnelType.isAssignableFrom(TunnelTypeVxlan.class)) {
+ interfaceType = InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE;
+ } else if (tunnelType.isAssignableFrom(TunnelTypeGre.class)) {
+ interfaceType = InterfaceInfo.InterfaceType.GRE_TRUNK_INTERFACE;
+ }
+ }
+ // TODO: Check if the below condition is still needed/valid
+ //else if (ifType.isAssignableFrom(InterfaceGroup.class)) {
+ // interfaceType = org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo.InterfaceType.LOGICAL_GROUP_INTERFACE;
+ //}
+ return interfaceType;
+ }
+
+ public static VlanInterfaceInfo getVlanInterfaceInfo(String interfaceName, Interface iface, BigInteger dpId){
+ IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class);
+
+ short vlanId = 0;
+ //FIXME :Use this below thing properly
+ VlanInterfaceInfo vlanInterfaceInfo = new VlanInterfaceInfo(dpId, "someString", vlanId);
+
+ if (vlanIface != null) {
+ vlanId = vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue().shortValue();
+ L2vlanMode l2VlanMode = vlanIface.getL2vlanMode();
+
+ if (l2VlanMode == L2vlanMode.Transparent) {
+ vlanInterfaceInfo.setVlanTransparent(true);
+ }
+ if (l2VlanMode == L2vlanMode.NativeUntagged) {
+ vlanInterfaceInfo.setUntaggedVlan(true);
+ }
+ vlanInterfaceInfo.setVlanId(vlanId);
+
+ }
+ return vlanInterfaceInfo;
+ }