Shankara-Huawei
Committed by Gerrit Code Review

[ONOS-4753] Identity/identityref implementation and UT

Change-Id: I40148fa228465555be3bdf410cc294ffc0f34c18
Showing 56 changed files with 3002 additions and 107 deletions
......@@ -39,5 +39,15 @@ public enum ResolvableType {
/**
* Identifies the leafref.
*/
YANG_LEAFREF
YANG_LEAFREF,
/**
* Identifies the base.
*/
YANG_BASE,
/**
* Identifies the identityref.
*/
YANG_IDENTITYREF
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import java.io.Serializable;
/**
* Reference RFC 6020.
*
* Represents data model node to maintain information defined in YANG base.
* The "base" statement, which is optional, takes as an argument a
* string that is the name of an existing identity, from which the new
* identity is derived. If no "base" statement is present, the identity
* is defined from scratch.
*
* If a prefix is present on the base name, it refers to an identity
* defined in the module that was imported with that prefix, or the
* local module if the prefix matches the local module's prefix.
* Otherwise, an identity with the matching name MUST be defined in the
* current module or an included submodule.
*/
/**
* Represents data model node to maintain information defined in YANG base.
*/
public class YangBase implements Resolvable, Serializable {
private static final long serialVersionUID = 806201693L;
// YANG node identifier.
private YangNodeIdentifier baseIdentifier;
// Referred identity parent information.
private YangIdentity referredIdentity;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
* is added to uses/type/base/identityref but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
// Creates a base type of node.
public YangBase() {
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
/**
* Returns the YANG node identifier.
*
* @return the YANG node identifier
*/
public YangNodeIdentifier getBaseIdentifier() {
return baseIdentifier;
}
/**
* Sets the YANG node identifier.
*
* @param baseIdentifier the YANG node identifier to set
*/
public void setBaseIdentifier(YangNodeIdentifier baseIdentifier) {
this.baseIdentifier = baseIdentifier;
}
/**
* Returns the parent identity node.
*
* @return the parent identity node
*/
public YangIdentity getReferredIdentity() {
return referredIdentity;
}
/**
* Sets the parent identity node.
*
* @param referredIdentity the parent identity node to set
*/
public void setReferredIdentity(YangIdentity referredIdentity) {
this.referredIdentity = referredIdentity;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public void resolve() throws DataModelException {
}
}
......@@ -334,7 +334,7 @@ public class YangDerivedInfo<T>
return RESOLVED;
}
}
} else if (baseType.getDataType() == LEAFREF) {
} else if ((baseType.getDataType() == LEAFREF) || (baseType.getDataType() == IDENTITYREF)) {
setEffectiveBuiltInType(baseType.getDataType());
return RESOLVED;
} else {
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import java.io.Serializable;
/*-
* Reference RFC 6020.
*
* The "identity" statement is used to define a new globally unique,
* abstract, and untyped identity. Its only purpose is to denote its
* name, semantics, and existence. An identity can either be defined
* from scratch or derived from a base identity. The identity's
* argument is an identifier that is the name of the identity. It is
* followed by a block of substatements that holds detailed identity
* information.
*
* The identity's Substatements
*
* +--------------+---------+-------------+-----------------------+
* | substatement | section | cardinality | data model mapping |
* +--------------+---------+-------------+-----------------------+
* | base | 7.16.2 | 0..1 | -YangNodeIdentifier |
* | description | 7.19.3 | 0..1 | -string |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* +--------------+---------+-------------+-----------------------+
*/
/**
* Represents data model node to maintain information defined in YANG identity.
*/
public class YangIdentity extends YangNode implements YangCommonInfo, Parsable, Serializable {
private static final long serialVersionUID = 806201691L;
//Name of the identity.
private String name;
//Base node of identity.
private YangBase baseNode;
//Status of YANG identity.
private YangStatusType status;
//Description of YANG identity.
private String description;
//YANG reference of the identity.
private String reference;
//Creates a identity type of node.
public YangIdentity() {
super(YangNodeType.IDENTITY_NODE);
}
/**
* Returns the name of identity.
*
* @return the identity name
*/
public String getName() {
return name;
}
/**
* Sets the name of identity.
*
* @param name the identity name to set
*/
public void setName(String name) {
this.name = name;
}
@Override
public YangStatusType getStatus() {
return status;
}
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getReference() {
return reference;
}
@Override
public void setReference(String reference) {
this.reference = reference;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IDENTITY_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
}
@Override
public void validateDataOnExit() throws DataModelException {
}
/**
* Returns base node of identity.
*
* @return the base node of identity
*/
public YangBase getBaseNode() {
return baseNode;
}
/**
* Sets the base node.
*
* @param baseNode the base node to set
*/
public void setBaseNode(YangBase baseNode) {
this.baseNode = baseNode;
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import java.io.Serializable;
/*-
* Reference RFC 6020.
*
* The identityref type is used to reference an existing identity.
*
* The identityref's base Statement :
* The "base" statement, which is a substatement to the "type"
* statement, MUST be present if the type is "identityref". The
* argument is the name of an identity, as defined by an "identity"
* statement. If a prefix is present on the identity name, it refers to
* an identity defined in the module that was imported with that prefix.
* Otherwise, an identity with the matching name MUST be defined in the
* current module or an included submodule.
* Valid values for an identityref are any identities derived from the
* identityref's base identity. On a particular server, the valid
* values are further restricted to the set of identities defined in the
* modules supported by the server.
*/
/**
* Represents data model node to maintain information defined in YANG identityref.
*/
public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
private static final long serialVersionUID = 806201692L;
// Get referred identity parent information.
private YangIdentity referredIdentity;
// YANG node identifier.
private YangNodeIdentifier baseIdentity;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
* is added to uses/type/identityref/base but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
// Creates a specific identityref of node.
public YangIdentityRef() {
super(YangNodeType.IDENTITYREF_NODE);
baseIdentity = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public void resolve() throws DataModelException {
// Check if the derived info is present.
YangIdentity identity = getReferredIdentity();
if (identity == null) {
throw new DataModelException("Linker Error: Identity information is missing.");
}
while (identity.getBaseNode() != null) {
if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) {
setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
return;
}
identity = identity.getBaseNode().getReferredIdentity();
}
}
/**
* Returns the YANG base node identifier.
*
* @return the YANG base node identifier
*/
public YangNodeIdentifier getBaseIdentity() {
return baseIdentity;
}
/**
* Sets the YANG node identifier.
*
* @param baseIdentity the YANG node identifier to set
*/
public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
this.baseIdentity = baseIdentity;
}
/**
* Returns the name of identity.
*
* @return the identity name
*/
@Override
public String getName() {
return baseIdentity.getName();
}
/**
* Sets the name of identity.
*
* @param name the identity name to set
*/
@Override
public void setName(String name) {
baseIdentity.setName(name);
}
/**
* Sets node identifier.
*
* @param nodeIdentifier the node identifier
*/
public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
this.baseIdentity = nodeIdentifier;
}
/**
* Returns prefix associated with base.
*
* @return prefix associated with base
*/
public String getPrefix() {
return baseIdentity.getPrefix();
}
/**
* Sets prefix associated with base.
*
* @param prefix prefix associated with base
*/
public void setPrefix(String prefix) {
baseIdentity.setPrefix(prefix);
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IDENTITYREF_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
}
@Override
public void validateDataOnExit() throws DataModelException {
}
/**
* Returns the parent identity node.
*
* @return the parent identity node
*/
public YangIdentity getReferredIdentity() {
return referredIdentity;
}
/**
* Sets the parent identity node.
*
* @param referredIdentity the parent identity node to set
*/
public void setReferredIdentity(YangIdentity referredIdentity) {
this.referredIdentity = referredIdentity;
}
}
......@@ -216,6 +216,17 @@ public class YangModule
private List<YangResolutionInfo> leafrefResolutionList;
/**
* base resolution list.
*/
private List<YangResolutionInfo> baseResolutionList;
/**
* identityref resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
/**
* Creates a YANG node of module type.
*/
public YangModule() {
......@@ -225,6 +236,8 @@ public class YangModule
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -597,8 +610,12 @@ public class YangModule
return usesResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else {
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
}
}
......@@ -611,8 +628,12 @@ public class YangModule
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else {
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
}
}
......@@ -627,6 +648,10 @@ public class YangModule
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
}
}
......@@ -650,11 +675,8 @@ public class YangModule
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangSubModule subModule = null;
try {
subModule = yangInclude.addReferenceToInclude(yangNodeSet);
} catch (DataModelException e) {
throw e;
}
subModule = yangInclude.addReferenceToInclude(yangNodeSet);
// Check if the referred sub-modules parent is self
if (!(subModule.getBelongsTo().getModuleNode() == this)) {
yangInclude.reportIncludeError();
......
......@@ -102,5 +102,15 @@ public enum YangNodeType {
/**
* Node contains "YANG's list" information.
*/
LIST_NODE
LIST_NODE,
/**
* Identity node.
*/
IDENTITY_NODE,
/**
* Identityref node.
*/
IDENTITYREF_NODE
}
......
......@@ -214,6 +214,16 @@ public class YangSubModule
private List<YangResolutionInfo> leafrefResolutionList;
/**
* base resolution list.
*/
private List<YangResolutionInfo> baseResolutionList;
/**
* identityref resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
......@@ -222,6 +232,8 @@ public class YangSubModule
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -559,8 +571,12 @@ public class YangSubModule
return usesResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else {
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
}
}
......@@ -573,8 +589,12 @@ public class YangSubModule
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else {
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
}
}
......@@ -589,6 +609,10 @@ public class YangSubModule
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
}
}
......
......@@ -22,6 +22,8 @@ import java.util.Set;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
......@@ -176,6 +178,10 @@ public final class DataModelUtils {
.getEntityToResolve() instanceof YangLeafRef) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_LEAFREF);
} else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
} else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
}
}
......
......@@ -19,6 +19,8 @@ import java.io.Serializable;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangUses;
......@@ -79,6 +81,10 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T
prefix = ((YangUses) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangIfFeature) {
prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangBase) {
prefix = ((YangBase) entityToBeResolved).getBaseIdentifier().getPrefix();
} else if (entityToBeResolved instanceof YangIdentityRef) {
prefix = ((YangIdentityRef) entityToBeResolved).getBaseIdentity().getPrefix();
} else {
throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
}
......
......@@ -158,11 +158,16 @@ public class YangLinkerManager
try {
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_BASE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
......
......@@ -24,12 +24,15 @@ import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
......@@ -69,9 +72,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
/**
* Represents implementation of resolution object which will be resolved by
......@@ -143,7 +149,10 @@ public class YangResolutionInfoImpl<T>
setCurReferenceResolver(dataModelRootNode);
// Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or YANG leafref.
/**
* Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
* YANG leafref or YANG base or YANG identityref.
*/
T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
// Check if linking is already done
......@@ -157,7 +166,7 @@ public class YangResolutionInfoImpl<T>
}
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
"type/uses/if-feature/leafref");
"type/uses/if-feature/leafref/base/identityref");
}
// Push the initial entity to resolve in stack.
......@@ -178,7 +187,10 @@ public class YangResolutionInfoImpl<T>
while (getPartialResolvedStack().size() != 0) {
// Current node to resolve, it can be a YANG type or YANG uses.
/**
* Current node to resolve, it can be a YANG type or YANG uses or
* YANG if-feature or YANG leafref or YANG base or YANG identityref.
*/
T entityToResolve = getCurrentEntityToResolveFromStack();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
......@@ -227,6 +239,10 @@ public class YangResolutionInfoImpl<T>
errorInfo = GROUPING_LINKER_ERROR;
} else if (resolvable instanceof YangIfFeature) {
errorInfo = FEATURE_LINKER_ERROR;
} else if (resolvable instanceof YangBase) {
errorInfo = BASE_LINKER_ERROR;
} else if (resolvable instanceof YangIdentityRef) {
errorInfo = IDENTITYREF_LINKER_ERROR;
} else {
errorInfo = LEAFREF_LINKER_ERROR;
}
......@@ -246,14 +262,16 @@ public class YangResolutionInfoImpl<T>
} else {
throw new DataModelException(
"Data Model Exception: Entity to resolved is other than type/uses/if-feature/leafref");
"Data Model Exception: Entity to resolved is other than type/uses/if-feature" +
"/leafref/base/identityref");
}
}
}
/**
* Adds the leafref type to the type, which has derived type referring to typedef with leafref type.
* Adds the leafref/identityref type to the type, which has derived type referring to
* typedef with leafref/identityref type.
*/
private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException {
......@@ -279,9 +297,10 @@ public class YangResolutionInfoImpl<T>
YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo();
/*
* If the derived types referred type is not leaf ref return
* If the derived types referred type is not leafref/identityref return
*/
if (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) {
if ((derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) &&
(derivedInfo.getEffectiveBuiltInType() != YangDataTypes.IDENTITYREF)) {
return;
}
......@@ -292,28 +311,49 @@ public class YangResolutionInfoImpl<T>
extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType()
.getDataTypeExtendedInfo();
}
/*
* Backup the derived types leaf ref info, delete all the info in
* current type, but for resolution status as resolved. Copy the backed
* up leaf ref to types extended info, create a leaf ref resolution info
* using the current resolution info and add to leaf ref resolution
* list.
* Backup the derived types leafref/identityref info, delete all the info in current type,
* but for resolution status as resolved. Copy the backed up leafref/identityref to types extended info,
* create a leafref/identityref resolution info using the current resolution info and
* add to leafref/identityref resolution list.
*/
YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
yangType.resetYangType();
yangType.setResolvableStatus(RESOLVED);
yangType.setDataType(YangDataTypes.LEAFREF);
yangType.setDataTypeName(LEAFREF);
yangType.setDataTypeExtendedInfo(leafRefInTypeDef);
leafRefInTypeDef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
ResolvableType.YANG_LEAFREF);
getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
yangType.resetYangType();
yangType.setResolvableStatus(RESOLVED);
yangType.setDataType(YangDataTypes.LEAFREF);
yangType.setDataTypeName(LEAFREF);
yangType.setDataTypeExtendedInfo(leafRefInTypeDef);
leafRefInTypeDef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
potentialAncestorWithReferredNode,
getLineNumber(), getCharPosition());
getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
ResolvableType.YANG_LEAFREF);
getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
} else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) {
YangIdentityRef identityRefInTypeDef = (YangIdentityRef) extendedInfo;
yangType.resetYangType();
yangType.setResolvableStatus(RESOLVED);
yangType.setDataType(YangDataTypes.IDENTITYREF);
yangType.setDataTypeName(IDENTITYREF);
yangType.setDataTypeExtendedInfo(identityRefInTypeDef);
identityRefInTypeDef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef,
potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
ResolvableType.YANG_IDENTITYREF);
getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
}
}
/**
......@@ -360,6 +400,10 @@ public class YangResolutionInfoImpl<T>
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode);
return;
} else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
(getCurrentEntityToResolveFromStack() instanceof YangBase)) {
resolveSelfFileLinkingForBaseAndIdentityref();
return;
} else {
/**
......@@ -453,6 +497,47 @@ public class YangResolutionInfoImpl<T>
}
/**
* Resolves self file linking for base/identityref.
*
* @throws DataModelException a violation of data model rules
*/
private void resolveSelfFileLinkingForBaseAndIdentityref()
throws DataModelException {
boolean referredIdentityFound = false;
String nodeName = null;
if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName();
}
if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
nodeName = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName();
}
if (getCurReferenceResolver() instanceof YangModule) {
YangModule rootNode = (YangModule) getCurReferenceResolver();
// Sends list of nodes for finding the target identity.
referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
} else if (getCurReferenceResolver() instanceof YangSubModule) {
YangSubModule rootNode = (YangSubModule) getCurReferenceResolver();
// Sends list of nodes for finding the target identity.
referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
}
if (referredIdentityFound) {
return;
}
/*
* In case prefix is not present it's a candidate for inter-file resolution via include list.
*/
if (getRefPrefix() == null) {
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
/**
* Returns the root parent with respect to the ancestor count from leafref.
*
* @param ancestorCount count of node where parent node can be reached
......@@ -561,6 +646,41 @@ public class YangResolutionInfoImpl<T>
}
/**
* Returns the status of the referred identity found for base/identityref.
*
* @param nodeName the name of the base nodeidentifier/identityref nodeidentifier
* @param ancestorWithTheReferredNode the parent node of base/identityref
* @return status of referred base/identityref
* @throws DataModelException a violation of data model rules
*/
private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorWithTheReferredNode)
throws DataModelException {
// When child is not present return.
if (ancestorWithTheReferredNode.getChild() == null) {
return false;
}
ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild();
// Checks all the siblings under the node and returns the matched node.
YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorWithTheReferredNode, nodeName);
if (nodeFound != null) {
// Adds reference link of entity to the node under resolution.
addReferredEntityLink(nodeFound, LINKED);
/**
* resolve the reference and update the partial resolution stack with any further recursive references
*/
addUnresolvedRecursiveReferenceToStack(nodeFound);
return true;
}
return false;
}
/**
* Fills the referred leaf or leaf-list inside the path predicates.
*
* @param ancestorWithTheReferredNode the actual node where YANG list will be present
......@@ -856,6 +976,28 @@ public class YangResolutionInfoImpl<T>
}
/**
* Checks for the referred parent node for the base/identity.
*
* @param potentialReferredNode potential referred node
* @return the reffered parent node of base/identity.
* @throws DataModelException data model errors
*/
private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode,
String referredNodeName) throws DataModelException {
while (potentialReferredNode != null) {
if (potentialReferredNode instanceof YangIdentity) {
// Check if the potential referred node is the actual referred node
if (isReferredNodeForIdentity(potentialReferredNode, referredNodeName)) {
return potentialReferredNode;
}
}
potentialReferredNode = potentialReferredNode.getNextSibling();
}
return null;
}
/**
* Checks if the current reference node name and the name in the path are equal.
*
* @param currentReferredNode the node where the reference is pointed
......@@ -878,6 +1020,28 @@ public class YangResolutionInfoImpl<T>
}
/**
* Checks if the current reference node name and the name in the base/identityref base are equal.
*
* @param currentReferredNode the node where the reference is pointed
* @param nameOfIdentityRefBase name of the base in the base/identityref base
* @return status of the match between the name
* @throws DataModelException a violation of data model rules
*/
private boolean isReferredNodeForIdentity(YangNode currentReferredNode, String nameOfIdentityRefBase)
throws DataModelException {
if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
(getCurrentEntityToResolveFromStack() instanceof YangBase)) {
/*
* Check if name of node name matches with the current reference node.
*/
return currentReferredNode.getName().contentEquals(nameOfIdentityRefBase);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than identityref");
}
}
/**
* Checks for the referred node defined in a ancestor scope.
*
* @param potentialReferredNode potential referred node
......@@ -946,8 +1110,18 @@ public class YangResolutionInfoImpl<T>
*/
return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
}
} else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
(getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
if (potentialReferredNode instanceof YangIdentity) {
/*
* Check if name of node name matches with the entity being
* resolved
*/
return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
}
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" +
"uses/base/identityref");
}
return false;
}
......@@ -977,6 +1151,16 @@ public class YangResolutionInfoImpl<T>
}
} else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
return isFeatureDefinedInNode(node);
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
if (node.getName().contentEquals(
((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
return true;
}
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
if (node.getName().contentEquals(
((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName())) {
return true;
}
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
......@@ -1020,8 +1204,13 @@ public class YangResolutionInfoImpl<T>
// do nothing , referred node is already set
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
// do nothing , referred node is already set
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
((YangBase) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
"/uses/base/identityref");
}
// Sets the resolution status in inside the type/uses.
......@@ -1062,6 +1251,15 @@ public class YangResolutionInfoImpl<T>
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
// do nothing , referred node is already set
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
} else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
(getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
/*
* Search if the identity has any un resolved base, if so return true, else return false.
*/
addUnResolvedBaseToStack(referredNode);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" +
"base/identityref");
}
}
......@@ -1109,6 +1307,26 @@ public class YangResolutionInfoImpl<T>
}
/**
* Returns if there is any unresolved base in identity.
*
* @param node module/submodule node
*/
private void addUnResolvedBaseToStack(YangNode node) {
YangIdentity curNode = (YangIdentity) node;
if (curNode.getBaseNode() != null) {
if (curNode.getBaseNode().getResolvableStatus() != RESOLVED) {
YangEntityToResolveInfoImpl<YangBase> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
unResolvedEntityInfo.setEntityToResolve(curNode.getBaseNode());
unResolvedEntityInfo.setHolderOfEntityToResolve(node);
addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
}
}
}
/**
* Returns stack of YANG type with partially resolved YANG construct
* hierarchy.
*
......@@ -1247,8 +1465,13 @@ public class YangResolutionInfoImpl<T>
refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix();
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
refPrefix = refPrefixForLeafRef();
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix();
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix();
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
"type/uses/base/identityref");
}
return refPrefix;
}
......@@ -1392,6 +1615,10 @@ public class YangResolutionInfoImpl<T>
errorInfo = GROUPING_LINKER_ERROR;
} else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
errorInfo = FEATURE_LINKER_ERROR;
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
errorInfo = BASE_LINKER_ERROR;
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
errorInfo = IDENTITYREF_LINKER_ERROR;
} else {
errorInfo = LEAFREF_LINKER_ERROR;
}
......@@ -1449,7 +1676,12 @@ public class YangResolutionInfoImpl<T>
setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
return referredNode;
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
linkedNode = findRefIdentity(yangInclude.getIncludedNode());
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
linkedNode = findRefIdentityRef(yangInclude.getIncludedNode());
}
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
......@@ -1502,6 +1734,10 @@ public class YangResolutionInfoImpl<T>
setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
return referredNode;
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
linkedNode = findRefIdentity(yangImport.getImportedNode());
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
linkedNode = findRefIdentityRef(yangImport.getImportedNode());
}
if (linkedNode != null) {
// Add the link to external entity.
......@@ -1584,8 +1820,13 @@ public class YangResolutionInfoImpl<T>
return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder();
} else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList();
} else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
return (T) ((YangBase) getCurrentEntityToResolveFromStack()).getReferredIdentity();
} else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity();
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
"/uses/base/identityref");
}
}
......@@ -1651,4 +1892,45 @@ public class YangResolutionInfoImpl<T>
}
return null;
}
/**
* Finds the referred identity node at the root level of imported/included node.
*
* @param refNode module/sub-module node
* @return referred identity
*/
private YangNode findRefIdentity(YangNode refNode) {
YangNode tmpNode = refNode.getChild();
while (tmpNode != null) {
if (tmpNode instanceof YangIdentity) {
if (tmpNode.getName()
.equals(((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
return tmpNode;
}
}
tmpNode = tmpNode.getNextSibling();
}
return null;
}
/**
* Finds the referred identity node at the root level of imported/included node.
*
* @param refNode module/sub-module node
* @return referred identity
*/
private YangNode findRefIdentityRef(YangNode refNode) {
YangNode tmpNode = refNode.getChild();
while (tmpNode != null) {
if (tmpNode instanceof YangIdentity) {
if (tmpNode.getName()
.equals(((YangIdentityRef) getCurrentEntityToResolveFromStack())
.getBaseIdentity().getName())) {
return tmpNode;
}
}
tmpNode = tmpNode.getNextSibling();
}
return null;
}
}
......
......@@ -28,6 +28,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener;
import org.onosproject.yangutils.parser.impl.listeners.BitListener;
import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
......@@ -42,7 +43,9 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.IdentityListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
......@@ -450,12 +453,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.IDENTITY_DATA, ctx, CURRENTLY_UNSUPPORTED);
IdentityListener.processIdentityEntry(this, ctx);
}
@Override
public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
// do nothing.
IdentityListener.processIdentityExit(this, ctx);
}
@Override
......@@ -470,7 +473,7 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.BASE_DATA, ctx, CURRENTLY_UNSUPPORTED);
BaseListener.processBaseEntry(this, ctx);
}
@Override
......@@ -710,12 +713,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// do nothing.
IdentityrefListener.processIdentityrefEntry(this, ctx);
}
@Override
public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// do nothing.
IdentityrefListener.processIdentityrefExit(this, ctx);
}
@Override
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
/**
* base-stmt = base-keyword sep identifier-ref-arg-str
* optsep stmtend*
* identifier-ref-arg = [prefix ":"] identifier
*/
/**
* Represents listener based call back function corresponding to the "base"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class BaseListener {
//Creates a new base listener.
private BaseListener() {
}
/**
* Performs validation and updates the data model tree when parser receives an
* input matching the grammar rule (base).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processBaseEntry(TreeWalkListener listener,
GeneratedYangParser.BaseStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, BASE_DATA, ctx.string().getText(), ENTRY);
YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), BASE_DATA, ctx);
Parsable tmpData = listener.getParsedDataStack().peek();
/**
* For identityref base node identifier is copied in identity listener itself, so no need to process
* base statement for indentityref
*/
if (tmpData instanceof YangIdentityRef) {
return;
}
if (!(tmpData instanceof YangIdentity)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BASE_DATA,
ctx.string().getText(), ENTRY));
}
YangBase yangBase = new YangBase();
yangBase.setBaseIdentifier(nodeIdentifier);
((YangIdentity) tmpData).setBaseNode(yangBase);
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<YangBase>(yangBase, (YangNode) tmpData, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
/**
* Add to resolution list.
*
* @param resolutionInfo resolution information
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfoImpl<YangBase> resolutionInfo,
GeneratedYangParser.BaseStatementContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
BASE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
}
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangIdentityNode;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITY_DATA;
/**
* Reference: RFC6020 and YANG ANTLR Grammar.
*
* ABNF grammar as per RFC6020
* identity-stmt = identity-keyword sep identifier-arg-str optsep
* (";" /
* "{" stmtsep
* ;; these stmts can appear in any order
* [base-stmt stmtsep]
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
* "}")
*/
/**
* Represents listener based call back function corresponding to the "identity"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class IdentityListener {
//Creates a identity listener.
private IdentityListener() {
}
/**
* Performs validations and update the data model tree when parser receives an input
* matching the grammar rule (identity).
*
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processIdentityEntry(TreeWalkListener listener,
GeneratedYangParser.IdentityStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), IDENTITY_DATA, ctx);
YangIdentity identity = getYangIdentityNode(JAVA_GENERATION);
identity.setName(identifier);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangSubModule) {
YangNode curNode = (YangNode) curData;
try {
curNode.addChild(identity);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
IDENTITY_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
}
// Push identity node to the stack.
listener.getParsedDataStack().push(identity);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
ctx.identifier().getText(), ENTRY));
}
}
/**
* Performs validations and update the data model tree when parser exits from grammar
* rule (identity).
*
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processIdentityExit(TreeWalkListener listener,
GeneratedYangParser.IdentityStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), EXIT);
Parsable parsableType = listener.getParsedDataStack().pop();
if (!(parsableType instanceof YangIdentity)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
ctx.identifier().getText(), EXIT));
}
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/**
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* identityref-specification =
* base-stmt stmtsep
* base-stmt = base-keyword sep identifier-ref-arg-str
* optsep stmtend*
* identifier-ref-arg = [prefix ":"] identifier
*/
/**
* Represents listener based call back function corresponding to the "identityref"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class IdentityrefListener {
//Creates a new type listener.
private IdentityrefListener() {
}
/**
* Performs validation and updates the data model tree when parser receives an input
* matching the grammar rule (identityref).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processIdentityrefEntry(TreeWalkListener listener,
GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
if (listener.getParsedDataStack().peek() instanceof YangType) {
YangIdentityRef identityRef = new YangIdentityRef();
Parsable typeData = listener.getParsedDataStack().pop();
YangDataTypes yangDataTypes = ((YangType) typeData).getDataType();
YangResolutionInfoImpl resolutionInfo;
// Validate node identifier.
YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
BASE_DATA, ctx);
identityRef.setBaseIdentity(nodeIdentifier);
((YangType) typeData).setDataTypeExtendedInfo(identityRef);
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
// Pop the stack entry to obtain the parent YANG node.
Parsable leaf = listener.getParsedDataStack().pop();
Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leaf);
// Verify parent node of leaf
if (!(parentNodeOfLeaf instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list
resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
(YangNode) parentNodeOfLeaf, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
break;
case LEAF_LIST_DATA:
// Pop the stack entry to obtain the parent YANG node.
Parsable leafList = listener.getParsedDataStack().pop();
Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leafList);
// Verify parent node of leaf
if (!(parentNodeOfLeafList instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list
resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
(YangNode) parentNodeOfLeafList, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
break;
case UNION_DATA:
Parsable parentNodeOfUnionNode = listener.getParsedDataStack().peek();
// Verify parent node of leaf
if (!(parentNodeOfUnionNode instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list
resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
(YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
break;
case TYPEDEF_DATA:
/**
* Do not add the identity ref to resolution list. It needs to be
* added to resolution list, when leaf/leaf list references to
* this typedef. At this time that leaf/leaf-list becomes the
* parent for the identityref.
*/
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
ctx.getText(), EXIT));
}
listener.getParsedDataStack().push(typeData);
listener.getParsedDataStack().push(identityRef);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
}
}
/**
* Performs validations and update the data model tree when parser exits from grammar
* rule (identityref).
*
* @param listener Listener's object
* @param ctx context object of the grammar rule
*/
public static void processIdentityrefExit(TreeWalkListener listener,
GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
Parsable parsableType = listener.getParsedDataStack().pop();
if (!(parsableType instanceof YangIdentityRef)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
ctx.getText(), EXIT));
}
}
/**
* Adds to resolution list.
*
* @param resolutionInfo resolution information
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
GeneratedYangParser.IdentityrefSpecificationContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
}
}
}
......@@ -130,6 +130,10 @@ public final class ModuleListener {
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_BASE);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
......
......@@ -135,6 +135,10 @@ public final class SubModuleListener {
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_BASE);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
......
......@@ -310,7 +310,11 @@ public final class TypeListener {
parserException = new ParserException("YANG file error : a type leafref" +
" must have one path statement.");
break;
// TODO : decimal64, identity ref
case IDENTITYREF:
parserException = new ParserException("YANG file error : a type identityref" +
" must have base statement.");
break;
// TODO : decimal64,
default:
return;
}
......
......@@ -48,10 +48,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENT;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
......@@ -341,7 +339,6 @@ public final class ListenerUtil {
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
return nodeIdentifier;
} else if (tmpData.length == 2) {
......@@ -375,7 +372,6 @@ public final class ListenerUtil {
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
return nodeIdentifier;
} else if (tmpData.length == 2) {
......@@ -706,24 +702,6 @@ public final class ListenerUtil {
}
/**
* Checks whether the type is an unsupported type.
*
* @param typeName name of the type
* @param yangConstruct yang construct to check if it is type
* @param ctx yang construct's context to get the line number and character position
*/
private static void checkForUnsupportedTypes(String typeName,
YangConstructType yangConstruct, ParserRuleContext ctx) {
if (yangConstruct == YangConstructType.TYPE_DATA) {
if (typeName.equalsIgnoreCase(IDENTITYREF)) {
handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
ctx, CURRENTLY_UNSUPPORTED);
}
}
}
/**
* Checks and return valid absolute schema node id.
*
* @param argumentString string from yang file
......
......@@ -89,6 +89,11 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
/**
* Identity listener class.
*/
public static final int GENERATE_IDENTITY_CLASS = 2048;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -20,6 +20,7 @@ import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
......@@ -41,6 +42,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
......@@ -163,6 +165,24 @@ public final class YangDataModelFactory {
* generated
* @return the corresponding inherited node based on the target language
*/
public static YangIdentity getYangIdentityNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
return new YangJavaIdentity();
}
default: {
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
/**
* Returns based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
* generated
* @return the corresponding inherited node based on the target language
*/
public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
......
......@@ -20,7 +20,9 @@ import java.util.Stack;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
......@@ -161,8 +163,10 @@ public final class AttributesJavaDataType {
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
YangIdentity identity = identityRef.getReferredIdentity();
return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).
getName(), pluginConfig));
case EMPTY:
return BOOLEAN_WRAPPER;
case UNION:
......@@ -196,8 +200,9 @@ public final class AttributesJavaDataType {
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
YangIdentity identity = identityRef.getReferredIdentity();
return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).getName(), pluginConfig));
case EMPTY:
return BOOLEAN_DATA_TYPE;
case UNION:
......@@ -212,7 +217,6 @@ public final class AttributesJavaDataType {
return null;
}
}
return null;
}
/**
......@@ -253,8 +257,7 @@ public final class AttributesJavaDataType {
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
return getIdentityRefPackage(yangType, conflictResolver);
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
......@@ -280,8 +283,7 @@ public final class AttributesJavaDataType {
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
return getIdentityRefPackage(yangType, conflictResolver);
case EMPTY:
return JAVA_LANG;
case UNION:
......@@ -294,7 +296,6 @@ public final class AttributesJavaDataType {
return null;
}
}
return null;
}
/**
......@@ -361,6 +362,25 @@ public final class AttributesJavaDataType {
}
/**
* Returns YANG identity's java package.
*
* @param type YANG type
* @param conflictResolver object of YANG to java naming conflict util
* @return YANG identity's java package
*/
private static String getIdentityRefPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) {
throw new TranslatorException("type should have been identityref.");
}
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
YangJavaIdentity identity = (YangJavaIdentity) (identityRef.getReferredIdentity());
if (identity.getJavaFileInfo().getPackage() == null) {
return getPackageFromParent(identity.getParent(), conflictResolver);
}
return identity.getJavaFileInfo().getPackage();
}
/**
* Returns package from parent node.
*
* @param parent parent YANG node
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents input information extended to support java code generation.
*/
public class YangJavaIdentity extends YangIdentity
implements JavaCodeGeneratorInfo, JavaCodeGenerator {
//File type extension for java classes.
private static final String JAVA_FILE_EXTENSION = ".java";
//Contains the information of the java file being generated.
private JavaFileInfo javaFileInfo;
//Contains the information of the importd.
private transient JavaImportData importData;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
*/
private TempJavaCodeFragmentFiles tempFileHandle;
/**
* Creates YANG java container object.
*/
public YangJavaIdentity() {
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
importData = new JavaImportData();
}
/**
* Returns the generated java file information.
*
* @return generated java file information
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
/**
* Sets the java file info object.
*
* @param javaInfo java file info object
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
/**
* Returns the temporary file handle.
*
* @return temporary file handle
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
return tempFileHandle;
}
/**
* Sets temporary file handle.
*
* @param fileHandle temporary file handle
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
/**
* Prepare the information for java code generation corresponding to YANG
* container info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
updatePackageInfo(this, yangPlugin);
JavaQualifiedTypeInfo basePkgInfo = new JavaQualifiedTypeInfo();
String className = getCapitalCase(getJavaFileInfo().getJavaName());
String path = getJavaFileInfo().getPackageFilePath();
createPackage(this);
List<String> imports = null;
boolean isQualified = false;
if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentity)) {
throw new TranslatorException("Failed to prepare generate code entry for base node");
}
YangJavaIdentity baseIdentity = (YangJavaIdentity) getBaseNode().getReferredIdentity();
String baseClassName = getCapitalCase(baseIdentity.getJavaFileInfo().getJavaName());
String basePkg = baseIdentity.getJavaFileInfo().getPackage();
basePkgInfo.setClassInfo(baseClassName);
basePkgInfo.setPkgInfo(basePkg);
isQualified = importData.addImportInfo(basePkgInfo, className, getJavaFileInfo().getPackage());
if (!isQualified) {
imports = importData.getImports();
}
}
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
closeFile(file, false);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for identity node " + this.getName());
}
}
/**
* Create a java file using the YANG container info.
*
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit() throws TranslatorException {
/* Do nothing, file is already generated in entry*/
}
}
......@@ -16,10 +16,13 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
......@@ -27,6 +30,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
......@@ -57,6 +61,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
......@@ -128,6 +134,8 @@ public final class ClassDefinitionGenerator {
return getEventListenerDefinition(yangName);
case GENERATE_EVENT_SUBJECT_CLASS:
return getClassDefinition(yangName);
case GENERATE_IDENTITY_CLASS:
return getIdentityClassDefinition(yangName, curNode);
default:
return null;
}
......@@ -214,6 +222,32 @@ public final class ClassDefinitionGenerator {
}
/**
* Returns implementation file identity class definition.
*
* @param yangName file name
* @return identity class definition
*/
private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
if (!(curNode instanceof YangJavaIdentity)) {
throw new TranslatorException("Expected java identity instance node");
}
YangJavaIdentity identity = (YangJavaIdentity) curNode;
if (identity.getBaseNode() != null) {
YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
if (!(baseIdentity instanceof YangJavaIdentity)) {
throw new TranslatorException("Expected java identity instance node");
}
YangJavaIdentity baseJavaIdentity = (YangJavaIdentity) baseIdentity;
return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + EXTEND + SPACE
+ getCapitalCase(baseJavaIdentity.getJavaFileInfo().getJavaName()) + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns type file class definition.
*
* @param yangName file name
......
......@@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
......@@ -68,6 +69,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionG
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
......@@ -294,6 +296,7 @@ public final class JavaFileGeneratorUtils {
}
file.createNewFile();
appendContents(file, genType, imports, curNode, className);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
......@@ -348,6 +351,11 @@ public final class JavaFileGeneratorUtils {
appendHeaderContents(file, pkgString, importsList);
write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
break;
case GENERATE_IDENTITY_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
break;
default:
break;
}
......
......@@ -647,6 +647,11 @@ public final class UtilConstants {
public static final String PUBLIC = "public";
/**
* Static attribute for abstract modifier.
*/
public static final String ABSTRACT = "abstract";
/**
* Static attribute for protected modifier.
*/
public static final String PROTECTED = "protected";
......@@ -1196,6 +1201,18 @@ public final class UtilConstants {
+ "leaf/leaf-list for given leafref";
/**
* Static attribute for base linker error information.
*/
public static final String BASE_LINKER_ERROR = "YANG file error: Unable to find base "
+ "identity for given base";
/**
* Static attribute for identityref linker error information.
*/
public static final String IDENTITYREF_LINKER_ERROR = "YANG file error: Unable to find base "
+ "identity for given base";
/**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test case for identity listener.
*/
public class IdentityListenerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks for updating datamodel for identity/identityref.
*/
@Test
public void processIdentityrefType() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/IdentityListener.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("IdentityListener"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("tunnel"));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("tunnel-type"));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling();
assertThat(yangIdentity.getName(), is("ref-address-family"));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
.getNextSibling();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
.getNextSibling().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
// Check whether identityref type got resolved.
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks for updating datamodel for intrafile resolution identity/identityref.
*/
@Test
public void processIntraIdentityrefType() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/IdentityIntraFile.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("IdentityIntraFile"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
/**
* Checks for updating datamodel for identityref used in tydedef.
*/
@Test
public void processIdentityTypedefStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/IdentityTypedef.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("tunnel"));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
assertThat(typedef.getName(), is("type15"));
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
assertThat(type.getDataTypeName(), is("identityref"));
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
assertThat(identityRef.getName(), is("tunnel"));
assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel-value"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("tunnel"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("tunnel"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("tunnel"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks for updating datamodel for unresolved status of identityref used in tydedef.
*/
@Test
public void processIdentityUnresolvedTypedefStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/IdentityTypedefUnresolved.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("tunnel"));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
assertThat(typedef.getName(), is("type15"));
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
assertThat(type.getDataTypeName(), is("identityref"));
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
assertThat(identityRef.getName(), is("tunnel"));
assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
}
}
......@@ -122,20 +122,6 @@ public class TypeListenerTest {
}
/**
* Checks for unsupported type identityref.
*/
@Test
public void processIdentityrefType() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
+ " please check wiki for YANG utils road map.");
YangNode node = manager
.getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
}
/**
* Checks for type instance-identifier.
*/
@Test
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.plugin.manager;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
/**
* Test cases for testing inter file linking for identity.
*/
public class InterFileIdentityLinkingTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private final YangUtilManager utilManager = new YangUtilManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
/**
* Checks inter file feature linking with imported file.
*/
@Test
public void processIdentityInImportedFile()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityimport";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("IdentityIntraFile")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("IdentityInModule")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("IdentityIntraFile"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks inter file feature linking with included file.
*/
@Test
public void processIdentityInIncludedFile()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityinlude";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Carry out linking of sub module with module.
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("syslog3")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("syslog4")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("syslog3"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks inter file feature linking with imported file with dependency.
*/
@Test
public void processIdentityInImportedFileWithDependency()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityimportdependency";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("syslog1")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("syslog2")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("syslog1"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks inter file feature linking with included file with dependency.
*/
@Test
public void processIdentityInIncludedFileWithDependency()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityincludedependency";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Carry out linking of sub module with module.
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("syslog1")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("syslog2")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("syslog1"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks inter file feature linking with imported file with dependency
* feature undefined.
*/
@Test
public void processIdentityInImportedFileWithDependencyUndefined()
throws IOException, LinkerException, MojoExecutionException {
thrown.expect(LinkerException.class);
thrown.expectMessage("YANG file error: Unable to find base identity for given base");
String searchDir = "src/test/resources/interfileidentityimportdependencyUndefined";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
}
/**
* Checks inter file feature linking with included file with dependency
* feature undefined.
*/
@Test
public void processIdentityInIncludedFileWithDependencyUndefined()
throws IOException, LinkerException, MojoExecutionException {
thrown.expect(LinkerException.class);
thrown.expectMessage("YANG file error: Unable to find base identity for given base");
String searchDir = "src/test/resources/interfileidentityincludedependencyUndefined";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Carry out linking of sub module with module.
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
}
/**
* Checks inter file feature linking with imported file.
*/
@Test
public void processIdentityTypedefUnresolvedInImportedFile()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentitytypedef";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("IdentityIntraFile")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("IdentityInModule")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("IdentityIntraFile"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
// Check whether leafref type got resolved.
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
assertThat(typedef.getName(), is("type15"));
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
assertThat(type.getDataTypeName(), is("identityref"));
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
assertThat(identityRef.getName(), is("ref-address-family"));
assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
}
/**
* Checks inter file feature linking with imported file.
*/
@Test
public void processIdentityTypedefInImportedFile()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentitytypedef";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("IdentityTypedef")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("IdentityInModule")) {
refNode1 = rootNode;
} else {
refNode2 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("IdentityTypedef"));
YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
assertThat(yangIdentity.getName(), is("ipv4-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
assertThat(yangIdentity.getName(), is("ipv6-address-family"));
assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
assertThat(typedef.getName(), is("type15"));
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
assertThat(type.getDataTypeName(), is("identityref"));
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
assertThat(identityRef.getName(), is("ref-address-family"));
assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tunnel"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangIdentityRef.getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
// Check whether the information in the leaf is correct.
assertThat(leafListInfo.getName(), is("network-ref"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
// Check whether leafref type got resolved.
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
}
module IdentityInModule{
yang-version 1;
namespace http://huawei.com;
prefix IdentityInModule;
identity tunnel-type {
description
"Base identity from which specific tunnel types are derived.";
}
identity ref-address-family {
reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
}
}
\ No newline at end of file
module IdentityIntraFile {
yang-version 1;
namespace http://huawei.com;
prefix IdentityIntraFile;
import "IdentityInModule" {
prefix "IdentityInModule";
}
identity ipv4-address-family {
base IdentityInModule:ref-address-family;
}
identity ipv6-address-family {
base IdentityInModule:ref-address-family;
}
leaf tunnel {
type identityref {
base IdentityInModule:ref-address-family;
}
}
}
\ No newline at end of file
module IdentityListener{
yang-version 1;
namespace http://huawei.com;
prefix IdentityListener;
identity tunnel {
description
"Base identity from which specific tunnel types are derived.";
}
identity tunnel-type {
description
"Base identity from which specific tunnel types are derived.";
}
identity ref-address-family {
reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
}
identity ipv4-address-family {
base ref-address-family;
}
identity ipv6-address-family {
base ref-address-family;
}
leaf tunnel {
type identityref {
base ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base ref-address-family;
}
}
}
\ No newline at end of file
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
identity tunnel {
description
"Base identity from which specific tunnel types are derived.";
}
leaf tunnel-value {
type type15;
}
typedef type15 {
type identityref {
base tunnel;
}
}
}
......@@ -2,10 +2,15 @@ module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
grouping currentcheck {
leaf invalid-interval {
type identityref {
}
}
identity tunnel {
description
"Base identity from which specific tunnel types are derived.";
}
typedef type15 {
type identityref {
base tunnel;
}
}
}
......
module IdentityTest{
yang-version 1;
namespace http://huawei.com;
prefix IdentityTest;
identity ref-address-family {
description "ref-address-family";
}
identity ipv4-address-family {
base ref-address-family;
}
leaf tunnel {
type identityref {
base ref-address-family;
}
}
}
\ No newline at end of file
module IdentityInModule{
yang-version 1;
namespace http://huawei.com;
prefix IdentityInModule;
identity tunnel-type {
description
"Base identity from which specific tunnel types are derived.";
}
identity ref-address-family {
reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
}
}
\ No newline at end of file
module IdentityIntraFile {
yang-version 1;
namespace http://huawei.com;
prefix IdentityIntraFile;
import "IdentityInModule" {
prefix "IdentityInModule";
}
identity ipv4-address-family {
base IdentityInModule:ref-address-family;
}
identity ipv6-address-family {
base IdentityInModule:ref-address-family;
}
leaf tunnel {
type identityref {
base IdentityInModule:ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base IdentityInModule:ref-address-family;
}
}
}
\ No newline at end of file
module syslog1 {
yang-version 1;
namespace "http://huawei1.com";
prefix "sys1";
import "syslog2" {
prefix "sys2";
}
identity ipv4-address-family {
base sys2:ref-address-family;
}
identity ipv6-address-family {
base sys2:ref-address-family;
}
leaf tunnel {
type identityref {
base sys2:ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base sys2:ref-address-family;
}
}
}
module syslog2 {
yang-version 1;
namespace "http://huawei2.com";
prefix "sys2";
import "syslog3" {
prefix "sys3";
}
identity tunnel-type {
base sys3:final-address-family;
}
identity ref-address-family {
base sys3:final-address-family;
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
identity final-address-family {
description
"Base identity from which specific tunnel types are derived.";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei1.com";
prefix "sys1";
import "syslog2" {
prefix "sys2";
}
identity ipv4-address-family {
base sys2:ref-address-family;
}
identity ipv6-address-family {
base sys2:ref-address-family;
}
leaf tunnel {
type identityref {
base sys2:ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base sys2:ref-address-family;
}
}
}
module syslog2 {
yang-version 1;
namespace "http://huawei2.com";
prefix "sys2";
import "syslog3" {
prefix "sys3";
}
identity tunnel-type {
base sys3:final-address-family;
}
identity ref-address-family {
base sys3:final-address-family;
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
}
module syslog1 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys1";
include "syslog2";
identity ipv4-address-family {
base ref-address-family;
}
identity ipv6-address-family {
base ref-address-family;
}
leaf tunnel {
type identityref {
base ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base ref-address-family;
}
}
}
submodule syslog2 {
yang-version 1;
belongs-to "syslog1" {
prefix "sys1";
}
import "syslog3" {
prefix "sys3";
}
identity tunnel-type {
base sys3:final-address-family;
}
identity ref-address-family {
base sys3:final-address-family;
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
identity final-address-family {
description
"Base identity from which specific tunnel types are derived.";
}
}
module syslog1 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys1";
include "syslog2";
identity ipv4-address-family {
base sys2:ref-address-family;
}
identity ipv6-address-family {
base sys2:ref-address-family;
}
leaf tunnel {
type identityref {
base sys2:ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base sys2:ref-address-family;
}
}
}
submodule syslog2 {
yang-version 1;
belongs-to "syslog1" {
prefix "sys1";
}
import "syslog3" {
prefix "sys3";
}
identity tunnel-type {
base sys3:final-address-family;
}
identity ref-address-family {
base sys3:final-address-family;
}
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
}
module syslog3 {
yang-version 1;
namespace "http://huawei3.com";
prefix "sys3";
include "syslog4";
identity ipv4-address-family {
base ref-address-family;
}
identity ipv6-address-family {
base ref-address-family;
}
leaf tunnel {
type identityref {
base ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base ref-address-family;
}
}
}
submodule syslog4 {
yang-version 1;
belongs-to "syslog3" {
prefix "sys3";
}
identity tunnel-type {
description
"Base identity from which specific tunnel types are derived.";
}
identity ref-address-family {
reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
}
}
\ No newline at end of file
module IdentityInModule{
yang-version 1;
namespace http://huawei.com;
prefix IdentityInModule;
identity tunnel-type {
description
"Base identity from which specific tunnel types are derived.";
}
identity ref-address-family {
reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
}
}
\ No newline at end of file
module IdentityIntraFile {
yang-version 1;
namespace http://huawei.com;
prefix IdentityIntraFile;
import "IdentityInModule" {
prefix "IdentityInModule";
}
identity ipv4-address-family {
base IdentityInModule:ref-address-family;
}
identity ipv6-address-family {
base IdentityInModule:ref-address-family;
}
leaf tunnel {
type identityref {
base IdentityInModule:ref-address-family;
}
}
leaf-list network-ref {
type identityref {
base IdentityInModule:ref-address-family;
}
}
typedef type15 {
type identityref {
base IdentityInModule:ref-address-family;
}
}
}
\ No newline at end of file
module IdentityTypedef {
yang-version 1;
namespace http://huawei.com;
prefix IdentityTypedef;
import "IdentityInModule" {
prefix "IdentityInModule";
}
identity ipv4-address-family {
base IdentityInModule:ref-address-family;
}
identity ipv6-address-family {
base IdentityInModule:ref-address-family;
}
leaf tunnel {
type type15;
}
leaf-list network-ref {
type type15;
}
typedef type15 {
type identityref {
base IdentityInModule:ref-address-family;
}
}
}
\ No newline at end of file
......@@ -56,7 +56,7 @@
reference "RFC3209";
}
/*identity tunnel-type {
identity tunnel-type {
description
"Base identity from which specific tunnel types are
derived.";
......@@ -254,7 +254,7 @@
base lsp-encoding-types;
description
"Line (e.g., 8B/10B) LSP encoding";
}*/
}
/* TE basic features */
feature p2mp-te {
......@@ -452,7 +452,7 @@
}
}
/*identity route-usage-type {
identity route-usage-type {
description
"Base identity for route usage";
}
......@@ -576,7 +576,7 @@
description
"The set of attribute filters associated with a
tunnel any of which renders a link unacceptable";
}*/
}
typedef admin-group {
type binary {
......@@ -605,7 +605,7 @@
description "SRLG type";
}
/*identity path-computation-srlg-type {
identity path-computation-srlg-type {
description
"Base identity for SRLG path computation";
}
......@@ -632,7 +632,7 @@
base path-computation-srlg-type;
description
"Include weighted SRLG check in path computation";
}*/
}
typedef te-metric {
type uint32;
......