<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectory>${project.basedir}</sourceDirectory>
<includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</includes>
+ <excludes>target\/</excludes>
</configuration>
</plugin>
<plugin>
--- /dev/null
+package org.opendaylight.controller.configuration;
+
+public enum ConfigurationEvent {
+ SAVE("Save"),
+ BACKUP("Backup"),
+ RESTORE("Restore"),
+ DELETE("Delete");
+
+ private ConfigurationEvent(String name) {
+ this.name = name;
+ }
+
+ private String name;
+
+ public String toString() {
+ return name;
+ }
+
+ public static ConfigurationEvent fromString(String pName) {
+ for(ConfigurationEvent p:ConfigurationEvent.values()) {
+ if (p.toString().equals(pName)) {
+ return p;
+ }
+ }
+ return null;
+ }
+}
package org.opendaylight.controller.configuration.internal;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
import org.opendaylight.controller.configuration.IConfigurationAware;
import org.opendaylight.controller.configuration.IConfigurationContainerAware;
c.add(createContainerServiceDependency(containerName).setService(
IConfigurationContainerAware.class).setCallbacks(
- "addConfigurationContainerAware",
- "removeConfigurationContainerAware").setRequired(false));
+ "addConfigurationContainerAware",
+ "removeConfigurationContainerAware").setRequired(false));
}
}
*/
protected void configureGlobalInstance(Component c, Object imp) {
if (imp.equals(ConfigurationImpl.class)) {
+ Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
+ Set<String> propSet = new HashSet<String>();
+ propSet.add("config.event.save");
+ props.put("cachenames", propSet);
// export the service
c.setInterface(
- new String[] { IConfigurationService.class.getName() },
- null);
+ new String[] { IConfigurationService.class.getName(),
+ ICacheUpdateAware.class.getName()},
+ props);
c.add(createServiceDependency().setService(
IClusterGlobalServices.class).setCallbacks(
- "setClusterServices", "unsetClusterServices").setRequired(
- true));
+ "setClusterServices", "unsetClusterServices").setRequired(
+ true));
c.add(createServiceDependency().setService(
IConfigurationAware.class).setCallbacks(
- "addConfigurationAware", "removeConfigurationAware")
- .setRequired(false));
+ "addConfigurationAware", "removeConfigurationAware")
+ .setRequired(false));
}
}
}
package org.opendaylight.controller.configuration.internal;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.configuration.ConfigurationEvent;
import org.opendaylight.controller.configuration.IConfigurationAware;
import org.opendaylight.controller.configuration.IConfigurationService;
import org.opendaylight.controller.sal.utils.StatusCode;
*
*/
-public class ConfigurationImpl implements IConfigurationService {
+public class ConfigurationImpl implements IConfigurationService, ICacheUpdateAware<ConfigurationEvent, String> {
private static final Logger logger = LoggerFactory
.getLogger(ConfigurationImpl.class);
private IClusterGlobalServices clusterServices;
+ private ConcurrentMap <ConfigurationEvent, String> configEvent;
/*
* Collection containing the configuration objects.
* This is configuration world: container names (also the map key)
logger.info("ContainerManager startup....");
}
+ public void start() {
+ allocateCache();
+ retrieveCache();
+ }
+
public void destroy() {
// Clear local states
this.configurationAwareList.clear();
@Override
public Status saveConfigurations() {
+ if (configEvent != null) {
+ configEvent.put(ConfigurationEvent.SAVE, "");
+ }
+ return saveConfigurationsInternal();
+ }
+
+ private Status saveConfigurationsInternal() {
boolean success = true;
for (IConfigurationAware configurationAware : configurationAwareList) {
- Status status = configurationAware.saveConfiguration();
+ Status status = configurationAware.saveConfiguration();
if (!status.isSuccess()) {
success = false;
logger.info("Failed to save config for {}",
- configurationAware.getClass().getName());
+ configurationAware.getClass().getName());
}
}
if (success) {
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS);
} else {
return new Status(StatusCode.INTERNALERROR,
- "Failed to Save All Configurations");
+ "Failed to Save All Configurations");
+ }
+ }
+
+ @Override
+ public void entryCreated(ConfigurationEvent key, String cacheName,
+ boolean originLocal) {
+ if (originLocal) return;
+ }
+
+ @Override
+ public void entryUpdated(ConfigurationEvent key, String new_value,
+ String cacheName, boolean originLocal) {
+ if (originLocal) return;
+ if (key == ConfigurationEvent.SAVE) {
+ saveConfigurationsInternal();
}
}
+ @Override
+ public void entryDeleted(ConfigurationEvent key, String cacheName,
+ boolean originLocal) {
+ if (originLocal) return;
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (this.clusterServices == null) {
+ logger.error("uninitialized clusterServices, can't create cache");
+ return;
+ }
+ try {
+ this.clusterServices.createCache("config.event.save",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Error creating Configuration cache ", cce);
+ } catch (CacheExistException cce) {
+ logger.error("Configuration Cache already exists, destroy and recreate ", cce);
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (this.clusterServices == null) {
+ logger.error("uninitialized clusterServices, can't retrieve cache");
+ return;
+ }
+ configEvent = (ConcurrentMap<ConfigurationEvent, String>) this.clusterServices.getCache("config.event.save");
+ if (configEvent == null) {
+ logger.error("Failed to retrieve configuration Cache");
+ }
+ }
}
package org.opendaylight.controller.forwarding.staticrouting;
+import java.io.Serializable;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Map;
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.packet.BitBufferHelper;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.NodeCreator;
-
-import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class defines a static route object.
*/
-public class StaticRoute {
+public class StaticRoute implements Serializable{
+ private static final long serialVersionUID = 1L;
protected static final Logger logger = LoggerFactory
.getLogger(StaticRoute.class);
/**
* This Enum defines the possible types for the next hop address.
*/
- public enum NextHopType {
+ public enum NextHopType implements Serializable {
IPADDRESS("nexthop-ip"), SWITCHPORT("nexthop-interface");
private NextHopType(String name) {
this.name = name;
import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.switchmanager.Switch;
* Configuration Java Object which represents a flow configuration information
* for Forwarding Rules Manager.
*/
-
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class FlowConfig implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(FlowConfig.class);
- private static final String staticFlowsGroup = "**StaticFlows";
+ public static final String staticFlowsGroup = "**StaticFlows";
+ public static final String internalStaticFlowsGroup = "**InternalStaticFlows";
+ public static final String internalStaticFlowBegin = "**";
private boolean dynamic;
private String status;
public FlowConfig() {
}
- public FlowConfig(String installInHw, String name, Node node,
- String priority, String cookie, String ingressPort,
- String portGroup, String vlanId, String vlanPriority,
- String etherType, String srcMac, String dstMac, String protocol,
- String tosBits, String srcIP, String dstIP, String tpSrc,
- String tpDst, String idleTimeout, String hardTimeout,
- List<String> actions) {
+ public FlowConfig(String installInHw, String name, Node node, String priority, String cookie, String ingressPort,
+ String portGroup, String vlanId, String vlanPriority, String etherType, String srcMac, String dstMac,
+ String protocol, String tosBits, String srcIP, String dstIP, String tpSrc, String tpDst,
+ String idleTimeout, String hardTimeout, List<String> actions) {
super();
this.installInHw = installInHw;
this.name = name;
public boolean isInternalFlow() {
// Controller generated static flows have name starting with "**"
- return (this.name != null && this.name.startsWith("**"));
+ return (this.name != null && this.name.startsWith(FlowConfig.internalStaticFlowBegin));
}
public String getName() {
@Override
public String toString() {
- return "FlowConfig [dynamic=" + dynamic + ", status=" + status
- + ", installInHw=" + installInHw + ", name=" + name
- + ", switchId=" + node + ", ingressPort=" + ingressPort
- + ", portGroup=" + portGroup + ", etherType=" + etherType
- + ", priority=" + priority + ", vlanId=" + vlanId
- + ", vlanPriority=" + vlanPriority + ", dlSrc=" + dlSrc
- + ", dlDst=" + dlDst + ", nwSrc=" + nwSrc + ", nwDst=" + nwDst
- + ", protocol=" + protocol + ", tosBits=" + tosBits
- + ", tpSrc=" + tpSrc + ", tpDst=" + tpDst + ", cookie="
- + cookie + ", idleTimeout=" + idleTimeout + ", hardTimeout="
- + hardTimeout + ", actions=" + actions + "]";
+ return "FlowConfig [dynamic=" + dynamic + ", status=" + status + ", installInHw=" + installInHw + ", name="
+ + name + ", switchId=" + node + ", ingressPort=" + ingressPort + ", portGroup=" + portGroup
+ + ", etherType=" + etherType + ", priority=" + priority + ", vlanId=" + vlanId + ", vlanPriority="
+ + vlanPriority + ", dlSrc=" + dlSrc + ", dlDst=" + dlDst + ", nwSrc=" + nwSrc + ", nwDst=" + nwDst
+ + ", protocol=" + protocol + ", tosBits=" + tosBits + ", tpSrc=" + tpSrc + ", tpDst=" + tpDst
+ + ", cookie=" + cookie + ", idleTimeout=" + idleTimeout + ", hardTimeout=" + hardTimeout + ", actions="
+ + actions + "]";
}
public void setPortGroup(String portGroup) {
}
public boolean isIPv6() {
- if (NetUtils.isIPv6AddressValid(this.getSrcIp())
- || NetUtils.isIPv6AddressValid(this.getDstIp())) {
- return true;
- }
- return false;
+ return NetUtils.isIPv6AddressValid(this.getSrcIp()) || NetUtils.isIPv6AddressValid(this.getDstIp());
}
public List<String> getActions() {
result = prime * result + ((dlDst == null) ? 0 : dlDst.hashCode());
result = prime * result + ((dlSrc == null) ? 0 : dlSrc.hashCode());
result = prime * result + (dynamic ? 1231 : 1237);
- result = prime * result
- + ((etherType == null) ? 0 : etherType.hashCode());
- result = prime * result
- + ((ingressPort == null) ? 0 : ingressPort.hashCode());
+ result = prime * result + ((etherType == null) ? 0 : etherType.hashCode());
+ result = prime * result + ((ingressPort == null) ? 0 : ingressPort.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((nwDst == null) ? 0 : nwDst.hashCode());
result = prime * result + ((nwSrc == null) ? 0 : nwSrc.hashCode());
- result = prime * result
- + ((portGroup == null) ? 0 : portGroup.hashCode());
- result = prime * result
- + ((priority == null) ? 0 : priority.hashCode());
- result = prime * result
- + ((protocol == null) ? 0 : protocol.hashCode());
+ result = prime * result + ((portGroup == null) ? 0 : portGroup.hashCode());
+ result = prime * result + ((priority == null) ? 0 : priority.hashCode());
+ result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
result = prime * result + ((node == null) ? 0 : node.hashCode());
result = prime * result + ((tosBits == null) ? 0 : tosBits.hashCode());
result = prime * result + ((tpDst == null) ? 0 : tpDst.hashCode());
result = prime * result + ((tpSrc == null) ? 0 : tpSrc.hashCode());
result = prime * result + ((vlanId == null) ? 0 : vlanId.hashCode());
- result = prime * result
- + ((vlanPriority == null) ? 0 : vlanPriority.hashCode());
- result = prime * result
- + ((idleTimeout == null) ? 0 : idleTimeout.hashCode());
- result = prime * result
- + ((hardTimeout == null) ? 0 : hardTimeout.hashCode());
+ result = prime * result + ((vlanPriority == null) ? 0 : vlanPriority.hashCode());
+ result = prime * result + ((idleTimeout == null) ? 0 : idleTimeout.hashCode());
+ result = prime * result + ((hardTimeout == null) ? 0 : hardTimeout.hashCode());
return result;
}
return false;
}
- Pattern macPattern = Pattern
- .compile("([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}");
+ Pattern macPattern = Pattern.compile("([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}");
Matcher mm = macPattern.matcher(mac);
if (!mm.matches()) {
- log.debug(
- "Ethernet address {} is not valid. Example: 00:05:b9:7c:81:5f",
- mac);
+ log.debug("Ethernet address {} is not valid. Example: 00:05:b9:7c:81:5f", mac);
return false;
}
return true;
return ((to >= 0) && (to <= 0xffff));
}
- private boolean conflictWithContainerFlow(IContainer container,
- StringBuffer resultStr) {
+ private Status conflictWithContainerFlow(IContainer container) {
// Return true if it's default container
if (container.getName().equals(GlobalConstants.DEFAULT.toString())) {
- return false;
+ return new Status(StatusCode.SUCCESS);
}
// No container flow = no conflict
List<ContainerFlow> cFlowList = container.getContainerFlows();
if (((cFlowList == null)) || cFlowList.isEmpty()) {
- return false;
+ return new Status(StatusCode.SUCCESS);
}
// Check against each container's flow
for (ContainerFlow cFlow : cFlowList) {
if (cFlow.allowsFlow(flow)) {
log.trace("Config is congruent with at least one container flow");
- return false;
+ return new Status(StatusCode.SUCCESS);
}
}
String msg = "Flow Config conflicts with all existing container flows";
- resultStr.append(msg);
log.trace(msg);
- return true;
+ return new Status(StatusCode.BADREQUEST, msg);
}
- public boolean isValid(IContainer container, StringBuffer resultStr) {
+ public Status validate(IContainer container) {
EtherIPType etype = EtherIPType.ANY;
EtherIPType ipsrctype = EtherIPType.ANY;
EtherIPType ipdsttype = EtherIPType.ANY;
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container.getName();
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container.getName();
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
Switch sw = null;
try {
- if (name == null) {
- resultStr.append(String.format("Name is null"));
- return false;
+ if (name == null || name.trim().isEmpty()) {
+ return new Status(StatusCode.BADREQUEST, "Invalid name");
}
+
if (node == null) {
- resultStr.append(String.format("Node is null"));
- return false;
+ return new Status(StatusCode.BADREQUEST, "Node is null");
}
+
if (switchManager != null) {
for (Switch device : switchManager.getNetworkDevices()) {
if (device.getNode().equals(node)) {
}
}
if (sw == null) {
- resultStr.append(String.format("Node %s not found", node));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Node %s not found", node));
}
} else {
log.debug("switchmanager is not set yet");
}
if (priority != null) {
- if (Integer.decode(priority) < 0
- || (Integer.decode(priority) > 65535)) {
- resultStr.append(String.format(
- "priority %s is not in the range 0 - 65535",
+ if (Integer.decode(priority) < 0 || (Integer.decode(priority) > 65535)) {
+ return new Status(StatusCode.BADREQUEST, String.format("priority %s is not in the range 0 - 65535",
priority));
- return false;
}
}
if (ingressPort != null) {
Short port = Short.decode(ingressPort);
if (isPortValid(sw, port) == false) {
- resultStr
- .append(String
- .format("Ingress port %d is not valid for the Switch",
- port));
- if ((container != null)
- && !container.getName().equals(
- GlobalConstants.DEFAULT.toString())) {
- resultStr
- .append(" in Container " + container.getName());
+ String msg = String.format("Ingress port %d is not valid for the Switch", port);
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ msg += " in Container " + containerName;
}
- return false;
+ return new Status(StatusCode.BADREQUEST, msg);
}
}
if ((vlanId != null) && !isVlanIdValid(vlanId)) {
- resultStr.append(String.format(
- "Vlan ID %s is not in the range 0 - 4095", vlanId));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Vlan ID %s is not in the range 0 - 4095",
+ vlanId));
}
if ((vlanPriority != null) && !isVlanPriorityValid(vlanPriority)) {
- resultStr.append(String.format(
- "Vlan priority %s is not in the range 0 - 7",
+ return new Status(StatusCode.BADREQUEST, String.format("Vlan priority %s is not in the range 0 - 7",
vlanPriority));
- return false;
}
-
if (etherType != null) {
int type = Integer.decode(etherType);
if ((type < 0) || (type > 0xffff)) {
- resultStr.append(String.format(
- "Ethernet type %s is not valid", etherType));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Ethernet type %s is not valid", etherType));
} else {
if (type == 0x800) {
etype = EtherIPType.V4;
}
if ((tosBits != null) && !isTOSBitsValid(tosBits)) {
- resultStr.append(String.format(
- "IP ToS bits %s is not in the range 0 - 63", tosBits));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("IP ToS bits %s is not in the range 0 - 63",
+ tosBits));
}
if ((tpSrc != null) && !isTpPortValid(tpSrc)) {
- resultStr.append(String.format(
- "Transport source port %s is not valid", tpSrc));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Transport source port %s is not valid", tpSrc));
}
+
if ((tpDst != null) && !isTpPortValid(tpDst)) {
- resultStr.append(String.format(
- "Transport destination port %s is not valid", tpDst));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Transport destination port %s is not valid",
+ tpDst));
}
if ((dlSrc != null) && !isL2AddressValid(dlSrc)) {
- resultStr
- .append(String
- .format("Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f",
- dlSrc));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", dlSrc));
}
if ((dlDst != null) && !isL2AddressValid(dlDst)) {
- resultStr
- .append(String
- .format("Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f",
- dlDst));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", dlDst));
}
if (nwSrc != null) {
} else if (NetUtils.isIPv6AddressValid(nwSrc)) {
ipsrctype = EtherIPType.V6;
} else {
- resultStr.append(String.format(
- "IP source address %s is not valid", nwSrc));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("IP source address %s is not valid", nwSrc));
}
}
} else if (NetUtils.isIPv6AddressValid(nwDst)) {
ipdsttype = EtherIPType.V6;
} else {
- resultStr.append(String.format(
- "IP destination address %s is not valid", nwDst));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("IP destination address %s is not valid",
+ nwDst));
}
}
if (etype != EtherIPType.ANY) {
if ((ipsrctype != EtherIPType.ANY) && (ipsrctype != etype)) {
- resultStr.append(String
- .format("Type mismatch between Ethernet & Src IP"));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Type mismatch between Ethernet & Src IP"));
}
if ((ipdsttype != EtherIPType.ANY) && (ipdsttype != etype)) {
- resultStr.append(String
- .format("Type mismatch between Ethernet & Dst IP"));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Type mismatch between Ethernet & Dst IP"));
}
}
if (ipsrctype != ipdsttype) {
if (!((ipsrctype == EtherIPType.ANY) || (ipdsttype == EtherIPType.ANY))) {
- resultStr
- .append(String.format("IP Src Dest Type mismatch"));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("IP Src Dest Type mismatch"));
}
}
if ((idleTimeout != null) && !isTimeoutValid(idleTimeout)) {
- resultStr.append(String.format(
- "Idle Timeout value %s is not valid", idleTimeout));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Idle Timeout value %s is not valid",
+ idleTimeout));
}
if ((hardTimeout != null) && !isTimeoutValid(hardTimeout)) {
- resultStr.append(String.format(
- "Hard Timeout value %s is not valid", hardTimeout));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Hard Timeout value %s is not valid",
+ hardTimeout));
}
Matcher sstr;
sstr = Pattern.compile("OUTPUT=(.*)").matcher(actiongrp);
if (sstr.matches()) {
for (String t : sstr.group(1).split(",")) {
- Matcher n = Pattern.compile("(?:(\\d+))")
- .matcher(t);
+ Matcher n = Pattern.compile("(?:(\\d+))").matcher(t);
if (n.matches()) {
if (n.group(1) != null) {
Short port = Short.parseShort(n.group(1));
if (isPortValid(sw, port) == false) {
- resultStr
- .append(String
- .format("Output port %d is not valid for this switch",
- port));
- if ((container != null)
- && !container.getName().equals(
- GlobalConstants.DEFAULT
- .toString())) {
- resultStr.append(" in Container "
- + container.getName());
+ String msg = String.format("Output port %d is not valid for this switch", port);
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ msg += " in Container " + containerName;
}
- return false;
+ return new Status(StatusCode.BADREQUEST, msg);
}
}
}
continue;
}
// Check src IP
- sstr = Pattern.compile(ActionType.FLOOD.toString())
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp);
if (sstr.matches()) {
- if (container != null) {
- resultStr.append(String.format(
- "flood is not allowed in container %s",
- container.getName()));
- return false;
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "flood is not allowed in container %s", containerName));
}
continue;
}
// Check src IP
- sstr = Pattern.compile(
- ActionType.SET_NW_SRC.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
if (!NetUtils.isIPv4AddressValid(sstr.group(1))) {
- resultStr.append(String.format(
- "IP source address %s is not valid",
+ return new Status(StatusCode.BADREQUEST, String.format("IP source address %s is not valid",
sstr.group(1)));
- return false;
}
continue;
}
// Check dst IP
- sstr = Pattern.compile(
- ActionType.SET_NW_DST.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
if (!NetUtils.isIPv4AddressValid(sstr.group(1))) {
- resultStr.append(String.format(
- "IP destination address %s is not valid",
- sstr.group(1)));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "IP destination address %s is not valid", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_VLAN_ID.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isVlanIdValid(sstr.group(1))) {
- resultStr.append(String.format(
- "Vlan ID %s is not in the range 0 - 4095",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isVlanIdValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Vlan ID %s is not in the range 0 - 4095", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_VLAN_PCP.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_VLAN_PCP.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isVlanPriorityValid(sstr.group(1))) {
- resultStr
- .append(String
- .format("Vlan priority %s is not in the range 0 - 7",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isVlanPriorityValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Vlan priority %s is not in the range 0 - 7", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_DL_SRC.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_DL_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isL2AddressValid(sstr.group(1))) {
- resultStr
- .append(String
- .format("Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f",
+ sstr.group(1)));
}
continue;
}
-
- sstr = Pattern.compile(
- ActionType.SET_DL_DST.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_DL_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isL2AddressValid(sstr.group(1))) {
- resultStr
- .append(String
- .format("Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f",
+ sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NW_TOS.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_TOS.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isTOSBitsValid(sstr.group(1))) {
- resultStr
- .append(String
- .format("IP ToS bits %s is not in the range 0 - 63",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isTOSBitsValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "IP ToS bits %s is not in the range 0 - 63", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_TP_SRC.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_TP_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isTpPortValid(sstr.group(1))) {
- resultStr.append(String.format(
- "Transport source port %s is not valid",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Transport source port %s is not valid", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_TP_DST.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_TP_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- if ((sstr.group(1) != null)
- && !isTpPortValid(sstr.group(1))) {
- resultStr
- .append(String
- .format("Transport destination port %s is not valid",
- sstr.group(1)));
- return false;
+ if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) {
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "Transport destination port %s is not valid", sstr.group(1)));
}
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NEXT_HOP.toString() + "=(.*)")
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
if (!NetUtils.isIPAddressValid(sstr.group(1))) {
- resultStr.append(String.format(
- "IP destination address %s is not valid",
- sstr.group(1)));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format(
+ "IP destination address %s is not valid", sstr.group(1)));
}
continue;
}
}
}
// Check against the container flow
- if ((container != null)
- && conflictWithContainerFlow(container, resultStr)) {
- return false;
+ Status status;
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString()) && !(status = conflictWithContainerFlow(container)).isSuccess()) {
+ return status;
}
} catch (NumberFormatException e) {
- resultStr.append(String.format("Invalid number format %s",
- e.getMessage()));
- return false;
+ return new Status(StatusCode.BADREQUEST, String.format("Invalid number format %s", e.getMessage()));
}
- return true;
+ return new Status(StatusCode.SUCCESS);
}
public FlowEntry getFlowEntry() {
- return new FlowEntry(FlowConfig.staticFlowsGroup, this.name,
- this.getFlow(), this.getNode());
+ return new FlowEntry(FlowConfig.staticFlowsGroup, this.name, this.getFlow(), this.getNode());
}
public Flow getFlow() {
Match match = new Match();
if (this.ingressPort != null) {
- match.setField(
- MatchType.IN_PORT,
- NodeConnectorCreator.createOFNodeConnector(
- Short.parseShort(ingressPort), getNode()));
+ match.setField(MatchType.IN_PORT,
+ NodeConnectorCreator.createOFNodeConnector(Short.parseShort(ingressPort), getNode()));
}
if (this.dlSrc != null) {
- match.setField(MatchType.DL_SRC,
- HexEncode.bytesFromHexString(this.dlSrc));
+ match.setField(MatchType.DL_SRC, HexEncode.bytesFromHexString(this.dlSrc));
}
if (this.dlDst != null) {
- match.setField(MatchType.DL_DST,
- HexEncode.bytesFromHexString(this.dlDst));
+ match.setField(MatchType.DL_DST, HexEncode.bytesFromHexString(this.dlDst));
}
if (this.etherType != null) {
- match.setField(MatchType.DL_TYPE, Integer.decode(etherType)
- .shortValue());
+ match.setField(MatchType.DL_TYPE, Integer.decode(etherType).shortValue());
}
if (this.vlanId != null) {
match.setField(MatchType.DL_VLAN, Short.parseShort(this.vlanId));
}
if (this.vlanPriority != null) {
- match.setField(MatchType.DL_VLAN_PR,
- Byte.parseByte(this.vlanPriority));
+ match.setField(MatchType.DL_VLAN_PR, Byte.parseByte(this.vlanPriority));
}
if (this.nwSrc != null) {
String parts[] = this.nwSrc.split("/");
InetAddress ip = NetUtils.parseInetAddress(parts[0]);
InetAddress mask = null;
+ int maskLen = 0;
if (parts.length > 1) {
- int maskLen = Integer.parseInt(parts[1]);
- mask = NetUtils.getInetNetworkMask(maskLen,
- ip instanceof Inet6Address);
+ maskLen = Integer.parseInt(parts[1]);
+ } else {
+ maskLen = (ip instanceof Inet6Address) ? 128 : 32;
}
+ mask = NetUtils.getInetNetworkMask(maskLen, ip instanceof Inet6Address);
match.setField(MatchType.NW_SRC, ip, mask);
}
if (this.nwDst != null) {
String parts[] = this.nwDst.split("/");
InetAddress ip = NetUtils.parseInetAddress(parts[0]);
InetAddress mask = null;
+ int maskLen = 0;
if (parts.length > 1) {
- int maskLen = Integer.parseInt(parts[1]);
- mask = NetUtils.getInetNetworkMask(maskLen,
- ip instanceof Inet6Address);
+ maskLen = Integer.parseInt(parts[1]);
+ } else {
+ maskLen = (ip instanceof Inet6Address) ? 128 : 32;
}
+ mask = NetUtils.getInetNetworkMask(maskLen, ip instanceof Inet6Address);
match.setField(MatchType.NW_DST, ip, mask);
}
if (this.protocol != null) {
- match.setField(MatchType.NW_PROTO,
- IPProtocols.getProtocolNumberByte(this.protocol));
+ match.setField(MatchType.NW_PROTO, IPProtocols.getProtocolNumberByte(this.protocol));
}
if (this.tosBits != null) {
match.setField(MatchType.NW_TOS, Byte.parseByte(this.tosBits));
}
if (this.tpSrc != null) {
- match.setField(MatchType.TP_SRC, Integer.valueOf(this.tpSrc)
- .shortValue());
+ match.setField(MatchType.TP_SRC, Integer.valueOf(this.tpSrc).shortValue());
}
if (this.tpDst != null) {
- match.setField(MatchType.TP_DST, Integer.valueOf(this.tpDst)
- .shortValue());
+ match.setField(MatchType.TP_DST, Integer.valueOf(this.tpDst).shortValue());
}
Flow flow = new Flow(match, getActionList());
return this.node.equals(node);
}
- public void toggleStatus() {
- installInHw = (installInHw == null) ? "true" : (installInHw
- .equals("true")) ? "false" : "true";
+ public void toggleInstallation() {
+ installInHw = (installInHw == null) ? "true" : (installInHw.equals("true")) ? "false" : "true";
}
/*
if (actions != null) {
Matcher sstr;
for (String actiongrp : actions) {
- sstr = Pattern.compile(ActionType.OUTPUT + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.OUTPUT + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
for (String t : sstr.group(1).split(",")) {
Matcher n = Pattern.compile("(?:(\\d+))").matcher(t);
if (n.matches()) {
if (n.group(1) != null) {
short ofPort = Short.parseShort(n.group(1));
- actionList.add(new Output(NodeConnectorCreator
- .createOFNodeConnector(ofPort,
- this.getNode())));
+ actionList.add(new Output(NodeConnectorCreator.createOFNodeConnector(ofPort,
+ this.getNode())));
}
}
}
continue;
}
- sstr = Pattern.compile(ActionType.DROP.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.DROP.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new Drop());
continue;
}
- sstr = Pattern.compile(ActionType.LOOPBACK.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.LOOPBACK.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new Loopback());
continue;
}
- sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new Flood());
continue;
}
- sstr = Pattern.compile(ActionType.SW_PATH.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SW_PATH.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new SwPath());
continue;
}
- sstr = Pattern.compile(ActionType.HW_PATH.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.HW_PATH.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new HwPath());
continue;
}
- sstr = Pattern.compile(ActionType.CONTROLLER.toString())
- .matcher(actiongrp);
+ sstr = Pattern.compile(ActionType.CONTROLLER.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new Controller());
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetVlanId(
- Short.parseShort(sstr.group(1))));
+ actionList.add(new SetVlanId(Short.parseShort(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_VLAN_PCP.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_VLAN_PCP.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList
- .add(new SetVlanPcp(Byte.parseByte(sstr.group(1))));
+ actionList.add(new SetVlanPcp(Byte.parseByte(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(ActionType.POP_VLAN.toString()).matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.POP_VLAN.toString()).matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new PopVlan());
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_DL_SRC.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_DL_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetDlSrc(HexEncode
- .bytesFromHexString(sstr.group(1))));
+ actionList.add(new SetDlSrc(HexEncode.bytesFromHexString(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_DL_DST.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_DL_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetDlDst(HexEncode
- .bytesFromHexString(sstr.group(1))));
+ actionList.add(new SetDlDst(HexEncode.bytesFromHexString(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NW_SRC.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetNwSrc(NetUtils.parseInetAddress(sstr
- .group(1))));
+ actionList.add(new SetNwSrc(NetUtils.parseInetAddress(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NW_DST.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetNwDst(NetUtils.parseInetAddress(sstr
- .group(1))));
+ actionList.add(new SetNwDst(NetUtils.parseInetAddress(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NW_TOS.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NW_TOS.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
actionList.add(new SetNwTos(Byte.parseByte(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_TP_SRC.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_TP_SRC.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList
- .add(new SetTpSrc(Integer.valueOf(sstr.group(1))));
+ actionList.add(new SetTpSrc(Integer.valueOf(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_TP_DST.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_TP_DST.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList
- .add(new SetTpDst(Integer.valueOf(sstr.group(1))));
+ actionList.add(new SetTpDst(Integer.valueOf(sstr.group(1))));
continue;
}
- sstr = Pattern.compile(
- ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(
- actiongrp);
+ sstr = Pattern.compile(ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(actiongrp);
if (sstr.matches()) {
- actionList.add(new SetNextHop(NetUtils.parseInetAddress(sstr
- .group(1))));
+ actionList.add(new SetNextHop(NetUtils.parseInetAddress(sstr.group(1))));
continue;
}
}
* instance the flows constituting a policy all share the same group name.
*/
public class FlowEntry implements Cloneable, Serializable {
- protected static final Logger logger = LoggerFactory
- .getLogger(FlowEntry.class);
+ protected static final Logger logger = LoggerFactory.getLogger(FlowEntry.class);
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(FlowEntry.class);
private String groupName; // group name
return cloned;
}
+ /*
+ * Only accounts fields which uniquely identify a flow for collision
+ * purposes: node, match and priority
+ */
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((flow == null) ? 0 : flow.hashCode());
- result = prime * result
- + ((flowName == null) ? 0 : flowName.hashCode());
- result = prime * result
- + ((groupName == null) ? 0 : groupName.hashCode());
result = prime * result + ((node == null) ? 0 : node.hashCode());
+ result = prime * result + ((flow == null) ? 0 : (int) flow.getPriority());
+ result = prime * result + ((flow == null || flow.getMatch() == null) ? 0 : flow.getMatch().hashCode());
+
return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
FlowEntry other = (FlowEntry) obj;
- if (flow == null) {
- if (other.flow != null)
+
+ if (node == null) {
+ if (other.node != null) {
return false;
- } else if (!flow.equals(other.flow))
+ }
+ } else if (!node.equals(other.node)) {
return false;
- if (flowName == null) {
- if (other.flowName != null)
- return false;
- } else if (!flowName.equals(other.flowName))
+ }
+
+ if (flow == null) {
+ return (other.flow == null) ? true : false;
+ } else if (other.flow == null) {
return false;
- if (groupName == null) {
- if (other.groupName != null)
- return false;
- } else if (!groupName.equals(other.groupName))
+ }
+ if (flow.getPriority() != other.flow.getPriority()) {
return false;
- if (node == null) {
- if (other.node != null)
+ }
+ if (flow.getMatch() == null) {
+ if (other.flow.getMatch() != null) {
return false;
- } else if (!node.equals(other.node))
+ }
+ } else if (!flow.getMatch().equals(other.flow.getMatch())) {
return false;
+ }
+
return true;
}
@Override
public String toString() {
- return "FlowEntry[flowName = " + flowName + ", groupName = "
- + groupName + ",node = " + node + ", flow = " + flow + "]";
+ return "FlowEntry[flowName = " + flowName + ", groupName = " + groupName + ", node = " + node + ", flow = "
+ + flow + "]";
}
private String constructFlowName() {
return this;
}
+
+ /**
+ * Returns whether this entry is the result of an internal generated static
+ * flow
+ *
+ * @return true if internal generated static flow, false otherwise
+ */
+ public boolean isInternal() {
+ return flowName.startsWith(FlowConfig.internalStaticFlowBegin);
+ }
}
package org.opendaylight.controller.forwardingrulesmanager;
+import java.io.Serializable;
+
import org.opendaylight.controller.sal.core.ContainerFlow;
import org.opendaylight.controller.sal.core.Node;
*
* Note: If the container flow is null, the install entry will be a clone of the
* original entry
- *
*/
-public class FlowEntryInstall {
- private FlowEntry original;
- private ContainerFlow cFlow;
- private FlowEntry install;
+public class FlowEntryInstall implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private final FlowEntry original;
+ private final ContainerFlow cFlow;
+ private final FlowEntry install;
transient private long requestId; // async request id
transient private boolean deletePending;
public FlowEntryInstall(FlowEntry original, ContainerFlow cFlow) {
this.original = original;
this.cFlow = cFlow;
- this.install = (cFlow == null) ? original.clone() : original
- .mergeWith(cFlow);
+ this.install = (cFlow == null) ? original.clone() : original.clone().mergeWith(cFlow);
deletePending = false;
requestId = 0;
}
+ /*
+ * Given FlowEntryInstall is used as key for FRM map which contains the
+ * software view of installed entries, having its hashcode tied to the one
+ * of the installed FlowEntry which takes into account the fields which
+ * uniquely identify a flow from switch point of view: node, match and
+ * priority.
+ */
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cFlow == null) ? 0 : cFlow.hashCode());
- result = prime * result + ((install == null) ? 0 : install.hashCode());
- result = prime * result
- + ((original == null) ? 0 : original.hashCode());
- return result;
+ return install.hashCode();
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
FlowEntryInstall other = (FlowEntryInstall) obj;
- if (cFlow == null) {
- if (other.cFlow != null)
- return false;
- } else if (!cFlow.equals(other.cFlow))
- return false;
if (install == null) {
- if (other.install != null)
+ if (other.install != null) {
return false;
- } else if (!install.equals(other.install))
- return false;
- if (original == null) {
- if (other.original != null)
- return false;
- } else if (!original.equals(other.original))
+ }
+ } else if (!install.equals(other.install)) {
return false;
+ }
return true;
}
return requestId;
}
+ /**
+ * Returns whether this entry is the result of an internal generated static
+ * flow
+ *
+ * @return true if internal generated static flow, false otherwise
+ */
+ public boolean isInternal() {
+ return original.isInternal();
+ }
+
@Override
public String toString() {
- return "[Install = " + install + " Original = " + original + " cFlow = "
- + cFlow + " rid = " + requestId + "]";
+ return "[Install = " + install + " Original = " + original + " cFlow = " + cFlow + " rid = " + requestId + "]";
}
}
/**
* Interface that describes methods for installing or removing forwarding rules
* and to access to the flows database.
- *
*/
public interface IForwardingRulesManager {
*/
public Status uninstallFlowEntry(FlowEntry flow);
+ /**
+ * It requests FRM to remove all the Flow Entry that are part of the
+ * specified group. FRM will request the SDN protocol plugin to uninstall
+ * the flows from the network node one by one. Based on the result of this
+ * operation FRM will update its database accordingly and will return the
+ * proper {@code Status} code.
+ *
+ * @param groupName
+ * the group name
+ * @return the {@code Status} object indicating the result of this action
+ */
+ public Status uninstallFlowEntryGroup(String groupName);
+
/**
* It requests FRM to replace the currently installed Flow Entry with the
* new one. It is up to the SDN protocol plugin to decide how to convey this
* not valid an error code is returned. If the existing flow is equal to the
* passed one it will be a no op and success code is returned.
*
- *
* @param newone
* the new flow entry to install
* @return the {@code Status} object indicating the result of this action
* call. A unique request id is returned to the caller. FRM will request the
* SDN protocol plugin to uninstall the flow from the network node. As
* immediate result of this asynchronous call, FRM will update its flow
- * database as if the flow was successfully installed.
+ * database as if the flow was successfully removed.
*
* @param flow
* the flow entry to uninstall
*/
public Status uninstallFlowEntryAsync(FlowEntry flow);
+ /**
+ * It requests FRM to remove all the Flow Entry that are part of the
+ * specified group through an asynchronous call. FRM will request the SDN
+ * protocol plugin to uninstall the flows from the network node one by one.
+ * As immediate result of this asynchronous call, FRM will update its flow
+ * database as if the flow was successfully removed.
+ *
+ * @param groupName
+ * the group name
+ * @return the {@code Status} object indicating the result of this action
+ */
+ public Status uninstallFlowEntryGroupAsync(String groupName);
+
/**
* It requests FRM to replace the currently installed Flow Entry with the
* new one through an asynchronous call. A unique request id is returned to
* @param dstPort
* the list of ports to be added to the flow output actions
*/
- public void addOutputPort(Node node, String flowName,
- List<NodeConnector> dstPort);
+ public void addOutputPort(Node node, String flowName, List<NodeConnector> dstPort);
/**
* Remove a list of output port from the flow with the specified name on the
* @param dstPortthe
* list of ports to be removed from the flow output actions
*/
- public void removeOutputPort(Node node, String flowName,
- List<NodeConnector> dstPort);
+ public void removeOutputPort(Node node, String flowName, List<NodeConnector> dstPort);
/**
* Replace the current output port in the specified flow with the specified
* @param dstPort
* the new output action port
*/
- public void replaceOutputPort(Node node, String flowName,
- NodeConnector outPort);
+ public void replaceOutputPort(Node node, String flowName, NodeConnector outPort);
/**
* Returns the output port configured on the specified flow
/**
* The interface which describes the methods forwarding rules manager will call
* for notifying the listeners of policy installation updates.
- *
*/
public interface IForwardingRulesManagerAware {
*
* PortGroup is used by PortGroupProvider application to signal a set of ports
* that represent a configured PortGroupConfig.
- *
- *
*/
public class PortGroup {
private long matrixSwitchId;
@Override
public String toString() {
- return "PortGroup [matrixSwitchId=" + matrixSwitchId + ", ports="
- + ports + "]";
+ return "PortGroup [matrixSwitchId=" + matrixSwitchId + ", ports=" + ports + "]";
}
}
* true indicates that the PortGroup is added. False indicates
* that the PortGroup is removed.
*/
- void portGroupChanged(PortGroupConfig config,
- Map<Node, PortGroup> portGroupData, boolean add);
+ void portGroupChanged(PortGroupConfig config, Map<Node, PortGroup> portGroupData, boolean add);
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((matchString == null) ? 0 : matchString.hashCode());
+ result = prime * result + ((matchString == null) ? 0 : matchString.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public String toString() {
- return "PortGroupConfig [name=" + name + ", matchString=" + matchString
- + "]";
+ return "PortGroupConfig [name=" + name + ", matchString=" + matchString + "]";
}
}
* @return PortGroup data for a given Openflow switch.
* @see PortGroup
*/
- public PortGroup getPortGroupData(PortGroupConfig config,
- long matrixSwitchId);
+ public PortGroup getPortGroupData(PortGroupConfig config, long matrixSwitchId);
/**
* Registers a Listener for Port Group membership changes based on Custom
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.sal.action.SetDlDst;
import org.opendaylight.controller.sal.action.SetNwDst;
import org.opendaylight.controller.sal.action.SetVlanId;
+import org.opendaylight.controller.sal.core.ContainerFlow;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.utils.IPProtocols;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.Status;
public class frmTest {
@Test
public void testFlowEntryInstall() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
- FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node),
- node);
- FlowEntryInstall fei = new FlowEntryInstall(pol, null);
- FlowEntryInstall fei2 = new FlowEntryInstall(pol, null);
- FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
+ FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node), node);
+ FlowEntryInstall fei = new FlowEntryInstall(pol.clone(), null);
+ FlowEntryInstall fei2 = new FlowEntryInstall(pol.clone(), null);
+ FlowEntryInstall fei3 = new FlowEntryInstall(pol2.clone(), null);
Assert.assertTrue(fei.getOriginal().equals(pol));
Assert.assertTrue(fei.getInstall().equals(pol));
Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName()));
fei.toBeDeleted();
Assert.assertTrue(fei.isDeletePending());
Assert.assertNull(fei.getContainerFlow());
- Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(),
- pol.getFlowName()));
+ Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(), pol.getFlowName()));
Assert.assertTrue(fei.equals(fei2));
- fei2.getOriginal().setFlowName("polTest2");
Assert.assertFalse(fei.equals(null));
- Assert.assertFalse(fei.equals(fei3));
+ Assert.assertTrue(fei.equals(fei3));
}
@Test
public void testFlowEntryCreation() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
Assert.assertTrue(pol.getFlow().equals(getSampleFlowV6(node)));
}
public void testFlowEntrySetGet() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
Node node2 = NodeCreator.createOFNode(2L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
pol.setGroupName("polTest2");
pol.setFlowName("flowName");
Assert.assertTrue(pol.getFlowName().equals("flowName"));
public void testFlowEntryEquality() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
Node node2 = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
- FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node2);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
+ FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node), node2);
Assert.assertTrue(pol.equals(pol2));
}
+ @Test
+ public void testFlowEntryCollision() throws UnknownHostException {
+ // Create 2 equal FlowEntry objects
+ Node node1 = NodeCreator.createOFNode(1L);
+ Node node2 = NodeCreator.createOFNode(1L);
+ FlowEntry fe1 = new FlowEntry("Junit", "flow1", getSampleFlowV6(node1), node1);
+ FlowEntry fe2 = new FlowEntry("Junit", "flow2", getSampleFlowV6(node2), node1);
+
+ // Check equality in FlowEntry and parameters
+ Assert.assertTrue(fe1.getFlow().getMatch().equals(fe2.getFlow().getMatch()));
+ Assert.assertTrue(fe1.getFlow().getMatch().getMatches() == fe2.getFlow().getMatch().getMatches());
+ Assert.assertTrue(fe1.getFlow().getMatch().hashCode() == fe2.getFlow().getMatch().hashCode());
+ Assert.assertTrue(fe1.getFlow().hashCode() == fe2.getFlow().hashCode());
+ Assert.assertTrue(fe1.equals(fe2));
+ Assert.assertTrue(fe1.hashCode() == fe2.hashCode());
+
+ // Change priority field for fe2, verify inequality
+ fe2.getFlow().setPriority((short)1000);
+
+ // Verify FlowEntry works as key in collection
+ ConcurrentMap<FlowEntry, FlowEntry> map = new ConcurrentHashMap<FlowEntry, FlowEntry>();
+ Assert.assertTrue(null == map.put(fe1, fe1));
+ Assert.assertTrue(fe1.clone().equals(map.put(fe1.clone(), fe1.clone())));
+ Assert.assertTrue(map.get(fe1.clone()).equals(fe1.clone()));
+ Assert.assertTrue(map.keySet().contains(fe1.clone()));
+ Assert.assertTrue(map.containsKey(fe1));
+
+ // Remove key
+ map.remove(fe1);
+ Assert.assertTrue(map.isEmpty());
+ Assert.assertFalse(map.containsKey(fe1));
+
+ // Verify cloned object as key
+ map.put(fe1.clone(), fe1.clone());
+ Assert.assertTrue(map.containsKey(fe1));
+
+ // Verify different key is not present
+ Assert.assertFalse(map.containsKey(fe2));
+
+ // Add different key
+ map.put(fe2.clone(), fe2.clone());
+ Assert.assertTrue(map.size() == 2);
+ Assert.assertTrue(map.containsKey(fe1));
+ Assert.assertTrue(map.containsKey(fe2));
+
+ // Make fe2 equal to fe1 again
+ fe2.getFlow().setPriority((short)300);
+ Assert.assertTrue(fe2.equals(fe1));
+ Assert.assertTrue(map.containsKey(fe2));
+
+ // Clean up
+ map.clear();
+ }
+
+ @Test
+ public void testFlowEntryInstallCollision() throws UnknownHostException {
+ // Create 2 equal FlowEntryInstall objects
+ Node node1 = NodeCreator.createOFNode(1L);
+ Node node2 = NodeCreator.createOFNode(1L);
+ FlowEntry fe1 = new FlowEntry("Junit", "flow1", getSampleFlowV6(node1), node1);
+ FlowEntry fe2 = new FlowEntry("Junit", "flow2", getSampleFlowV6(node2), node1);
+ ContainerFlow cf1 = null;
+ ContainerFlow cf2 = null;
+ FlowEntryInstall fei1 = new FlowEntryInstall(fe1, cf1);
+ FlowEntryInstall fei2 = new FlowEntryInstall(fe2, cf2);
+
+ // Check equality in FlowEntry and parameters
+ Assert.assertTrue(fei1.equals(fei2));
+ Assert.assertTrue(fei1.hashCode() == fei2.hashCode());
+
+ // Verify FlowEntryInstall works as key in collection
+ ConcurrentMap<FlowEntryInstall, FlowEntryInstall> map =
+ new ConcurrentHashMap<FlowEntryInstall, FlowEntryInstall>();
+ Assert.assertTrue(null == map.put(fei1, fei1));
+ Assert.assertTrue(map.get(fei1).equals(fei2));
+ Assert.assertTrue(map.keySet().contains(fei1));
+ Assert.assertTrue(map.keySet().contains(fei2));
+ Assert.assertTrue(map.containsKey(fei1));
+
+ // Remove key
+ map.remove(fei1);
+ Assert.assertTrue(map.isEmpty());
+ Assert.assertFalse(map.containsKey(fei1));
+
+ // Verify cloned object as key
+ map.put(fei1, fei1);
+ Assert.assertTrue(map.containsKey(fei1));
+
+ // Change fei2, change relevant hashcode info
+ fei2.getInstall().getFlow().setPriority((short)301);
+ Assert.assertFalse(fei1.equals(fei2));
+ Assert.assertFalse(fei1.hashCode() == fei2.hashCode());
+
+
+ // Verify different key is not present
+ Assert.assertFalse(map.containsKey(fei2));
+
+ // Add different key
+ map.put(fei2, fei2);
+ Assert.assertTrue(map.size() == 2);
+ Assert.assertTrue(map.containsKey(fei1));
+ Assert.assertTrue(map.containsKey(fei2));
+
+ // Make fei2 equal to fei1 again
+ fei2.getInstall().getFlow().setPriority((short)300);
+ Assert.assertTrue(fei2.equals(fei1));
+ Assert.assertTrue(map.containsKey(fei2));
+
+ // Clean up
+ map.clear();
+ }
+
@Test
public void testFlowEntryCloning() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
FlowEntry pol2 = pol.clone();
Assert.assertTrue(pol.equals(pol2));
}
FlowConfig frmC = new FlowConfig();
FlowConfig frmC3 = new FlowConfig();
Node node = NodeCreator.createOFNode(1L);
- FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
// testing equal function
Assert.assertFalse(frmC.equals(null));
Assert.assertFalse(frmC.equals(flowC));
frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertTrue(frmC.getNode().equals(
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertTrue(frmC.getNode().equals(Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
Assert.assertFalse(frmC.equals(frmC3));
frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
FlowConfig fc2 = new FlowConfig();
fc.setName("flow1");
fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
- "0")));
- Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
- "1")));
-
- Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
- Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
- Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
+ Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+
+ Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1", Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1", Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
+ Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2", Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
fc2.setName("flow1");
@Test
public void testStatusToggle() throws UnknownHostException {
FlowConfig fc = new FlowConfig();
- fc.toggleStatus();
+ fc.toggleInstallation();
Assert.assertTrue(fc.installInHw());
- fc.toggleStatus();
+ fc.toggleInstallation();
Assert.assertFalse(fc.installInHw());
- fc.toggleStatus();
+ fc.toggleInstallation();
Assert.assertTrue(fc.installInHw());
}
@Test
public void testValid() throws UnknownHostException {
- StringBuffer sb = new StringBuffer();
- sb.setLength(0);
FlowConfig fc2 = createSampleFlowConfig();
- Assert.assertTrue(fc2.isValid(null, sb));
+ Assert.assertTrue(fc2.validate(null).isSuccess());
FlowConfig fc = new FlowConfig();
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Name is null"));
+ Status status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Invalid name"));
fc.setName("Config");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Node is null"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Node is null"));
fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setPriority("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "is not in the range 0 - 65535"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 65535"));
fc.setPriority("100000");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "is not in the range 0 - 65535"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 65535"));
+
fc.setPriority("2000");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setCookie("100");
+ Assert.assertTrue(fc.validate(null).isSuccess());
+
fc.setIngressPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not valid for the Switch"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not valid for the Switch"));
+
fc.setIngressPort("100");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setVlanId(("-1"));
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("is not in the range 0 - 4095"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 4095"));
+
fc.setVlanId("5000");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("is not in the range 0 - 4095"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 4095"));
+
fc.setVlanId("100");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
+
fc.setVlanPriority("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 7"));
+
fc.setVlanPriority("9");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 7"));
+
fc.setVlanPriority("5");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setEtherType("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet type"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet type"));
+
fc.setEtherType("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet type"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet type"));
+
fc.setEtherType("0x800");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setTosBits("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP ToS bits"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP ToS bits"));
+
fc.setTosBits("65");
- sb.setLength(0);
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP ToS bits"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP ToS bits"));
+
fc.setTosBits("60");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setSrcPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport source port"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport source port"));
+
fc.setSrcPort("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport source port"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport source port"));
+
fc.setSrcPort("0x00ff");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setDstPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport destination port"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport destination port"));
+
fc.setDstPort("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport destination port"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport destination port"));
+
fc.setDstPort("0x00ff");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setSrcMac("abc");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet source address"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet source address"));
+
fc.setSrcMac("00:A0:C9:14:C8:29");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setDstMac("abc");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("Ethernet destination address"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet destination address"));
+
fc.setDstMac("00:A0:C9:22:AB:11");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setSrcIp("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP source address"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP source address"));
+
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Src IP"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Src IP"));
fc.setEtherType("0x86dd");
- Assert.assertTrue(fc.isValid(null, sb));
- sb.setLength(0);
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setSrcIp("1.1.1.1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Src IP"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Src IP"));
+
fc.setEtherType("0x800");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setDstIp("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP destination address"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP destination address"));
+
fc.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Dst IP"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Dst IP"));
fc.setEtherType("0x86dd");
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertTrue(fc.isValid(null, sb));
- sb.setLength(0);
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setDstIp("2.2.2.2");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Dst IP"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Dst IP"));
+
fc.setEtherType("0x800");
fc.setSrcIp("1.1.1.1");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setEtherType(null);
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP Src Dest Type mismatch"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP Src Dest Type mismatch"));
+
fc.setSrcIp("1.1.1.1");
fc.setIdleTimeout("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
- sb.setLength(0);
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Idle Timeout value"));
+
fc.setIdleTimeout("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Idle Timeout value"));
+
fc.setIdleTimeout("10");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
fc.setHardTimeout("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Hard Timeout value"));
+
fc.setHardTimeout("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
+ status = fc.validate(null);
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Hard Timeout value"));
+
fc.setHardTimeout("10");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate(null).isSuccess());
}
ArrayList<String> actions;
actions = createSampleActionList();
// actions.add(ActionType.CONTROLLER.toString());
- FlowConfig flowConfig = new FlowConfig("true", "Config1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1"), "100", "0",
- "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29",
- "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0",
- "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
+ FlowConfig flowConfig = new FlowConfig("true", "Config1", Node.fromString(Node.NodeIDType.OPENFLOW, "1"),
+ "100", "0", "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29", "00:A0:C9:22:AB:11",
+ IPProtocols.TCP.toString(), "0", "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
return flowConfig;
}
}
private Flow getSampleFlowV6(Node node) throws UnknownHostException {
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
- (short) 30, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34,
- (byte) 0x9a, (byte) 0xee };
- InetAddress srcIP = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMask = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMask2 = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34, (byte) 0x9a, (byte) 0xee };
+ InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMask = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMask2 = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
short ethertype = EtherTypes.IPv6.shortValue();
short vlan = (short) 27;
actions.add(new PopVlan());
actions.add(new Flood());
- actions.add(new Controller());
-
Flow flow = new Flow(match, actions);
flow.setPriority((short) 300);
flow.setHardTimeout((short) 240);
import org.opendaylight.controller.sal.core.IContainerListener;
import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
-import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
import org.opendaylight.controller.hosttracker.IfIptoHost;
public class Activator extends ComponentActivatorAbstractBase {
- protected static final Logger logger = LoggerFactory
- .getLogger(Activator.class);
+ protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
/**
* Function called when the activator starts just after some initializations
* are done by the ComponentActivatorAbstractBase.
*
*/
+ @Override
public void init() {
}
* ComponentActivatorAbstractBase
*
*/
+ @Override
public void destroy() {
}
* instantiated in order to get an fully working implementation
* Object
*/
+ @Override
public Object[] getImplementations() {
Object[] res = { ForwardingRulesManagerImpl.class };
return res;
* per-container different behavior if needed, usually should not
* be the case though.
*/
+ @Override
public void configureInstance(Component c, Object imp, String containerName) {
if (imp.equals(ForwardingRulesManagerImpl.class)) {
String interfaces[] = null;
Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
Set<String> propSet = new HashSet<String>();
- propSet.add("staticFlows");
+ propSet.add("frm.flowsSaveEvent");
props.put("cachenames", propSet);
// export the service
- if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
- interfaces = new String[] { IContainerListener.class.getName(),
- ISwitchManagerAware.class.getName(),
- IForwardingRulesManager.class.getName(),
- IInventoryListener.class.getName(),
- ICacheUpdateAware.class.getName(),
- IConfigurationContainerAware.class.getName(),
- IFlowProgrammerListener.class.getName() };
- } else {
- interfaces = new String[] {
- ISwitchManagerAware.class.getName(),
- IForwardingRulesManager.class.getName(),
- IInventoryListener.class.getName(),
- ICacheUpdateAware.class.getName(),
- IConfigurationContainerAware.class.getName(),
- IFlowProgrammerListener.class.getName() };
- }
+ interfaces = new String[] { IContainerListener.class.getName(), ISwitchManagerAware.class.getName(),
+ IForwardingRulesManager.class.getName(), IInventoryListener.class.getName(),
+ ICacheUpdateAware.class.getName(), IConfigurationContainerAware.class.getName(),
+ IFlowProgrammerListener.class.getName() };
c.setInterface(interfaces, props);
- c.add(createContainerServiceDependency(containerName)
- .setService(IFlowProgrammerService.class)
- .setCallbacks("setFlowProgrammerService",
- "unsetFlowProgrammerService").setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(IFlowProgrammerService.class)
+ .setCallbacks("setFlowProgrammerService", "unsetFlowProgrammerService").setRequired(true));
- c.add(createContainerServiceDependency(containerName)
- .setService(IClusterContainerServices.class)
- .setCallbacks("setClusterContainerService",
- "unsetClusterContainerService").setRequired(true));
- c.add(createContainerServiceDependency(containerName)
- .setService(ISwitchManager.class)
- .setCallbacks("setSwitchManager", "unsetSwitchManager")
- .setRequired(true));
- c.add(createContainerServiceDependency(containerName)
- .setService(IForwardingRulesManagerAware.class)
- .setCallbacks("setFrmAware", "unsetFrmAware")
- .setRequired(false));
- c.add(createContainerServiceDependency(containerName)
- .setService(IfIptoHost.class)
- .setCallbacks("setHostFinder", "unsetHostFinder")
- .setRequired(true));
- c.add(createContainerServiceDependency(containerName)
- .setService(IContainer.class)
- .setCallbacks("setIContainer", "unsetIContainer")
- .setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService", "unsetClusterContainerService").setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(ISwitchManager.class)
+ .setCallbacks("setSwitchManager", "unsetSwitchManager").setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(IForwardingRulesManagerAware.class)
+ .setCallbacks("setFrmAware", "unsetFrmAware").setRequired(false));
+ c.add(createContainerServiceDependency(containerName).setService(IfIptoHost.class)
+ .setCallbacks("setHostFinder", "unsetHostFinder").setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(IContainer.class)
+ .setCallbacks("setIContainer", "unsetIContainer").setRequired(true));
}
}
}
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingQueue;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
* the network. It also maintains the central repository of all the forwarding
* rules installed on the network nodes.
*/
-public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
- PortGroupChangeListener, IContainerListener, ISwitchManagerAware,
- IConfigurationContainerAware, IInventoryListener, IObjectReader,
- ICacheUpdateAware<Long, String>, CommandProvider,
- IFlowProgrammerListener {
+public class ForwardingRulesManagerImpl implements IForwardingRulesManager, PortGroupChangeListener,
+ IContainerListener, ISwitchManagerAware, IConfigurationContainerAware, IInventoryListener, IObjectReader,
+ ICacheUpdateAware<Long, String>, CommandProvider, IFlowProgrammerListener {
private static final String SAVE = "Save";
private static final String NODEDOWN = "Node is Down";
- private static final Logger log = LoggerFactory
- .getLogger(ForwardingRulesManagerImpl.class);
+ private static final String SUCCESS = StatusCode.SUCCESS.toString();
+ private static final Logger log = LoggerFactory.getLogger(ForwardingRulesManagerImpl.class);
private Map<Long, String> flowsSaveEvent;
private String frmFileName;
private String portGroupFileName;
private ConcurrentMap<String, PortGroupConfig> portGroupConfigs;
private ConcurrentMap<PortGroupConfig, Map<Node, PortGroup>> portGroupData;
private ConcurrentMap<String, Object> TSPolicies;
- private boolean inContainerMode; // being used by default instance only
+ private boolean inContainerMode; // being used by global instance only
+ private boolean stopping;
+
/*
- * Flow database. It's the software view of what was installed on the
- * switch. It is indexed by node. For convenience a version indexed by group
- * name is also maintained. The core element is a class which contains the
- * flow entry pushed by the functional modules and the respective container
- * flow merged version. In absence of container flows, the two flow entries
- * are the same.
+ * Flow database. It's the software view of what was requested to install
+ * and what is installed on the switch. It is indexed by the entry itself.
+ * The entry's hashcode resumes the network node index, the flow's priority
+ * and the flow's match. The value element is a class which contains the
+ * flow entry pushed by the applications modules and the respective
+ * container flow merged version. In absence of container flows, the two
+ * flow entries are the same.
*/
- private ConcurrentMap<Node, Set<FlowEntryInstall>> nodeFlows;
- private ConcurrentMap<String, Set<FlowEntryInstall>> groupFlows;
+ private ConcurrentMap<FlowEntry, FlowEntry> originalSwView;
+ private ConcurrentMap<FlowEntryInstall, FlowEntryInstall> installedSwView;
+ /*
+ * Per node and per group indexing
+ */
+ private ConcurrentMap<Node, List<FlowEntryInstall>> nodeFlows;
+ private ConcurrentMap<String, List<FlowEntryInstall>> groupFlows;
+
/*
* Inactive flow list. This is for the global instance of FRM It will
* contain all the flow entries which were installed on the global container
private IFlowProgrammerService programmer;
private IClusterContainerServices clusterContainerService = null;
private ISwitchManager switchManager;
+ private Thread frmEventHandler;
+ protected BlockingQueue<FRMEvent> pendingEvents;
/**
* Adds a flow entry onto the network node It runs various validity checks
* the original flow entry application requested to add
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
private Status addEntry(FlowEntry flowEntry, boolean async) {
* Derive the container flow merged entries to install In presence of N
* container flows, we may end up with N different entries to install...
*/
- List<FlowEntryInstall> toInstallList = deriveInstallEntries(
- flowEntry.clone(), container.getContainerFlows());
+ List<FlowEntryInstall> toInstallList = deriveInstallEntries(flowEntry.clone(), container.getContainerFlows());
// Container Flow conflict Check
if (toInstallList.isEmpty()) {
for (FlowEntryInstall entry : toInstallList) {
// Conflict Check: Verify new entry would not overwrite existing
// ones
- if (findMatch(entry.getInstall(), false) != null) {
- log.warn("Operation Rejected: A flow with same match "
- + "and priority exists on the target node");
+ if (this.installedSwView.containsKey(entry)) {
+ log.warn("Operation Rejected: A flow with same match and priority exists on the target node");
log.trace("Aborting to install {}", entry);
continue;
}
// Declare failure if all the container flow merged entries clash with
// existing entries
if (toInstallSafe.size() == 0) {
- String msg = "A flow with same match and priority exists "
- + "on the target node";
+ String msg = "A flow with same match and priority exists on the target node";
String logMsg = msg + ": {}";
log.warn(logMsg, flowEntry);
return new Status(StatusCode.CONFLICT, msg);
if (ret.isSuccess()) {
oneSucceded = true;
/*
- * The first successful status response will be returned
- * For the asynchronous call, we can discard the container flow
- * complication for now and assume we will always deal with
- * one flow only per request
+ * The first successful status response will be returned For the
+ * asynchronous call, we can discard the container flow
+ * complication for now and assume we will always deal with one
+ * flow only per request
*/
succeded = ret;
} else {
error = ret;
- log.warn("Failed to install the entry: {}. The failure is: {}",
- installEntry, ret.getDescription());
+ log.warn("Failed to install the entry: {}. The failure is: {}", installEntry, ret.getDescription());
}
}
* @return the list of container flow merged entries good to be installed on
* this container
*/
- private List<FlowEntryInstall> deriveInstallEntries(FlowEntry request,
- List<ContainerFlow> cFlowList) {
- List<FlowEntryInstall> toInstallList = new ArrayList<FlowEntryInstall>(
- 1);
+ private List<FlowEntryInstall> deriveInstallEntries(FlowEntry request, List<ContainerFlow> cFlowList) {
+ List<FlowEntryInstall> toInstallList = new ArrayList<FlowEntryInstall>(1);
- if (container.getContainerFlows() == null
- || container.getContainerFlows().isEmpty()) {
+ if (container.getContainerFlows() == null || container.getContainerFlows().isEmpty()) {
// No container flows => entry good to be installed unchanged
toInstallList.add(new FlowEntryInstall(request.clone(), null));
} else {
// created
for (ContainerFlow cFlow : container.getContainerFlows()) {
if (cFlow.allowsFlow(request.getFlow())) {
- toInstallList.add(new FlowEntryInstall(request.clone(),
- cFlow));
+ toInstallList.add(new FlowEntryInstall(request.clone(), cFlow));
}
}
}
* @param newFlowEntry
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
- private Status modifyEntry(FlowEntry currentFlowEntry,
- FlowEntry newFlowEntry, boolean async) {
-
+ private Status modifyEntry(FlowEntry currentFlowEntry, FlowEntry newFlowEntry, boolean async) {
Status retExt;
// Sanity checks
- if (currentFlowEntry == null || currentFlowEntry.getNode() == null
- || newFlowEntry == null || newFlowEntry.getNode() == null) {
+ if (currentFlowEntry == null || currentFlowEntry.getNode() == null || newFlowEntry == null
+ || newFlowEntry.getNode() == null) {
String msg = "Modify: Invalid FlowEntry";
String logMsg = msg + ": {} or {}";
log.warn(logMsg, currentFlowEntry, newFlowEntry);
return new Status(StatusCode.NOTACCEPTABLE, msg);
}
if (!currentFlowEntry.getNode().equals(newFlowEntry.getNode())
- || !currentFlowEntry.getFlowName().equals(
- newFlowEntry.getFlowName())) {
+ || !currentFlowEntry.getFlowName().equals(newFlowEntry.getFlowName())) {
String msg = "Modify: Incompatible Flow Entries";
String logMsg = msg + ": {} and {}";
log.warn(logMsg, currentFlowEntry, newFlowEntry);
}
// Equality Check
- if (currentFlowEntry.equals(newFlowEntry)) {
+ if (currentFlowEntry.getFlow().equals(newFlowEntry.getFlow())) {
String msg = "Modify skipped as flows are the same";
String logMsg = msg + ": {} and {}";
log.debug(logMsg, currentFlowEntry, newFlowEntry);
return new Status(StatusCode.SUCCESS, msg);
}
- // Conflict Check: Verify the new entry would not conflict with another
- // existing one
- // This is a loose check on the previous original flow entry requests.
- // No check
- // on the container flow merged flow entries (if any) yet
- FlowEntryInstall sameMatchOriginalEntry = findMatch(newFlowEntry, true);
- if (sameMatchOriginalEntry != null
- && !sameMatchOriginalEntry.getOriginal().equals(
- currentFlowEntry)) {
- String msg = "Operation Rejected: Another flow with same match "
- + "and priority exists on the target node";
+ /*
+ * Conflict Check: Verify the new entry would not conflict with an
+ * existing one. This is a loose check on the previous original flow
+ * entry requests. No check on the container flow merged flow entries
+ * (if any) yet
+ */
+ FlowEntry sameMatchOriginalEntry = originalSwView.get(newFlowEntry);
+ if (sameMatchOriginalEntry != null && !sameMatchOriginalEntry.equals(currentFlowEntry)) {
+ String msg = "Operation Rejected: Another flow with same match and priority exists on the target node";
String logMsg = msg + ": {}";
log.warn(logMsg, currentFlowEntry);
return new Status(StatusCode.CONFLICT, msg);
}
// Derive the installed and toInstall entries
- List<FlowEntryInstall> installedList = deriveInstallEntries(
- currentFlowEntry.clone(), container.getContainerFlows());
- List<FlowEntryInstall> toInstallList = deriveInstallEntries(
- newFlowEntry.clone(), container.getContainerFlows());
+ List<FlowEntryInstall> installedList = deriveInstallEntries(currentFlowEntry.clone(),
+ container.getContainerFlows());
+ List<FlowEntryInstall> toInstallList = deriveInstallEntries(newFlowEntry.clone(), container.getContainerFlows());
if (toInstallList.isEmpty()) {
- String msg = "Modify Operation Rejected: The new entry "
- + "conflicts with all the container flows";
+ String msg = "Modify Operation Rejected: The new entry conflicts with all the container flows";
String logMsg = msg + ": {}";
log.warn(logMsg, newFlowEntry);
log.warn(msg);
}
List<FlowEntryInstall> toInstallSafe = new ArrayList<FlowEntryInstall>();
for (FlowEntryInstall installEntry : toInstallList) {
- // Conflict Check: Verify the new entry would not overwrite another
- // existing one
- FlowEntryInstall sameMatchEntry = findMatch(
- installEntry.getInstall(), false);
- if (sameMatchEntry != null
- && !sameMatchEntry.getOriginal().equals(currentFlowEntry)) {
- log.info("Modify: new container flow merged flow entry "
- + "clashes with existing flow");
+ /*
+ * Conflict Check: Verify the new entry would not overwrite another
+ * existing one
+ */
+ FlowEntryInstall sameMatchEntry = installedSwView.get(installEntry);
+ if (sameMatchEntry != null && !sameMatchEntry.getOriginal().equals(currentFlowEntry)) {
+ log.info("Modify: new container flow merged flow entry clashes with existing flow");
decouple = true;
} else {
toInstallSafe.add(installEntry);
int size = toInstallList.size();
while (i < size) {
// Modify and update database
- retModify = modifyEntryInternal(installedList.get(i),
- toInstallList.get(i), async);
+ retModify = modifyEntryInternal(installedList.get(i), toInstallList.get(i), async);
if (retModify.isSuccess()) {
i++;
} else {
}
// Check if uncompleted modify
if (i < size) {
- log.warn("Unable to perform a complete modify for all "
- + "the container flows merged entries");
+ log.warn("Unable to perform a complete modify for all the container flows merged entries");
// Restore original entries
int j = 0;
while (j < i) {
log.info("Attempting to restore initial entries");
- retExt = modifyEntryInternal(toInstallList.get(i),
- installedList.get(i), async);
+ retExt = modifyEntryInternal(toInstallList.get(i), installedList.get(i), async);
if (retExt.isSuccess()) {
j++;
} else {
succeeded = retModify;
}
/*
- * The first successful status response will be returned.
- * For the asynchronous call, we can discard the container flow
- * complication for now and assume we will always deal with
- * one flow only per request
+ * The first successful status response will be returned. For the
+ * asynchronous call, we can discard the container flow complication for
+ * now and assume we will always deal with one flow only per request
*/
return succeeded;
}
* @param newEntries
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
- private Status modifyEntryInternal(FlowEntryInstall currentEntries,
- FlowEntryInstall newEntries, boolean async) {
+ private Status modifyEntryInternal(FlowEntryInstall currentEntries, FlowEntryInstall newEntries, boolean async) {
// Modify the flow on the network node
- Status status = (async)?
- programmer.modifyFlowAsync(currentEntries.getNode(),
- currentEntries.getInstall().getFlow(), newEntries.getInstall()
- .getFlow()) :
- programmer.modifyFlow(currentEntries.getNode(),
- currentEntries.getInstall().getFlow(), newEntries.getInstall()
- .getFlow());
-
+ Status status = (async) ? programmer.modifyFlowAsync(currentEntries.getNode(), currentEntries.getInstall()
+ .getFlow(), newEntries.getInstall().getFlow()) : programmer.modifyFlow(currentEntries.getNode(),
+ currentEntries.getInstall().getFlow(), newEntries.getInstall().getFlow());
if (!status.isSuccess()) {
- log.warn(
- "SDN Plugin failed to program the flow: {}. The failure is: {}",
- newEntries.getInstall(), status.getDescription());
+ log.warn("SDN Plugin failed to program the flow: {}. The failure is: {}", newEntries.getInstall(),
+ status.getDescription());
return status;
}
- log.trace("Modified {} => {}", currentEntries.getInstall(),
- newEntries.getInstall());
+ log.trace("Modified {} => {}", currentEntries.getInstall(), newEntries.getInstall());
// Update DB
newEntries.setRequestId(status.getRequestId());
* (entry or node not present), it return successfully
*
* @param flowEntry
- * the flow entry to remove
+ * the flow entry to remove
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
- private synchronized Status removeEntry(FlowEntry flowEntry, boolean async) {
+ private Status removeEntry(FlowEntry flowEntry, boolean async) {
Status error = new Status(null, null);
// Sanity Check
}
// Derive the container flows merged installed entries
- List<FlowEntryInstall> installedList = deriveInstallEntries(
- flowEntry.clone(), container.getContainerFlows());
+ List<FlowEntryInstall> installedList = deriveInstallEntries(flowEntry.clone(), container.getContainerFlows());
- Set<FlowEntryInstall> flowsOnNode = nodeFlows.get(flowEntry.getNode());
Status succeeded = null;
boolean atLeastOneRemoved = false;
for (FlowEntryInstall entry : installedList) {
- if (flowsOnNode == null) {
- String msg = "Removal skipped (Node down) for flow entry";
- String logMsg = msg + ": {}";
- log.debug(logMsg, flowEntry);
- return new Status(StatusCode.SUCCESS, msg);
- }
- if (!flowsOnNode.contains(entry)) {
+ if (!installedSwView.containsKey(entry)) {
String logMsg = "Removal skipped (not present in software view) for flow entry: {}";
log.debug(logMsg, flowEntry);
if (installedList.size() == 1) {
if (!ret.isSuccess()) {
error = ret;
- log.warn("Failed to remove the entry: {}. The failure is: {}",
- entry.getInstall(), ret.getDescription());
+ log.warn("Failed to remove the entry: {}. The failure is: {}", entry.getInstall(), ret.getDescription());
if (installedList.size() == 1) {
// If we had only one entry to remove, this is fatal failure
return error;
* the flow entry to remove
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
private Status removeEntryInternal(FlowEntryInstall entry, boolean async) {
// Mark the entry to be deleted (for CC just in case we fail)
entry.toBeDeleted();
// Remove from node
- Status status = (async)?
- programmer.removeFlowAsync(entry.getNode(), entry
- .getInstall().getFlow()) :
- programmer.removeFlow(entry.getNode(), entry
- .getInstall().getFlow());
-
+ Status status = (async) ? programmer.removeFlowAsync(entry.getNode(), entry.getInstall().getFlow())
+ : programmer.removeFlow(entry.getNode(), entry.getInstall().getFlow());
if (!status.isSuccess()) {
- log.warn(
- "SDN Plugin failed to program the flow: {}. The failure is: {}",
- entry.getInstall(), status.getDescription());
+ log.warn("SDN Plugin failed to program the flow: {}. The failure is: {}", entry.getInstall(),
+ status.getDescription());
return status;
}
log.trace("Removed {}", entry.getInstall());
* the flow entry to install
* @param async
* the flag indicating if this is a asynchronous request
- * @return the status of this request. In case of asynchronous call, it
- * will contain the unique id assigned to this request
+ * @return the status of this request. In case of asynchronous call, it will
+ * contain the unique id assigned to this request
*/
private Status addEntriesInternal(FlowEntryInstall entry, boolean async) {
// Install the flow on the network node
- Status status = (async)?
- programmer.addFlowAsync(entry.getNode(), entry.getInstall()
- .getFlow()) :
- programmer.addFlow(entry.getNode(), entry.getInstall()
- .getFlow());
-
+ Status status = (async) ? programmer.addFlowAsync(entry.getNode(), entry.getInstall().getFlow()) : programmer
+ .addFlow(entry.getNode(), entry.getInstall().getFlow());
if (!status.isSuccess()) {
- log.warn(
- "SDN Plugin failed to program the flow: {}. The failure is: {}",
- entry.getInstall(), status.getDescription());
+ log.warn("SDN Plugin failed to program the flow: {}. The failure is: {}", entry.getInstall(),
+ status.getDescription());
return status;
}
return true;
}
- private synchronized void updateLocalDatabase(FlowEntryInstall entry,
- boolean add) {
+ private void updateLocalDatabase(FlowEntryInstall entry, boolean add) {
+ // Update the software view
+ updateSwViewes(entry, add);
+
// Update node indexed flow database
updateNodeFlowsDB(entry, add);
/*
* Update the node mapped flows database
*/
- private synchronized void updateNodeFlowsDB(FlowEntryInstall flowEntries, boolean add) {
+ private void updateSwViewes(FlowEntryInstall flowEntries, boolean add) {
+ if (add) {
+ originalSwView.put(flowEntries.getOriginal(), flowEntries.getOriginal());
+ installedSwView.put(flowEntries, flowEntries);
+ } else {
+ originalSwView.remove(flowEntries.getOriginal());
+ installedSwView.remove(flowEntries);
+ }
+ }
+
+ /*
+ * Update the node mapped flows database
+ */
+ private void updateNodeFlowsDB(FlowEntryInstall flowEntries, boolean add) {
Node node = flowEntries.getNode();
- Set<FlowEntryInstall> flowEntrylist = this.nodeFlows.get(node);
- if (flowEntrylist == null) {
- if (add == false) {
+ List<FlowEntryInstall> nodeIndeces = this.nodeFlows.get(node);
+ if (nodeIndeces == null) {
+ if (!add) {
return;
} else {
- flowEntrylist = new HashSet<FlowEntryInstall>();
+ nodeIndeces = new ArrayList<FlowEntryInstall>();
}
}
- if (add == true) {
- flowEntrylist.add(flowEntries);
+ if (add) {
+ nodeIndeces.add(flowEntries);
} else {
- flowEntrylist.remove(flowEntries);
+ nodeIndeces.remove(flowEntries);
}
- if (flowEntrylist.isEmpty()) {
+ // Update cache across cluster
+ if (nodeIndeces.isEmpty()) {
this.nodeFlows.remove(node);
} else {
- this.nodeFlows.put(node, flowEntrylist);
+ this.nodeFlows.put(node, nodeIndeces);
}
}
* Update the group name mapped flows database
*/
private void updateGroupFlowsDB(FlowEntryInstall flowEntries, boolean add) {
- Set<FlowEntryInstall> flowList;
- FlowEntryInstall exists = null;
- String flowName = flowEntries.getFlowName();
String groupName = flowEntries.getGroupName();
- if (this.groupFlows == null) {
- return;
- }
-
// Flow may not be part of a group
if (groupName == null) {
return;
}
- if (this.groupFlows.containsKey(groupName)) {
- flowList = this.groupFlows.get(groupName);
- } else {
- if (add == false) {
+ List<FlowEntryInstall> indices = this.groupFlows.get(groupName);
+ if (indices == null) {
+ if (!add) {
return;
} else {
- flowList = new HashSet<FlowEntryInstall>();
- }
- }
-
- for (FlowEntryInstall flow : flowList) {
- if (flow.equalsByNodeAndName(flowEntries.getNode(), flowName)) {
- exists = flow;
- break;
+ indices = new ArrayList<FlowEntryInstall>();
}
}
- if (exists == null && add == false) {
- return;
- }
-
- if (exists != null) {
- flowList.remove(exists);
- }
-
- if (add == true) {
- flowList.add(flowEntries);
+ if (add) {
+ indices.add(flowEntries);
+ } else {
+ indices.remove(flowEntries);
}
- if (flowList.isEmpty()) {
+ // Update cache across cluster
+ if (indices.isEmpty()) {
this.groupFlows.remove(groupName);
} else {
- this.groupFlows.put(groupName, flowList);
+ this.groupFlows.put(groupName, indices);
}
}
* entry is effectively present in the local database
*/
@SuppressWarnings("unused")
- private synchronized Status removeEntry(Node node, String flowName) {
+ private Status removeEntry(Node node, String flowName) {
FlowEntryInstall target = null;
// Find in database
- for (FlowEntryInstall entry : this.nodeFlows.get(node)) {
+ for (FlowEntryInstall entry : installedSwView.values()) {
if (entry.equalsByNodeAndName(node, flowName)) {
target = entry;
break;
}
// Remove from node
- Status status = programmer.removeFlow(target.getNode(), target
- .getInstall().getFlow());
+ Status status = programmer.removeFlow(target.getNode(), target.getInstall().getFlow());
// Update DB
if (status.isSuccess()) {
updateLocalDatabase(target, false);
} else {
// log the error
- log.warn(
- "SDN Plugin failed to remove the flow: {}. The failure is: {}",
- target.getInstall(), status.getDescription());
+ log.warn("SDN Plugin failed to remove the flow: {}. The failure is: {}", target.getInstall(),
+ status.getDescription());
}
return status;
}
@Override
- public Status modifyFlowEntry(FlowEntry currentFlowEntry,
- FlowEntry newFlowEntry) {
+ public Status modifyFlowEntry(FlowEntry currentFlowEntry, FlowEntry newFlowEntry) {
Status status = null;
if (inContainerMode) {
String msg = "Controller in container mode: Modify Refused";
@Override
public Status modifyOrAddFlowEntry(FlowEntry newFlowEntry) {
/*
- * Run a loose check on the installed entries to decide whether to go
- * with a add or modify method. A loose check means only check against
- * the original flow entry requests and not against the installed flow
+ * Run a check on the original entries to decide whether to go with a
+ * add or modify method. A loose check means only check against the
+ * original flow entry requests and not against the installed flow
* entries which are the result of the original entry merged with the
* container flow(s) (if any). The modifyFlowEntry method in presence of
* conflicts with the Container flows (if any) would revert back to a
* delete + add pattern
*/
- FlowEntryInstall currentFlowEntries = findMatch(newFlowEntry, true);
+ FlowEntry currentFlowEntry = originalSwView.get(newFlowEntry);
- if (currentFlowEntries != null) {
- return modifyFlowEntry(currentFlowEntries.getOriginal(),
- newFlowEntry);
+ if (currentFlowEntry != null) {
+ return modifyFlowEntry(currentFlowEntry, newFlowEntry);
} else {
return installFlowEntry(newFlowEntry);
}
}
@Override
- public Status modifyOrAddFlowEntryAsync(FlowEntry newone) {
+ public Status modifyOrAddFlowEntryAsync(FlowEntry newFlowEntry) {
/*
- * Run a loose check on the installed entries to decide whether to go
- * with a add or modify method. A loose check means only check against
- * the original flow entry requests and not against the installed flow
+ * Run a check on the original entries to decide whether to go with a
+ * add or modify method. A loose check means only check against the
+ * original flow entry requests and not against the installed flow
* entries which are the result of the original entry merged with the
* container flow(s) (if any). The modifyFlowEntry method in presence of
* conflicts with the Container flows (if any) would revert back to a
* delete + add pattern
*/
- FlowEntryInstall currentFlowEntries = findMatch(newone, true);
+ FlowEntry currentFlowEntry = originalSwView.get(newFlowEntry);
- if (currentFlowEntries != null) {
- return modifyFlowEntryAsync(currentFlowEntries.getOriginal(),
- newone);
+ if (currentFlowEntry != null) {
+ return modifyFlowEntryAsync(currentFlowEntry, newFlowEntry);
} else {
- return installFlowEntryAsync(newone);
+ return installFlowEntryAsync(newFlowEntry);
}
}
-
- /**
- * Try to find in the database if a Flow with the same Match and priority of
- * the passed one already exists for the specified network node. Flow,
- * priority and network node are all specified in the FlowEntry If found,
- * the respective FlowEntryInstall Object is returned
- *
- * @param flowEntry
- * the FlowEntry to be tested against the ones installed
- * @param looseCheck
- * if true, the function will run the check against the original
- * flow entry portion of the installed entries
- * @return null if not found, otherwise the FlowEntryInstall which contains
- * the existing flow entry
- */
- private synchronized FlowEntryInstall findMatch(FlowEntry flowEntry, boolean looseCheck) {
- Flow flow = flowEntry.getFlow();
- Match match = flow.getMatch();
- short priority = flow.getPriority();
- Set<FlowEntryInstall> thisNodeList = nodeFlows.get(flowEntry.getNode());
-
- if (thisNodeList != null) {
- for (FlowEntryInstall flowEntries : thisNodeList) {
- flow = (looseCheck == false) ? flowEntries.getInstall()
- .getFlow() : flowEntries.getOriginal().getFlow();
- if (flow.getMatch().equals(match)
- && flow.getPriority() == priority) {
- return flowEntries;
+ @Override
+ public Status uninstallFlowEntryGroup(String groupName) {
+ if (groupName == null || groupName.isEmpty()) {
+ return new Status(StatusCode.BADREQUEST, "Invalid group name");
+ }
+ if (groupName.equals(FlowConfig.internalStaticFlowsGroup)) {
+ return new Status(StatusCode.BADREQUEST, "Static flows group cannot be deleted through this api");
+ }
+ if (inContainerMode) {
+ String msg = "Controller in container mode: Group Uninstall Refused";
+ String logMsg = msg + ": {}";
+ log.warn(logMsg, groupName);
+ return new Status(StatusCode.NOTACCEPTABLE, msg);
+ }
+ int toBeRemoved = groupFlows.get(groupName).size();
+ String error = "";
+ if (groupFlows.containsKey(groupName)) {
+ List<FlowEntryInstall> list = new ArrayList<FlowEntryInstall>(groupFlows.get(groupName));
+ for (FlowEntryInstall entry : list) {
+ Status status = this.removeEntry(entry.getOriginal(), false);
+ if (status.isSuccess()) {
+ toBeRemoved -= 1;
+ } else {
+ error = status.getDescription();
}
}
}
- return null;
+ return (toBeRemoved == 0) ? new Status(StatusCode.SUCCESS) : new Status(StatusCode.INTERNALERROR,
+ "Not all the flows were removed: " + error);
}
+ @Override
+ public Status uninstallFlowEntryGroupAsync(String groupName) {
+ if (groupName == null || groupName.isEmpty()) {
+ return new Status(StatusCode.BADREQUEST, "Invalid group name");
+ }
+ if (groupName.equals(FlowConfig.internalStaticFlowsGroup)) {
+ return new Status(StatusCode.BADREQUEST, "Static flows group cannot be deleted through this api");
+ }
+ if (inContainerMode) {
+ String msg = "Controller in container mode: Group Uninstall Refused";
+ String logMsg = msg + ": {}";
+ log.warn(logMsg, groupName);
+ return new Status(StatusCode.NOTACCEPTABLE, msg);
+ }
+ if (groupFlows.containsKey(groupName)) {
+ List<FlowEntryInstall> list = new ArrayList<FlowEntryInstall>(groupFlows.get(groupName));
+ for (FlowEntryInstall entry : list) {
+ this.removeEntry(entry.getOriginal(), true);
+ }
+ }
+ return new Status(StatusCode.SUCCESS);
+ }
+
+ @Override
public boolean checkFlowEntryConflict(FlowEntry flowEntry) {
return entryConflictsWithContainerFlows(flowEntry);
}
* merged flow may conflict with an existing old container flows merged flow
* on the network node
*/
- private synchronized void updateFlowsContainerFlow() {
- List<FlowEntryInstall> oldCouples = new ArrayList<FlowEntryInstall>();
- List<FlowEntry> toReinstall = new ArrayList<FlowEntry>();
- for (Entry<Node, Set<FlowEntryInstall>> entry : this.nodeFlows
- .entrySet()) {
- oldCouples.clear();
- toReinstall.clear();
- if (entry.getValue() == null) {
- continue;
- }
- // Create a set of old entries and one of original entries to be
- // reinstalled
- for (FlowEntryInstall oldCouple : entry.getValue()) {
- oldCouples.add(oldCouple);
- toReinstall.add(oldCouple.getOriginal());
- }
+ private void updateFlowsContainerFlow() {
+ Set<FlowEntry> toReInstall = new HashSet<FlowEntry>();
+ // First remove all installed entries
+ for (ConcurrentMap.Entry<FlowEntryInstall, FlowEntryInstall> entry : installedSwView.entrySet()) {
+ FlowEntryInstall current = entry.getValue();
+ // Store the original entry
+ toReInstall.add(current.getOriginal());
// Remove the old couples. No validity checks to be run, use the
// internal remove
- for (FlowEntryInstall oldCouple : oldCouples) {
- this.removeEntryInternal(oldCouple, false);
- }
+ this.removeEntryInternal(current, false);
+ }
+ // Then reinstall the original entries
+ for (FlowEntry entry : toReInstall) {
// Reinstall the original flow entries, via the regular path: new
// cFlow merge + validations
- for (FlowEntry flowEntry : toReinstall) {
- this.installFlowEntry(flowEntry);
- }
+ this.installFlowEntry(entry);
}
}
public void nonClusterObjectCreate() {
- nodeFlows = new ConcurrentHashMap<Node, Set<FlowEntryInstall>>();
+ originalSwView = new ConcurrentHashMap<FlowEntry, FlowEntry>();
+ installedSwView = new ConcurrentHashMap<FlowEntryInstall, FlowEntryInstall>();
+ nodeFlows = new ConcurrentHashMap<Node, List<FlowEntryInstall>>();
+ groupFlows = new ConcurrentHashMap<String, List<FlowEntryInstall>>();
TSPolicies = new ConcurrentHashMap<String, Object>();
- groupFlows = new ConcurrentHashMap<String, Set<FlowEntryInstall>>();
staticFlowsOrdinal = new ConcurrentHashMap<Integer, Integer>();
portGroupConfigs = new ConcurrentHashMap<String, PortGroupConfig>();
portGroupData = new ConcurrentHashMap<PortGroupConfig, Map<Node, PortGroup>>();
}
private void registerWithOSGIConsole() {
- BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- bundleContext.registerService(CommandProvider.class.getName(), this,
- null);
+ BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ bundleContext.registerService(CommandProvider.class.getName(), this, null);
}
@Override
@Override
public List<FlowEntry> getFlowEntriesForGroup(String policyName) {
List<FlowEntry> list = new ArrayList<FlowEntry>();
- if (this.groupFlows != null && this.groupFlows.containsKey(policyName)) {
- for (FlowEntryInstall entries : groupFlows.get(policyName)) {
- list.add(entries.getOriginal());
+ if (policyName != null && !policyName.trim().isEmpty()) {
+ for (Map.Entry<FlowEntry, FlowEntry> entry : this.originalSwView.entrySet()) {
+ if (policyName.equals(entry.getKey().getGroupName())) {
+ list.add(entry.getKey().clone());
+ }
}
}
return list;
}
@Override
- public synchronized void addOutputPort(Node node, String flowName,
- List<NodeConnector> portList) {
+ public void addOutputPort(Node node, String flowName, List<NodeConnector> portList) {
- Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
-
- for (FlowEntryInstall flow : flowEntryList) {
+ for (FlowEntryInstall flow : this.nodeFlows.get(node)) {
if (flow.getFlowName().equals(flowName)) {
FlowEntry currentFlowEntry = flow.getOriginal();
FlowEntry newFlowEntry = currentFlowEntry.clone();
}
Status error = modifyEntry(currentFlowEntry, newFlowEntry, false);
if (error.isSuccess()) {
- log.info("Ports {} added to FlowEntry {}", portList,
- flowName);
+ log.info("Ports {} added to FlowEntry {}", portList, flowName);
} else {
- log.warn(
- "Failed to add ports {} to Flow entry {}. The failure is: {}",
- portList, currentFlowEntry.toString(),
- error.getDescription());
+ log.warn("Failed to add ports {} to Flow entry {}. The failure is: {}", portList,
+ currentFlowEntry.toString(), error.getDescription());
}
return;
}
}
- log.warn("Failed to add ports to Flow {} on Node {}: Entry Not Found",
- flowName, node);
+ log.warn("Failed to add ports to Flow {} on Node {}: Entry Not Found", flowName, node);
}
@Override
- public synchronized void removeOutputPort(Node node, String flowName,
- List<NodeConnector> portList) {
-
- Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
-
- for (FlowEntryInstall flow : flowEntryList) {
+ public void removeOutputPort(Node node, String flowName, List<NodeConnector> portList) {
+ for (FlowEntryInstall index : this.nodeFlows.get(node)) {
+ FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
FlowEntry currentFlowEntry = flow.getOriginal();
FlowEntry newFlowEntry = currentFlowEntry.clone();
}
Status status = modifyEntry(currentFlowEntry, newFlowEntry, false);
if (status.isSuccess()) {
- log.info("Ports {} removed from FlowEntry {}", portList,
- flowName);
+ log.info("Ports {} removed from FlowEntry {}", portList, flowName);
} else {
- log.warn(
- "Failed to remove ports {} from Flow entry {}. The failure is: {}",
- portList, currentFlowEntry.toString(),
- status.getDescription());
+ log.warn("Failed to remove ports {} from Flow entry {}. The failure is: {}", portList,
+ currentFlowEntry.toString(), status.getDescription());
}
return;
}
}
- log.warn(
- "Failed to remove ports from Flow {} on Node {}: Entry Not Found",
- flowName, node);
+ log.warn("Failed to remove ports from Flow {} on Node {}: Entry Not Found", flowName, node);
}
/*
* This function assumes the target flow has only one output port
*/
@Override
- public synchronized void replaceOutputPort(Node node, String flowName,
- NodeConnector outPort) {
+ public void replaceOutputPort(Node node, String flowName, NodeConnector outPort) {
FlowEntry currentFlowEntry = null;
FlowEntry newFlowEntry = null;
- Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
// Find the flow
- for (FlowEntryInstall flow : flowEntryList) {
+ for (FlowEntryInstall index : this.nodeFlows.get(node)) {
+ FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
currentFlowEntry = flow.getOriginal();
break;
}
}
if (currentFlowEntry == null) {
- log.warn(
- "Failed to replace output port for flow {} on node {}: Entry Not Found",
- flowName, node);
+ log.warn("Failed to replace output port for flow {} on node {}: Entry Not Found", flowName, node);
return;
}
Status status = modifyEntry(currentFlowEntry, newFlowEntry, false);
if (status.isSuccess()) {
- log.info("Output port replaced with {} for flow {} on node {}",
- outPort, flowName, node);
+ log.info("Output port replaced with {} for flow {} on node {}", outPort, flowName, node);
} else {
- log.warn(
- "Failed to replace output port for flow {} on node {}. The failure is: {}",
- flowName, node, status.getDescription());
+ log.warn("Failed to replace output port for flow {} on node {}. The failure is: {}", flowName, node,
+ status.getDescription());
}
return;
}
@Override
- public synchronized NodeConnector getOutputPort(Node node, String flowName) {
- Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
-
- for (FlowEntryInstall flow : flowEntryList) {
+ public NodeConnector getOutputPort(Node node, String flowName) {
+ for (FlowEntryInstall index : this.nodeFlows.get(node)) {
+ FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
for (Action action : flow.getOriginal().getFlow().getActions()) {
if (action.getType() == ActionType.OUTPUT) {
}
}
}
-
return null;
}
return;
}
- log.debug("FRM allocateCaches for Container {}", container);
+ log.debug("Allocating caches for Container {}", container.getName());
try {
+ clusterContainerService.createCache("frm.originalSwView",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+
+ clusterContainerService.createCache("frm.installedSwView",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+
clusterContainerService.createCache("frm.nodeFlows",
EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
} catch (CacheConfigException cce) {
- log.error("FRM CacheConfigException", cce);
+ log.error("CacheConfigException");
} catch (CacheExistException cce) {
- log.error("FRM CacheExistException", cce);
+ log.error("CacheExistException");
}
}
return;
}
- log.debug("FRM retrieveCaches for Container {}", container);
+ log.debug("Retrieving Caches for Container {}", container.getName());
+
+ map = clusterContainerService.getCache("frm.originalSwView");
+ if (map != null) {
+ originalSwView = (ConcurrentMap<FlowEntry, FlowEntry>) map;
+ } else {
+ log.error("Retrieval of frm.originalSwView cache failed for Container {}", container.getName());
+ }
+
+ map = clusterContainerService.getCache("frm.installedSwView");
+ if (map != null) {
+ installedSwView = (ConcurrentMap<FlowEntryInstall, FlowEntryInstall>) map;
+ } else {
+ log.error("Retrieval of frm.installedSwView cache failed for Container {}", container.getName());
+ }
map = clusterContainerService.getCache("frm.nodeFlows");
if (map != null) {
- nodeFlows = (ConcurrentMap<Node, Set<FlowEntryInstall>>) map;
+ nodeFlows = (ConcurrentMap<Node, List<FlowEntryInstall>>) map;
} else {
- log.error(
- "FRM Cache frm.nodeFlows allocation failed for Container {}",
- container);
+ log.error("Retrieval of cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.groupFlows");
if (map != null) {
- groupFlows = (ConcurrentMap<String, Set<FlowEntryInstall>>) map;
+ groupFlows = (ConcurrentMap<String, List<FlowEntryInstall>>) map;
} else {
- log.error(
- "FRM Cache frm.groupFlows allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.groupFlows cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.staticFlows");
if (map != null) {
staticFlows = (ConcurrentMap<Integer, FlowConfig>) map;
} else {
- log.error(
- "FRM Cache frm.staticFlows allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.staticFlows cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.flowsSaveEvent");
if (map != null) {
flowsSaveEvent = (ConcurrentMap<Long, String>) map;
} else {
- log.error(
- "FRM Cache frm.flowsSaveEvent allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.flowsSaveEvent cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.staticFlowsOrdinal");
if (map != null) {
staticFlowsOrdinal = (ConcurrentMap<Integer, Integer>) map;
} else {
- log.error(
- "FRM Cache frm.staticFlowsOrdinal allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.staticFlowsOrdinal cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.portGroupConfigs");
if (map != null) {
portGroupConfigs = (ConcurrentMap<String, PortGroupConfig>) map;
} else {
- log.error(
- "FRM Cache frm.portGroupConfigs allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.portGroupConfigs cache failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.portGroupData");
if (map != null) {
portGroupData = (ConcurrentMap<PortGroupConfig, Map<Node, PortGroup>>) map;
} else {
- log.error(
- "FRM Cache frm.portGroupData allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.portGroupData allocation failed for Container {}", container.getName());
}
map = clusterContainerService.getCache("frm.TSPolicies");
if (map != null) {
TSPolicies = (ConcurrentMap<String, Object>) map;
} else {
- log.error(
- "FRM Cache frm.TSPolicies allocation failed for Container {}",
- container);
+ log.error("Retrieval of frm.TSPolicies cache failed for Container {}", container.getName());
}
}
- @SuppressWarnings("deprecation")
- private void destroyCaches() {
- if (this.clusterContainerService == null) {
- log.warn("Un-initialized clusterContainerService, can't destroy cache");
- return;
- }
-
- log.debug("FRM destroyCaches for Container {}", container);
- clusterContainerService.destroyCache("frm.nodeFlows");
- clusterContainerService.destroyCache("frm.TSPolicies");
- clusterContainerService.destroyCache("frm.groupFlows");
- clusterContainerService.destroyCache("frm.staticFlows");
- clusterContainerService.destroyCache("frm.flowsSaveEvent");
- clusterContainerService.destroyCache("frm.staticFlowsOrdinal");
- clusterContainerService.destroyCache("frm.portGroupData");
- clusterContainerService.destroyCache("frm.portGroupConfigs");
- nonClusterObjectCreate();
- }
-
private boolean flowConfigExists(FlowConfig config) {
- // As per customer requirement, flow name has to be unique on per node
- // id basis
- for (FlowConfig fc : staticFlows.values()) {
- if (fc.isByNameAndNodeIdEqual(config)) {
+ // Flow name has to be unique on per node id basis
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ if (entry.getValue().isByNameAndNodeIdEqual(config)) {
return true;
}
}
@Override
public Status addStaticFlow(FlowConfig config, boolean restore) {
- StringBuffer resultStr = new StringBuffer();
boolean multipleFlowPush = false;
String error;
Status status;
- config.setStatus(StatusCode.SUCCESS.toString());
+ config.setStatus(SUCCESS);
+
+ // Skip validation check if we are trying to restore a saved config
+ if (!restore && !(status = config.validate(container)).isSuccess()) {
+ log.warn("Invalid Configuration for flow {}. The failure is {}", config, status.getDescription());
+ error = "Invalid Configuration (" + status.getDescription() + ")";
+ config.setStatus(error);
+ return new Status(StatusCode.BADREQUEST, error);
+ }
// Presence check
if (flowConfigExists(config)) {
error = "Entry with this name on specified switch already exists";
- log.warn(
- "Entry with this name on specified switch already exists: {}",
- config);
+ log.warn("Entry with this name on specified switch already exists: {}", config);
config.setStatus(error);
return new Status(StatusCode.CONFLICT, error);
}
- // Skip validation check if we are trying to restore a saved config
- if (!restore && !config.isValid(container, resultStr)) {
- log.warn("Invalid Configuration for flow {}. The failure is {}",
- config, resultStr.toString());
- error = "Invalid Configuration (" + resultStr.toString() + ")";
- config.setStatus(error);
- return new Status(StatusCode.BADREQUEST, error);
- }
-
if ((config.getIngressPort() == null) && config.getPortGroup() != null) {
for (String portGroupName : portGroupConfigs.keySet()) {
if (portGroupName.equalsIgnoreCase(config.getPortGroup())) {
}
}
if (!multipleFlowPush) {
- log.warn(
- "Invalid Configuration(Invalid PortGroup Name) for flow {}",
- config);
+ log.warn("Invalid Configuration(Invalid PortGroup Name) for flow {}", config);
error = "Invalid Configuration (Invalid PortGroup Name)";
config.setStatus(error);
return new Status(StatusCode.BADREQUEST, error);
// Program hw
if (config.installInHw()) {
FlowEntry entry = config.getFlowEntry();
- status = this.addEntry(entry, false);
+ status = this.installFlowEntry(entry);
if (!status.isSuccess()) {
config.setStatus(status.getDescription());
if (!restore) {
staticFlows.put(ordinal, config);
if (multipleFlowPush) {
- PortGroupConfig pgconfig = portGroupConfigs.get(config
- .getPortGroup());
+ PortGroupConfig pgconfig = portGroupConfigs.get(config.getPortGroup());
Map<Node, PortGroup> existingData = portGroupData.get(pgconfig);
if (existingData != null) {
portGroupChanged(pgconfig, existingData, true);
}
private void addStaticFlowsToSwitch(Node node) {
- for (FlowConfig config : staticFlows.values()) {
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ FlowConfig config = entry.getValue();
if (config.isPortGroupEnabled()) {
continue;
}
if (config.getNode().equals(node)) {
- if (config.installInHw()
- && !config.getStatus().equals(
- StatusCode.SUCCESS.toString())) {
- Status status = this.addEntry(config.getFlowEntry(), false);
+ if (config.installInHw() && !config.getStatus().equals(SUCCESS)) {
+ Status status = this.installFlowEntryAsync(config.getFlowEntry());
config.setStatus(status.getDescription());
}
}
}
+ // Update cluster cache
+ refreshClusterStaticFlowsStatus(node);
}
private void updateStaticFlowConfigsOnNodeDown(Node node) {
for (Integer index : toRemove) {
staticFlows.remove(index);
}
+ // Update cluster cache
+ refreshClusterStaticFlowsStatus(node);
+
}
private void updateStaticFlowConfigsOnContainerModeChange(UpdateType update) {
- log.trace("Updating Static Flow configs on container mode change: {}",
- update);
+ log.trace("Updating Static Flow configs on container mode change: {}", update);
- for (FlowConfig config : staticFlows.values()) {
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ FlowConfig config = entry.getValue();
if (config.isPortGroupEnabled()) {
continue;
}
- if (config.installInHw()) {
+ if (config.installInHw() && !config.isInternalFlow()) {
switch (update) {
case ADDED:
config.setStatus("Removed from node because in container mode");
break;
case REMOVED:
- config.setStatus(StatusCode.SUCCESS.toString());
+ config.setStatus(SUCCESS);
break;
default:
}
}
}
+ // Update cluster cache
+ refreshClusterStaticFlowsStatus(null);
}
+ @Override
public Status removeStaticFlow(FlowConfig config) {
/*
* No config.isInternal() check as NB does not take this path and GUI
* reactive, so that we can remove the internal generated LLDP and ARP
* punt flows
*/
- for (Map.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+
+ // Look for the target configuration entry
+ Integer key = 0;
+ FlowConfig target = null;
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
if (entry.getValue().isByNameAndNodeIdEqual(config)) {
- // Program the network node
- Status status = this.removeEntry(config.getFlowEntry(), false);
- // Update configuration database if programming was successful
- if (status.isSuccess()) {
- staticFlows.remove(entry.getKey());
- return status;
- } else {
- entry.getValue().setStatus(status.getDescription());
- return status;
- }
+ key = entry.getKey();
+ target = entry.getValue();
+ break;
}
}
- return new Status(StatusCode.NOTFOUND, "Entry Not Present");
+ if (target == null) {
+ return new Status(StatusCode.NOTFOUND, "Entry Not Present");
+ }
+
+ // Program the network node
+ Status status = this.uninstallFlowEntry(config.getFlowEntry());
+
+ // Update configuration database if programming was successful
+ if (status.isSuccess()) {
+ staticFlows.remove(key);
+ }
+
+ return status;
}
@Override
public Status removeStaticFlow(String name, Node node) {
- for (Map.Entry<Integer, FlowConfig> mapEntry : staticFlows.entrySet()) {
- FlowConfig entry = mapEntry.getValue();
- Status status = new Status(null, null);
- if (entry.isByNameAndNodeIdEqual(name, node)) {
- // Validity check for api3 entry point
- if (entry.isInternalFlow()) {
- String msg = "Invalid operation: Controller generated "
- + "flow cannot be deleted";
- String logMsg = msg + ": {}";
- log.warn(logMsg, name);
- return new Status(StatusCode.NOTACCEPTABLE, msg);
- }
- if (!entry.isPortGroupEnabled()) {
- // Program the network node
- status = this.removeEntry(entry.getFlowEntry(), false);
- }
- // Update configuration database if programming was successful
- if (status.isSuccess()) {
- staticFlows.remove(mapEntry.getKey());
- return status;
- } else {
- entry.setStatus(status.getDescription());
- return status;
- }
+ // Look for the target configuration entry
+ Integer key = 0;
+ FlowConfig target = null;
+ for (ConcurrentMap.Entry<Integer, FlowConfig> mapEntry : staticFlows.entrySet()) {
+ if (mapEntry.getValue().isByNameAndNodeIdEqual(name, node)) {
+ key = mapEntry.getKey();
+ target = mapEntry.getValue();
+ break;
}
}
- return new Status(StatusCode.NOTFOUND, "Entry Not Present");
+ if (target == null) {
+ return new Status(StatusCode.NOTFOUND, "Entry Not Present");
+ }
+
+ // Validity check for api3 entry point
+ if (target.isInternalFlow()) {
+ String msg = "Invalid operation: Controller generated flow cannot be deleted";
+ String logMsg = msg + ": {}";
+ log.warn(logMsg, name);
+ return new Status(StatusCode.NOTACCEPTABLE, msg);
+ }
+
+ if (target.isPortGroupEnabled()) {
+ String msg = "Invalid operation: Port Group flows cannot be deleted through this API";
+ String logMsg = msg + ": {}";
+ log.warn(logMsg, name);
+ return new Status(StatusCode.NOTACCEPTABLE, msg);
+ }
+
+ // Program the network node
+ Status status = this.removeEntry(target.getFlowEntry(), false);
+
+ // Update configuration database if programming was successful
+ if (status.isSuccess()) {
+ staticFlows.remove(key);
+ }
+
+ return status;
}
+ @Override
public Status modifyStaticFlow(FlowConfig newFlowConfig) {
// Validity check for api3 entry point
if (newFlowConfig.isInternalFlow()) {
- String msg = "Invalid operation: Controller generated flow "
- + "cannot be modified";
+ String msg = "Invalid operation: Controller generated flow cannot be modified";
String logMsg = msg + ": {}";
log.warn(logMsg, newFlowConfig);
return new Status(StatusCode.NOTACCEPTABLE, msg);
}
// Validity Check
- StringBuffer resultStr = new StringBuffer();
- if (!newFlowConfig.isValid(container, resultStr)) {
- String msg = "Invalid Configuration (" + resultStr.toString() + ")";
+ Status status = newFlowConfig.validate(container);
+ if (!status.isSuccess()) {
+ String msg = "Invalid Configuration (" + status.getDescription() + ")";
newFlowConfig.setStatus(msg);
- log.warn("Invalid Configuration for flow {}. The failure is {}",
- newFlowConfig, resultStr.toString());
+ log.warn("Invalid Configuration for flow {}. The failure is {}", newFlowConfig, status.getDescription());
return new Status(StatusCode.BADREQUEST, msg);
}
FlowConfig oldFlowConfig = null;
Integer index = null;
- for (Map.Entry<Integer, FlowConfig> mapEntry : staticFlows.entrySet()) {
+ for (ConcurrentMap.Entry<Integer, FlowConfig> mapEntry : staticFlows.entrySet()) {
FlowConfig entry = mapEntry.getValue();
- if (entry.isByNameAndNodeIdEqual(newFlowConfig.getName(),
- newFlowConfig.getNode())) {
+ if (entry.isByNameAndNodeIdEqual(newFlowConfig.getName(), newFlowConfig.getNode())) {
oldFlowConfig = entry;
index = mapEntry.getKey();
break;
// Do not attempt to reinstall the flow, warn user
if (newFlowConfig.equals(oldFlowConfig)) {
String msg = "No modification detected";
- log.info(
- "Static flow modification skipped. New flow and old flow are the same: {}",
- newFlowConfig);
+ log.info("Static flow modification skipped. New flow and old flow are the same: {}", newFlowConfig);
return new Status(StatusCode.SUCCESS, msg);
}
// If flow is installed, program the network node
- Status status = new Status(StatusCode.SUCCESS, "Saved in config");
+ status = new Status(StatusCode.SUCCESS, "Saved in config");
if (oldFlowConfig.installInHw()) {
- status = this.modifyEntry(oldFlowConfig.getFlowEntry(),
- newFlowConfig.getFlowEntry(), false);
+ status = this.modifyFlowEntry(oldFlowConfig.getFlowEntry(), newFlowConfig.getFlowEntry());
}
// Update configuration database if programming was successful
}
// Validity check for api3 entry point
if (config.isInternalFlow()) {
- String msg = "Invalid operation: Controller generated flow "
- + "cannot be modified";
+ String msg = "Invalid operation: Controller generated flow cannot be modified";
String logMsg = msg + ": {}";
log.warn(logMsg, config);
return new Status(StatusCode.NOTACCEPTABLE, msg);
}
+ // Find the config entry
+ Integer key = 0;
+ FlowConfig target = null;
for (Map.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
FlowConfig conf = entry.getValue();
if (conf.isByNameAndNodeIdEqual(config)) {
- // Program the network node
- Status status = new Status(StatusCode.SUCCESS);
- if (conf.installInHw()) {
- status = this.removeEntry(conf.getFlowEntry(), false);
- } else {
- status = this.addEntry(conf.getFlowEntry(), false);
- }
- if (!status.isSuccess()) {
- conf.setStatus(status.getDescription());
- return status;
- }
-
+ key = entry.getKey();
+ target = conf;
+ break;
+ }
+ }
+ if (target != null) {
+ // Program the network node
+ Status status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
+ .installFlowEntry(target.getFlowEntry());
+ if (status.isSuccess()) {
// Update Configuration database
- conf.setStatus(StatusCode.SUCCESS.toString());
- conf.toggleStatus();
- return status;
+ target.setStatus(SUCCESS);
+ target.toggleInstallation();
+ staticFlows.put(key, target);
+ }
+ return status;
+ }
+
+ return new Status(StatusCode.NOTFOUND, "Unable to locate the entry. Failed to toggle status");
+ }
+
+ /**
+ * Reinsert all static flows entries in the cache to force cache updates in
+ * the cluster. This is useful when only some parameters were changed in the
+ * entries, like the status.
+ *
+ * @param node
+ * The node for which the static flow configurations have to be
+ * refreshed. If null, all nodes static flows will be refreshed.
+ */
+ private void refreshClusterStaticFlowsStatus(Node node) {
+ // Refresh cluster cache
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ if (node == null || entry.getValue().getNode().equals(node)) {
+ staticFlows.put(entry.getKey(), entry.getValue());
}
}
- return new Status(StatusCode.NOTFOUND,
- "Unable to locate the entry. Failed to toggle status");
}
/**
- * Uninstall all the Flow Entries present in the software view A copy of
- * each entry is stored in the inactive list so that it can be re-applied
- * when needed This function is called on the default container instance of
- * FRM only when the first container is created
+ * Uninstall all the non-internal Flow Entries present in the software view.
+ * A copy of each entry is stored in the inactive list so that it can be
+ * re-applied when needed. This function is called on the global instance of
+ * FRM only, when the first container is created
*/
private void uninstallAllFlowEntries() {
- log.info("Uninstalling all flows");
+ log.info("Uninstalling all non-internal flows");
// Store entries / create target list
- for (ConcurrentMap.Entry<Node, Set<FlowEntryInstall>> mapEntry : nodeFlows
- .entrySet()) {
- for (FlowEntryInstall flowEntries : mapEntry.getValue()) {
+ for (ConcurrentMap.Entry<FlowEntryInstall, FlowEntryInstall> mapEntry : installedSwView.entrySet()) {
+ FlowEntryInstall flowEntries = mapEntry.getValue();
+ // Skip internal generated static flows
+ if (!flowEntries.isInternal()) {
inactiveFlows.add(flowEntries.getOriginal());
}
}
for (FlowEntry flowEntry : inactiveFlows) {
Status status = this.removeEntry(flowEntry, false);
if (!status.isSuccess()) {
- log.warn("Failed to remove entry: {}. The failure is: {}",
- flowEntry, status.getDescription());
+ log.warn("Failed to remove entry: {}. The failure is: {}", flowEntry, status.getDescription());
}
}
}
log.info("Reinstalling all inactive flows");
for (FlowEntry flowEntry : this.inactiveFlows) {
- Status status = this.addEntry(flowEntry, false);
- if (!status.isSuccess()) {
- log.warn("Failed to install entry: {}. The failure is: {}",
- flowEntry, status.getDescription());
- }
+ this.addEntry(flowEntry, false);
}
// Empty inactive list in any case
inactiveFlows.clear();
}
+ @Override
public List<FlowConfig> getStaticFlows() {
- return getStaticFlowsOrderedList(staticFlows, staticFlowsOrdinal.get(0)
- .intValue());
+ return getStaticFlowsOrderedList(staticFlows, staticFlowsOrdinal.get(0).intValue());
}
- // TODO: need to come out with a better algorithm for mantaining the order
+ // TODO: need to come out with a better algorithm for maintaining the order
// of the configuration entries
// with actual one, index associated to deleted entries cannot be reused and
// map grows...
- private List<FlowConfig> getStaticFlowsOrderedList(
- ConcurrentMap<Integer, FlowConfig> flowMap, int maxKey) {
+ private List<FlowConfig> getStaticFlowsOrderedList(ConcurrentMap<Integer, FlowConfig> flowMap, int maxKey) {
List<FlowConfig> orderedList = new ArrayList<FlowConfig>();
for (int i = 0; i <= maxKey; i++) {
FlowConfig entry = flowMap.get(i);
@Override
public FlowConfig getStaticFlow(String name, Node node) {
- for (FlowConfig config : staticFlows.values()) {
- if (config.isByNameAndNodeIdEqual(name, node)) {
- return config;
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ if (entry.getValue().isByNameAndNodeIdEqual(name, node)) {
+ return entry.getValue();
}
}
return null;
@Override
public List<FlowConfig> getStaticFlows(Node node) {
List<FlowConfig> list = new ArrayList<FlowConfig>();
- for (FlowConfig config : staticFlows.values()) {
- if (config.onNode(node)) {
- list.add(config);
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ if (entry.getValue().onNode(node)) {
+ list.add(entry.getValue());
}
}
return list;
@Override
public List<String> getStaticFlowNamesForNode(Node node) {
List<String> list = new ArrayList<String>();
- for (FlowConfig config : staticFlows.values()) {
- if (config.onNode(node)) {
- list.add(config.getName());
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ if (entry.getValue().onNode(node)) {
+ list.add(entry.getValue().getName());
}
}
return list;
@Override
public List<Node> getListNodeWithConfiguredFlows() {
Set<Node> set = new HashSet<Node>();
- for (FlowConfig config : staticFlows.values()) {
- set.add(config.getNode());
+ for (ConcurrentMap.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
+ set.add(entry.getValue().getNode());
}
return new ArrayList<Node>(set);
}
@SuppressWarnings("unchecked")
private void loadFlowConfiguration() {
ObjectReader objReader = new ObjectReader();
- ConcurrentMap<Integer, FlowConfig> confList = (ConcurrentMap<Integer, FlowConfig>) objReader
- .read(this, frmFileName);
+ ConcurrentMap<Integer, FlowConfig> confList = (ConcurrentMap<Integer, FlowConfig>) objReader.read(this,
+ frmFileName);
- ConcurrentMap<String, PortGroupConfig> pgConfig = (ConcurrentMap<String, PortGroupConfig>) objReader
- .read(this, portGroupFileName);
+ ConcurrentMap<String, PortGroupConfig> pgConfig = (ConcurrentMap<String, PortGroupConfig>) objReader.read(this,
+ portGroupFileName);
if (pgConfig != null) {
- for (Map.Entry<String, PortGroupConfig> entry : pgConfig.entrySet()) {
- addPortGroupConfig(entry.getKey(), entry.getValue()
- .getMatchString(), true);
+ for (ConcurrentMap.Entry<String, PortGroupConfig> entry : pgConfig.entrySet()) {
+ addPortGroupConfig(entry.getKey(), entry.getValue().getMatchString(), true);
}
}
int maxKey = 0;
for (Integer key : confList.keySet()) {
- if (key.intValue() > maxKey)
+ if (key.intValue() > maxKey) {
maxKey = key.intValue();
+ }
}
for (FlowConfig conf : getStaticFlowsOrderedList(confList, maxKey)) {
}
@Override
- public Object readObject(ObjectInputStream ois)
- throws FileNotFoundException, IOException, ClassNotFoundException {
+ public Object readObject(ObjectInputStream ois) throws FileNotFoundException, IOException, ClassNotFoundException {
return ois.readObject();
}
+ @Override
public Status saveConfig() {
// Publish the save config event to the cluster nodes
flowsSaveEvent.put(new Date().getTime(), SAVE);
private Status saveConfigInternal() {
ObjectWriter objWriter = new ObjectWriter();
- ConcurrentHashMap<Integer, FlowConfig> nonDynamicFlows = new ConcurrentHashMap<Integer, FlowConfig>();
+ ConcurrentMap<Integer, FlowConfig> nonDynamicFlows = new ConcurrentHashMap<Integer, FlowConfig>();
for (Integer ordinal : staticFlows.keySet()) {
FlowConfig config = staticFlows.get(ordinal);
// Do not save dynamic and controller generated static flows
nonDynamicFlows.put(ordinal, config);
}
objWriter.write(nonDynamicFlows, frmFileName);
- objWriter.write(new ConcurrentHashMap<String, PortGroupConfig>(
- portGroupConfigs), portGroupFileName);
+ objWriter.write(new ConcurrentHashMap<String, PortGroupConfig>(portGroupConfigs), portGroupFileName);
return new Status(StatusCode.SUCCESS, null);
}
}
@Override
- public void entryUpdated(Long key, String new_value, String cacheName,
- boolean originLocal) {
+ public void entryUpdated(Long key, String new_value, String cacheName, boolean originLocal) {
saveConfigInternal();
}
allowARP.setName("**Punt ARP Reply");
allowARP.setPriority("500");
allowARP.setNode(node);
- allowARP.setEtherType("0x"
- + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
- allowARP.setDstMac(HexEncode.bytesToHexString(switchManager
- .getControllerMAC()));
+ allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
+ allowARP.setDstMac(HexEncode.bytesToHexString(switchManager.getControllerMAC()));
allowARP.setActions(puntAction);
addStaticFlow(allowARP, false);
}
allowARP.setName("**Punt ARP");
allowARP.setPriority("1");
allowARP.setNode(node);
- allowARP.setEtherType("0x"
- + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
+ allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
allowARP.setActions(puntAction);
defaultConfigs.add(allowARP);
allowLLDP.setName("**Punt LLDP");
allowLLDP.setPriority("1");
allowLLDP.setNode(node);
- allowLLDP
- .setEtherType("0x"
- + Integer.toHexString(EtherTypes.LLDP.intValue())
- .toUpperCase());
+ allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue()).toUpperCase());
allowLLDP.setActions(puntAction);
defaultConfigs.add(allowLLDP);
}
}
- log.info("Set Switch {} Mode to {}", node, proactive);
+ log.info("Set Switch {} Mode to {}", node, (proactive ? "proactive" : "reactive"));
}
/**
*
* @param node
*/
- private synchronized void cleanDatabaseForNode(Node node) {
- log.info("Cleaning Flow database for Node {}", node.toString());
-
- // Find out which groups the node's flows are part of
- Set<String> affectedGroups = new HashSet<String>();
- Set<FlowEntryInstall> flowEntryList = nodeFlows.get(node);
- if (flowEntryList != null) {
- for (FlowEntryInstall entry : flowEntryList) {
- String groupName = entry.getGroupName();
- if (groupName != null) {
- affectedGroups.add(groupName);
- }
- }
- }
+ private void cleanDatabaseForNode(Node node) {
+ log.info("Cleaning Flow database for Node {}", node);
+ if (nodeFlows.containsKey(node)) {
+ List<FlowEntryInstall> toRemove = new ArrayList<FlowEntryInstall>(nodeFlows.get(node));
- // Remove the node's flows from the group indexed flow database
- if (!affectedGroups.isEmpty()) {
- for (String group : affectedGroups) {
- Set<FlowEntryInstall> flowList = groupFlows.get(group);
- Set<FlowEntryInstall> toRemove = new HashSet<FlowEntryInstall>();
- for (FlowEntryInstall entry : flowList) {
- if (node.equals(entry.getNode())) {
- toRemove.add(entry);
- }
- }
- flowList.removeAll(toRemove);
- if (flowList.isEmpty()) {
- groupFlows.remove(group);
- }
+ for (FlowEntryInstall entry : toRemove) {
+ updateLocalDatabase(entry, false);
}
}
-
- // Remove the node's flows from the node indexed flow database
- nodeFlows.remove(node);
}
@Override
- public void notifyNode(Node node, UpdateType type,
- Map<String, Property> propMap) {
- switch (type) {
- case ADDED:
- addStaticFlowsToSwitch(node);
- break;
- case REMOVED:
- cleanDatabaseForNode(node);
- updateStaticFlowConfigsOnNodeDown(node);
- break;
- default:
- break;
- }
+ public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
+ this.pendingEvents.offer(new NodeUpdateEvent(type, node));
}
@Override
- public void notifyNodeConnector(NodeConnector nodeConnector,
- UpdateType type, Map<String, Property> propMap) {
+ public void notifyNodeConnector(NodeConnector nodeConnector, UpdateType type, Map<String, Property> propMap) {
+
}
- private FlowConfig getDerivedFlowConfig(FlowConfig original,
- String configName, Short port) {
+ private FlowConfig getDerivedFlowConfig(FlowConfig original, String configName, Short port) {
FlowConfig derivedFlow = new FlowConfig(original);
derivedFlow.setDynamic(true);
derivedFlow.setPortGroup(null);
return derivedFlow;
}
- private void addPortGroupFlows(PortGroupConfig config, Node node,
- PortGroup data) {
- for (Iterator<FlowConfig> it = staticFlows.values().iterator(); it
- .hasNext();) {
- FlowConfig staticFlow = it.next();
+ private void addPortGroupFlows(PortGroupConfig config, Node node, PortGroup data) {
+ for (FlowConfig staticFlow : staticFlows.values()) {
if (staticFlow.getPortGroup() == null) {
continue;
}
- if ((staticFlow.getNode().equals(node))
- && (staticFlow.getPortGroup().equals(config.getName()))) {
+ if ((staticFlow.getNode().equals(node)) && (staticFlow.getPortGroup().equals(config.getName()))) {
for (Short port : data.getPorts()) {
- FlowConfig derivedFlow = getDerivedFlowConfig(staticFlow,
- config.getName(), port);
+ FlowConfig derivedFlow = getDerivedFlowConfig(staticFlow, config.getName(), port);
addStaticFlow(derivedFlow, false);
}
}
}
}
- private void removePortGroupFlows(PortGroupConfig config, Node node,
- PortGroup data) {
- for (Iterator<FlowConfig> it = staticFlows.values().iterator(); it
- .hasNext();) {
- FlowConfig staticFlow = it.next();
+ private void removePortGroupFlows(PortGroupConfig config, Node node, PortGroup data) {
+ for (FlowConfig staticFlow : staticFlows.values()) {
if (staticFlow.getPortGroup() == null) {
continue;
}
- if ((staticFlow.getNode().equals(node))
- && (staticFlow.getPortGroup().equals(config.getName()))) {
+ if (staticFlow.getNode().equals(node) && staticFlow.getPortGroup().equals(config.getName())) {
for (Short port : data.getPorts()) {
- FlowConfig derivedFlow = getDerivedFlowConfig(staticFlow,
- config.getName(), port);
+ FlowConfig derivedFlow = getDerivedFlowConfig(staticFlow, config.getName(), port);
removeStaticFlow(derivedFlow);
}
}
}
@Override
- public void portGroupChanged(PortGroupConfig config,
- Map<Node, PortGroup> data, boolean add) {
+ public void portGroupChanged(PortGroupConfig config, Map<Node, PortGroup> data, boolean add) {
log.info("PortGroup Changed for: {} Data: {}", config, portGroupData);
Map<Node, PortGroup> existingData = portGroupData.get(config);
if (existingData != null) {
if (existingPortGroup == null) {
if (add) {
existingData.put(entry.getKey(), entry.getValue());
- addPortGroupFlows(config, entry.getKey(),
- entry.getValue());
+ addPortGroupFlows(config, entry.getKey(), entry.getValue());
}
} else {
if (add) {
- existingPortGroup.getPorts().addAll(
- entry.getValue().getPorts());
- addPortGroupFlows(config, entry.getKey(),
- entry.getValue());
+ existingPortGroup.getPorts().addAll(entry.getValue().getPorts());
+ addPortGroupFlows(config, entry.getKey(), entry.getValue());
} else {
- existingPortGroup.getPorts().removeAll(
- entry.getValue().getPorts());
- removePortGroupFlows(config, entry.getKey(),
- entry.getValue());
+ existingPortGroup.getPorts().removeAll(entry.getValue().getPorts());
+ removePortGroupFlows(config, entry.getKey(), entry.getValue());
}
}
}
}
}
+ @Override
public boolean addPortGroupConfig(String name, String regex, boolean restore) {
PortGroupConfig config = portGroupConfigs.get(name);
- if (config != null)
+ if (config != null) {
return false;
+ }
if ((portGroupProvider == null) && !restore) {
return false;
}
- if ((portGroupProvider != null)
- && (!portGroupProvider.isMatchCriteriaSupported(regex))) {
+ if ((portGroupProvider != null) && (!portGroupProvider.isMatchCriteriaSupported(regex))) {
return false;
}
return true;
}
+ @Override
public boolean delPortGroupConfig(String name) {
PortGroupConfig config = portGroupConfigs.get(name);
if (config == null) {
return;
}
if (portGroupProvider != null) {
- Map<Node, PortGroup> data = portGroupProvider
- .getPortGroupData(config);
+ Map<Node, PortGroup> data = portGroupProvider.getPortGroupData(config);
portGroupData.put(config, data);
}
}
return true;
}
- // Fir PortGroupProvider to use regular Dependency Manager
- /* @SuppressWarnings("rawtypes") */
- /* public void bind(Object arg0, Map arg1) throws Exception { */
- /* if (arg0 instanceof PortGroupProvider) { */
- /* setPortGroupProvider((PortGroupProvider)arg0); */
- /* } */
- /* } */
-
- /* @SuppressWarnings("rawtypes") */
- /* @Override */
- /* public void unbind(Object arg0, Map arg1) throws Exception { */
- /* if (arg0 instanceof PortGroupProvider) { */
- /* portGroupProvider = null; */
- /* } */
- /* } */
-
public void setIContainer(IContainer s) {
this.container = s;
}
}
}
+ @Override
public PortGroupProvider getPortGroupProvider() {
return portGroupProvider;
}
*
*/
void init() {
- frmAware = Collections
- .synchronizedSet(new HashSet<IForwardingRulesManagerAware>());
- frmFileName = GlobalConstants.STARTUPHOME.toString()
- + "frm_staticflows_" + this.getContainerName() + ".conf";
- portGroupFileName = GlobalConstants.STARTUPHOME.toString()
- + "portgroup_" + this.getContainerName() + ".conf";
+ frmAware = Collections.synchronizedSet(new HashSet<IForwardingRulesManagerAware>());
+ frmFileName = GlobalConstants.STARTUPHOME.toString() + "frm_staticflows_" + this.getContainerName() + ".conf";
+ portGroupFileName = GlobalConstants.STARTUPHOME.toString() + "portgroup_" + this.getContainerName() + ".conf";
inContainerMode = false;
if (staticFlowsOrdinal.size() == 0) {
staticFlowsOrdinal.put(0, Integer.valueOf(0));
}
+
+ pendingEvents = new LinkedBlockingQueue<FRMEvent>();
+
+ // Initialize the event handler thread
+ frmEventHandler = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!stopping) {
+ try {
+ FRMEvent event = pendingEvents.take();
+ if (event == null) {
+ log.warn("Dequeued null event");
+ continue;
+ }
+ if (event instanceof NodeUpdateEvent) {
+ NodeUpdateEvent update = (NodeUpdateEvent) event;
+ Node node = update.getNode();
+ switch (update.getUpdateType()) {
+ case ADDED:
+ addStaticFlowsToSwitch(node);
+ break;
+ case REMOVED:
+ cleanDatabaseForNode(node);
+ updateStaticFlowConfigsOnNodeDown(node);
+ break;
+ default:
+ }
+ } else if (event instanceof ErrorReportedEvent) {
+ ErrorReportedEvent errEvent = (ErrorReportedEvent) event;
+ processErrorEvent(errEvent);
+ } else {
+ log.warn("Dequeued unknown event {}", event.getClass().getSimpleName());
+ }
+ } catch (InterruptedException e) {
+ log.warn("FRM EventHandler thread interrupted", e);
+ }
+ }
+ }
+ }, "FRM EventHandler Collector");
}
/**
*
*/
void destroy() {
- destroyCaches();
}
/**
*
*/
void start() {
+ // Initialize graceful stop flag
+ stopping = false;
+
+ // Start event handler thread
+ frmEventHandler.start();
+
/*
* Read startup and build database if we have not already gotten the
* configurations synced from another node
* Function called by the dependency manager before the services exported by
* the component are unregistered, this will be followed by a "destroy ()"
* calls
- *
*/
void stop() {
+ stopping = true;
+ uninstallAllFlowEntries();
}
public void setFlowProgrammerService(IFlowProgrammerService service) {
}
@Override
- public void tagUpdated(String containerName, Node n, short oldTag,
- short newTag, UpdateType t) {
-
+ public void tagUpdated(String containerName, Node n, short oldTag, short newTag, UpdateType t) {
+ if (!container.getName().equals(containerName)) {
+ return;
+ }
}
@Override
- public void containerFlowUpdated(String containerName,
- ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) {
+ public void containerFlowUpdated(String containerName, ContainerFlow previous, ContainerFlow current,
+ UpdateType t) {
+ if (!container.getName().equals(containerName)) {
+ return;
+ }
+ log.trace("Container {}: Updating installed flows because of container flow change: {} {}",
+ container.getName(), t, current);
/*
* Whether it is an addition or removal, we have to recompute the merged
* flows entries taking into account all the current container flows
}
@Override
- public void nodeConnectorUpdated(String containerName, NodeConnector p,
- UpdateType t) {
- // No action
+ public void nodeConnectorUpdated(String containerName, NodeConnector p, UpdateType t) {
+ if (!container.getName().equals(containerName)) {
+ return;
+ }
}
@Override
public void containerModeUpdated(UpdateType update) {
+ // Only default container instance reacts on this event
+ if (!container.getName().equals(GlobalConstants.DEFAULT.toString())) {
+ return;
+ }
switch (update) {
case ADDED:
this.inContainerMode = true;
updateStaticFlowConfigsOnContainerModeChange(update);
}
+ protected abstract class FRMEvent {
+
+ }
+
+ private class NodeUpdateEvent extends FRMEvent {
+ private final Node node;
+ private final UpdateType update;
+
+ public NodeUpdateEvent(UpdateType update, Node node) {
+ this.update = update;
+ this.node = node;
+ }
+
+ public UpdateType getUpdateType() {
+ return update;
+ }
+
+ public Node getNode() {
+ return node;
+ }
+ }
+
+ private class ErrorReportedEvent extends FRMEvent {
+ private final long rid;
+ private final Node node;
+ private final Object error;
+
+ public ErrorReportedEvent(long rid, Node node, Object error) {
+ this.rid = rid;
+ this.node = node;
+ this.error = error;
+ }
+
+ public long getRequestId() {
+ return rid;
+ }
+
+ public Object getError() {
+ return error;
+ }
+
+ public Node getNode() {
+ return node;
+ }
+ }
+
/*
* OSGI COMMANDS
*/
ci.println(this.programmer.addFlow(node, getSampleFlow(node)));
}
- public void _frmremoveflow(CommandInterpreter ci)
- throws UnknownHostException {
+ public void _frmremoveflow(CommandInterpreter ci) throws UnknownHostException {
Node node = null;
String nodeId = ci.nextArgument();
if (nodeId == null) {
}
private Flow getSampleFlow(Node node) throws UnknownHostException {
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
- (short) 30, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
InetAddress srcIP = InetAddress.getByName("172.28.30.50");
InetAddress dstIP = InetAddress.getByName("171.71.9.52");
InetAddress ipMask = InetAddress.getByName("255.255.255.0");
}
public void _frmNodeFlows(CommandInterpreter ci) {
+ String nodeId = ci.nextArgument();
+ Node node = Node.fromString(nodeId);
+ if (node == null) {
+ ci.println("frmNodeFlows <node> [verbose]");
+ return;
+ }
boolean verbose = false;
String verboseCheck = ci.nextArgument();
if (verboseCheck != null) {
verbose = verboseCheck.equals("true");
}
+ if (!nodeFlows.containsKey(node)) {
+ return;
+ }
// Dump per node database
- for (Entry<Node, Set<FlowEntryInstall>> entry : this.nodeFlows
- .entrySet()) {
- Node node = entry.getKey();
- for (FlowEntryInstall flow : entry.getValue()) {
- if (!verbose) {
- ci.println(node + " " + flow.getFlowName());
- } else {
- ci.println(node + " " + flow.toString());
- }
+ for (FlowEntryInstall entry : nodeFlows.get(node)) {
+ if (!verbose) {
+ ci.println(node + " " + installedSwView.get(entry).getFlowName());
+ } else {
+ ci.println(node + " " + installedSwView.get(entry).toString());
}
}
}
public void _frmGroupFlows(CommandInterpreter ci) {
+ String group = ci.nextArgument();
+ if (group == null) {
+ ci.println("frmGroupFlows <group> [verbose]");
+ return;
+ }
boolean verbose = false;
String verboseCheck = ci.nextArgument();
if (verboseCheck != null) {
verbose = verboseCheck.equalsIgnoreCase("true");
}
+ if (!groupFlows.containsKey(group)) {
+ return;
+ }
// Dump per node database
- for (Entry<String, Set<FlowEntryInstall>> entry : this.groupFlows
- .entrySet()) {
- String group = entry.getKey();
- ci.println("Group " + group + ":");
- for (FlowEntryInstall flow : entry.getValue()) {
- if (!verbose) {
- ci.println(flow.getNode() + " " + flow.getFlowName());
- } else {
- ci.println(flow.getNode() + " " + flow.toString());
- }
+ ci.println("Group " + group + ":\n");
+ for (FlowEntryInstall flowEntry : groupFlows.get(group)) {
+ if (!verbose) {
+ ci.println(flowEntry.getNode() + " " + flowEntry.getFlowName());
+ } else {
+ ci.println(flowEntry.getNode() + " " + flowEntry.toString());
}
}
}
@Override
public void flowRemoved(Node node, Flow flow) {
log.trace("Received flow removed notification on {} for {}", node, flow);
- // For flow entry identification, only match and priority matter
- FlowEntry toFind = new FlowEntry("any", "any", flow, node);
- FlowEntryInstall installedEntry = this.findMatch(toFind, false);
+
+ // For flow entry identification, only node, match and priority matter
+ FlowEntryInstall test = new FlowEntryInstall(new FlowEntry("","",flow, node), null);
+ FlowEntryInstall installedEntry = this.installedSwView.get(test);
if (installedEntry == null) {
- log.trace("Entry is not know to us");
+ log.trace("Entry is not known to us");
return;
}
// Update Static flow status
+ Integer key = 0;
+ FlowConfig target = null;
for (Map.Entry<Integer, FlowConfig> entry : staticFlows.entrySet()) {
FlowConfig conf = entry.getValue();
if (conf.isByNameAndNodeIdEqual(installedEntry.getFlowName(), node)) {
- // Update Configuration database
- conf.toggleStatus();
+ key = entry.getKey();
+ target = conf;
break;
}
}
+ if (target != null) {
+ // Update Configuration database
+ target.toggleInstallation();
+ target.setStatus(SUCCESS);
+ staticFlows.put(key, target);
+ }
+
// Update software views
this.updateLocalDatabase(installedEntry, false);
}
@Override
- public synchronized void flowErrorReported(Node node, long rid, Object err) {
- log.trace("Got error {} for message rid {} from node {}",
- new Object[] {err, rid, node });
+ public void flowErrorReported(Node node, long rid, Object err) {
+ log.trace("Got error {} for message rid {} from node {}", new Object[] { err, rid, node });
+ pendingEvents.offer(new ErrorReportedEvent(rid, node, err));
+ }
+
+ private void processErrorEvent(ErrorReportedEvent event) {
+ Node node = event.getNode();
+ long rid = event.getRequestId();
+ Object error = event.getError();
+ String errorString = (error == null) ? "Not provided" : error.toString();
/*
- * If this was for a flow install, remove the corresponding entry
- * from the software view. If it was a Looking for the rid going through the
- * software database.
- * TODO: A more efficient rid <-> FlowEntryInstall mapping will
- * have to be added in future
+ * If this was for a flow install, remove the corresponding entry from
+ * the software view. If it was a Looking for the rid going through the
+ * software database. TODO: A more efficient rid <-> FlowEntryInstall
+ * mapping will have to be added in future
*/
- Set<FlowEntryInstall> entries = nodeFlows.get(node);
- if (entries != null) {
- FlowEntryInstall target = null;
- for (FlowEntryInstall entry : entries) {
- if (entry.getRequestId() == rid) {
- target = entry;
- break;
- }
- }
- if (target != null) {
- // This was a flow install, update database
- this.updateLocalDatabase(target, false);
+ FlowEntryInstall target = null;
+ for (FlowEntryInstall index : nodeFlows.get(node)) {
+ FlowEntryInstall entry = installedSwView.get(index);
+ if (entry.getRequestId() == rid) {
+ target = entry;
+ break;
}
}
+ if (target != null) {
+ // This was a flow install, update database
+ this.updateLocalDatabase(target, false);
+ }
// Notify listeners
if (frmAware != null) {
synchronized (frmAware) {
for (IForwardingRulesManagerAware frma : frmAware) {
try {
- frma.requestFailed(rid, err.toString());
+ frma.requestFailed(rid, errorString);
} catch (Exception e) {
log.warn("Failed to notify {}", frma);
}
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.osgi.framework.ServiceReference;
import org.opendaylight.controller.sal.action.Action;
import org.opendaylight.controller.sal.action.Drop;
import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.match.Match;
import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.controller.sal.reader.FlowOnNode;
-import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
-import org.opendaylight.controller.sal.reader.NodeDescription;
import org.opendaylight.controller.sal.utils.NodeCreator;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
assertNotNull(bc);
boolean debugit = false;
Bundle b[] = bc.getBundles();
- for (int i = 0; i < b.length; i++) {
- int state = b[i].getState();
+ for (Bundle element : b) {
+ int state = element.getState();
if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
- log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
+ log.debug("Bundle:" + element.getSymbolicName() + " state:"
+ stateToString(state));
debugit = true;
}
package org.opendaylight.controller.hosttracker.hostAware;
+import java.io.Serializable;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
@XmlRootElement(name = "host")
@XmlAccessorType(XmlAccessType.NONE)
-public class HostNodeConnector extends Host {
+public class HostNodeConnector extends Host implements Serializable {
private static final long serialVersionUID = 1L;
@XmlElement
private NodeConnector nodeConnector;
import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.HexEncode;
+import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.NodeCreator;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
* removed the database
*/
-public class HostTracker implements IfIptoHost, IfHostListener,
- ISwitchManagerAware, IInventoryListener, ITopologyManagerAware {
- private static final Logger logger = LoggerFactory
- .getLogger(HostTracker.class);
+public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAware, IInventoryListener,
+ ITopologyManagerAware {
+ private static final Logger logger = LoggerFactory.getLogger(HostTracker.class);
private IHostFinder hostFinder;
private ConcurrentMap<InetAddress, HostNodeConnector> hostsDB;
/*
* added here until both come up
*/
private ConcurrentMap<NodeConnector, HostNodeConnector> inactiveStaticHosts;
- private Set<IfNewHostNotify> newHostNotify = Collections
- .synchronizedSet(new HashSet<IfNewHostNotify>());
+ private final Set<IfNewHostNotify> newHostNotify = Collections.synchronizedSet(new HashSet<IfNewHostNotify>());
private ITopologyManager topologyManager;
private IClusterContainerServices clusterContainerService = null;
// This list contains the hosts for which ARP requests are being sent
// periodically
- private List<ARPPending> ARPPendingList = new ArrayList<HostTracker.ARPPending>();
+ private final List<ARPPending> ARPPendingList = new ArrayList<HostTracker.ARPPending>();
/*
* This list below contains the hosts which were initially in ARPPendingList
* above, but ARP response didn't come from there hosts after multiple
*
* We can't recover from condition 3 above
*/
- private ArrayList<ARPPending> failedARPReqList = new ArrayList<HostTracker.ARPPending>();
+ private final ArrayList<ARPPending> failedARPReqList = new ArrayList<HostTracker.ARPPending>();
public HostTracker() {
}
return hostsDB.get(networkAddress);
}
- private Entry<NodeConnector, HostNodeConnector> getHostFromInactiveDB(
- InetAddress networkAddress) {
- for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
- .entrySet()) {
+ private Entry<NodeConnector, HostNodeConnector> getHostFromInactiveDB(InetAddress networkAddress) {
+ for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts.entrySet()) {
if (entry.getValue().equalsByIP(networkAddress)) {
- logger.debug(
- "getHostFromInactiveDB(): Inactive Host found for IP:{} ",
- networkAddress.getHostAddress());
+ logger.debug("getHostFromInactiveDB(): Inactive Host found for IP:{} ", networkAddress.getHostAddress());
return entry;
}
}
- logger.debug(
- "getHostFromInactiveDB() Inactive Host Not found for IP: {}",
- networkAddress.getHostAddress());
+ logger.debug("getHostFromInactiveDB() Inactive Host Not found for IP: {}", networkAddress.getHostAddress());
return null;
}
private void removeHostFromInactiveDB(InetAddress networkAddress) {
NodeConnector nodeConnector = null;
- for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
- .entrySet()) {
+ for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts.entrySet()) {
if (entry.getValue().equalsByIP(networkAddress)) {
nodeConnector = entry.getKey();
break;
}
if (nodeConnector != null) {
inactiveStaticHosts.remove(nodeConnector);
- logger.debug("removeHostFromInactiveDB(): Host Removed for IP: {}",
- networkAddress.getHostAddress());
+ logger.debug("removeHostFromInactiveDB(): Host Removed for IP: {}", networkAddress.getHostAddress());
return;
}
- logger.debug("removeHostFromInactiveDB(): Host Not found for IP: {}",
- networkAddress.getHostAddress());
+ logger.debug("removeHostFromInactiveDB(): Host Not found for IP: {}", networkAddress.getHostAddress());
}
protected boolean hostMoved(HostNodeConnector host) {
return false;
}
+ @Override
public HostNodeConnector hostQuery(InetAddress networkAddress) {
return hostsDB.get(networkAddress);
}
+ @Override
public Future<HostNodeConnector> discoverHost(InetAddress networkAddress) {
ExecutorService executor = Executors.newFixedThreadPool(1);
if (executor == null) {
logger.error("discoverHost: Null executor");
return null;
}
- Callable<HostNodeConnector> worker = new HostTrackerCallable(this,
- networkAddress);
+ Callable<HostNodeConnector> worker = new HostTrackerCallable(this, networkAddress);
Future<HostNodeConnector> submit = executor.submit(worker);
return submit;
}
+ @Override
public HostNodeConnector hostFind(InetAddress networkAddress) {
/*
* Sometimes at boot with containers configured in the startup we hit
HostNodeConnector host = hostQuery(networkAddress);
if (host != null) {
- logger.debug("hostFind(): Host found for IP: {}",
- networkAddress.getHostAddress());
+ logger.debug("hostFind(): Host found for IP: {}", networkAddress.getHostAddress());
return host;
}
/* host is not found, initiate a discovery */
hostFinder.find(networkAddress);
/* Also add this host to ARPPending List for any potential retries */
AddtoARPPendingList(networkAddress);
- logger.debug(
- "hostFind(): Host Not Found for IP: {}, Inititated Host Discovery ...",
+ logger.debug("hostFind(): Host Not Found for IP: {}, Inititated Host Discovery ...",
networkAddress.getHostAddress());
return null;
}
+ @Override
public Set<HostNodeConnector> getAllHosts() {
Set<HostNodeConnector> allHosts = new HashSet<HostNodeConnector>();
for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
@Override
public Set<HostNodeConnector> getInactiveStaticHosts() {
Set<HostNodeConnector> list = new HashSet<HostNodeConnector>();
- for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
- .entrySet()) {
+ for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts.entrySet()) {
list.add(entry.getValue());
}
logger.debug("getInactiveStaticHosts(): Found {} Hosts", list.size());
private void removePendingARPFromList(int index) {
if (index >= ARPPendingList.size()) {
- logger.warn(
- "removePendingARPFromList(): index greater than the List. Size:{}, Index:{}",
+ logger.warn("removePendingARPFromList(): index greater than the List. Size:{}, Index:{}",
ARPPendingList.size(), index);
return;
}
htCallable.wakeup();
}
- public void setCallableOnPendingARP(InetAddress networkAddr,
- HostTrackerCallable callable) {
+ public void setCallableOnPendingARP(InetAddress networkAddr, HostTrackerCallable callable) {
ARPPending arphost;
for (int i = 0; i < ARPPendingList.size(); i++) {
arphost = ARPPendingList.get(i);
* the request
*/
removePendingARPFromList(i);
- logger.debug("Host Removed from ARPPending List, IP: {}",
- networkAddr);
+ logger.debug("Host Removed from ARPPending List, IP: {}", networkAddr);
return;
}
}
* the request
*/
failedARPReqList.remove(i);
- logger.debug("Host Removed from FailedARPReqList List, IP: {}",
- networkAddr);
+ logger.debug("Host Removed from FailedARPReqList List, IP: {}", networkAddr);
return;
}
}
// Learn a new Host
private void learnNewHost(HostNodeConnector host) {
host.initArpSendCountDown();
- hostsDB.put(host.getNetworkAddress(), host);
- logger.debug("New Host Learned: MAC: {} IP: {}",
- HexEncode.bytesToHexString(host.getDataLayerAddressBytes()),
- host.getNetworkAddress().getHostAddress());
+ HostNodeConnector rHost = hostsDB.putIfAbsent(host.getNetworkAddress(), host);
+ if (rHost != null) {
+ // Another host is already learned for this IP address, replace it
+ replaceHost(host.getNetworkAddress(), rHost, host);
+ } else {
+ logger.debug("New Host Learned: MAC: {} IP: {}", HexEncode.bytesToHexString(host
+ .getDataLayerAddressBytes()), host.getNetworkAddress().getHostAddress());
+ }
+ }
+
+ private void replaceHost(InetAddress networkAddr, HostNodeConnector removedHost, HostNodeConnector newHost) {
+ newHost.initArpSendCountDown();
+ if (hostsDB.replace(networkAddr, removedHost, newHost)) {
+ logger.debug("Host move occurred. Old Host:{}, New Host: {}", removedHost, newHost);
+ } else {
+ /*
+ * Host replacement has failed, do the recovery
+ */
+ hostsDB.put(networkAddr, newHost);
+ logger.error("Host replacement failed. Overwrite the host. Repalced Host: {}, New Host: {}", removedHost,
+ newHost);
+ }
+ notifyHostLearnedOrRemoved(removedHost, false);
+ notifyHostLearnedOrRemoved(newHost, true);
+ if (!newHost.isStaticHost()) {
+ ProcPendingARPReqs(networkAddr);
+ }
}
// Remove known Host
private void removeKnownHost(InetAddress key) {
HostNodeConnector host = hostsDB.get(key);
if (host != null) {
- logger.debug("Removing Host: IP:{}", host.getNetworkAddress()
- .getHostAddress());
+ logger.debug("Removing Host: IP:{}", host.getNetworkAddress().getHostAddress());
hostsDB.remove(key);
} else {
- logger.error(
- "removeKnownHost(): Host for IP address {} not found in hostsDB",
- key.getHostAddress());
+ logger.error("removeKnownHost(): Host for IP address {} not found in hostsDB", key.getHostAddress());
}
}
private class NotifyHostThread extends Thread {
- private HostNodeConnector host;
+ private final HostNodeConnector host;
public NotifyHostThread(HostNodeConnector h) {
this.host = h;
}
+ @Override
public void run() {
+ HostNodeConnector removedHost = null;
+ InetAddress networkAddr = host.getNetworkAddress();
+
/* Check for Host Move case */
if (hostMoved(host)) {
/*
* Host has been moved from one location (switch,port, MAC, or
- * VLAN). Remove the existing host with its previous location
- * parameters, inform the applications, and add it as a new Host
+ * VLAN) to another. Replace the existing host and its previous
+ * location parameters with new information, and notify the
+ * applications listening to host move.
*/
- HostNodeConnector removedHost = hostsDB.get(host
- .getNetworkAddress());
- removeKnownHost(host.getNetworkAddress());
+ removedHost = hostsDB.get(networkAddr);
if (removedHost != null) {
- notifyHostLearnedOrRemoved(removedHost, false);
- logger.debug(
- "Host move occurred. Old Host:{}, New Host: {}",
- removedHost, host);
+ replaceHost(networkAddr, removedHost, host);
+ return;
} else {
- logger.error(
- "Host to be removed not found in hostsDB. Host {}",
- removedHost);
+ logger.error("Host to be removed not found in hostsDB. Host {}", removedHost);
}
}
- /* check if there is an outstanding request for this host */
- InetAddress networkAddr = host.getNetworkAddress();
+ if (removedHost == null) {
+ // It is a new host
+ learnNewHost(host);
+ }
- // add and notify
- learnNewHost(host);
+ /* check if there is an outstanding request for this host */
ProcPendingARPReqs(networkAddr);
notifyHostLearnedOrRemoved(host, true);
}
}
+ @Override
public void hostListener(HostNodeConnector host) {
if (hostExists(host)) {
logger.debug("ARP received for Host: {}", host);
- HostNodeConnector existinghost = hostsDB.get(host
- .getNetworkAddress());
+ HostNodeConnector existinghost = hostsDB.get(host.getNetworkAddress());
existinghost.initArpSendCountDown();
return;
}
Host h = null;
NodeConnector p = host.getnodeConnector();
try {
- DataLinkAddress dla = new EthernetAddress(
- host.getDataLayerAddressBytes());
- h = new org.opendaylight.controller.sal.core.Host(dla,
- host.getNetworkAddress());
+ DataLinkAddress dla = new EthernetAddress(host.getDataLayerAddressBytes());
+ h = new Host(dla, host.getNetworkAddress());
} catch (ConstructionException ce) {
p = null;
h = null;
private void updateSwitchTiers(Node n, int currentTier) {
Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
if (ndlinks == null) {
- logger.debug(
- "updateSwitchTiers(): ndlinks null for Node: {}, Tier:{}",
- n, currentTier);
+ logger.debug("updateSwitchTiers(): ndlinks null for Node: {}, Tier:{}", n, currentTier);
return;
}
Set<Edge> links = ndlinks.get(n);
if (links == null) {
- logger.debug("updateSwitchTiers(): links null for ndlinks:{}",
- ndlinks);
+ logger.debug("updateSwitchTiers(): links null for ndlinks:{}", ndlinks);
return;
}
ArrayList<Node> needsVisiting = new ArrayList<Node>();
for (Edge lt : links) {
- if (!lt.getHeadNodeConnector().getType()
- .equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
+ if (!lt.getHeadNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
// We don't want to work on Node that are not openflow
// for now
continue;
private boolean switchNeedsTieringUpdate(Node n, int tier) {
if (n == null) {
- logger.error("switchNeedsTieringUpdate(): Null node for tier: {}",
- tier);
+ logger.error("switchNeedsTieringUpdate(): Null node for tier: {}", tier);
return false;
}
/*
* @return Network Hierarchies represented by an Array of Array (of
* Switch-Ids as String).
*/
+ @Override
public List<List<String>> getHostNetworkHierarchy(InetAddress hostAddress) {
HostNodeConnector host = hostQuery(hostAddress);
if (host == null)
* Array of multiple Hierarchies that represent a given host.
*/
@SuppressWarnings("unchecked")
- private void updateCurrentHierarchy(Node node,
- ArrayList<String> currHierarchy, List<List<String>> fullHierarchy) {
+ private void updateCurrentHierarchy(Node node, ArrayList<String> currHierarchy, List<List<String>> fullHierarchy) {
// currHierarchy.add(String.format("%x", currSw.getId()));
currHierarchy.add(dpidToHostNameHack((Long) node.getID()));
- ArrayList<String> currHierarchyClone = (ArrayList<String>) currHierarchy
- .clone(); // Shallow copy as required
+ ArrayList<String> currHierarchyClone = (ArrayList<String>) currHierarchy.clone(); // Shallow
+ // copy
+ // as
+ // required
Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
if (ndlinks == null) {
- logger.debug(
- "updateCurrentHierarchy(): topologyManager returned null ndlinks for node: {}",
- node);
+ logger.debug("updateCurrentHierarchy(): topologyManager returned null ndlinks for node: {}", node);
return;
}
Node n = NodeCreator.createOFNode((Long) node.getID());
return;
}
for (Edge lt : links) {
- if (!lt.getHeadNodeConnector().getType()
- .equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
+ if (!lt.getHeadNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
// We don't want to work on Node that are not openflow
// for now
continue;
}
Node dstNode = lt.getHeadNodeConnector().getNode();
- Tier nodeTier = (Tier) switchManager.getNodeProp(node,
- Tier.TierPropName);
- Tier dstNodeTier = (Tier) switchManager.getNodeProp(dstNode,
- Tier.TierPropName);
+ Tier nodeTier = (Tier) switchManager.getNodeProp(node, Tier.TierPropName);
+ Tier dstNodeTier = (Tier) switchManager.getNodeProp(dstNode, Tier.TierPropName);
if (dstNodeTier.getValue() > nodeTier.getValue()) {
ArrayList<String> buildHierarchy = currHierarchy;
if (currHierarchy.size() > currHierarchyClone.size()) {
- buildHierarchy = (ArrayList<String>) currHierarchyClone
- .clone(); // Shallow copy as required
+ buildHierarchy = (ArrayList<String>) currHierarchyClone.clone(); // Shallow
+ // copy
+ // as
+ // required
fullHierarchy.add(buildHierarchy);
}
updateCurrentHierarchy(dstNode, buildHierarchy, fullHierarchy);
}
if (!srcType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
- logger.error("For now we cannot handle updates for "
- + "non-openflow nodes");
+ logger.error("For now we cannot handle updates for " + "non-openflow nodes");
return;
}
}
if (!dstType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
- logger.error("For now we cannot handle updates for "
- + "non-openflow nodes");
+ logger.error("For now we cannot handle updates for " + "non-openflow nodes");
return;
}
}
}
- logger.debug(
- "HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
+ logger.debug("HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
new Object[] { srcNid, srcPort, dstNid, dstPort, added });
}
}
}
+ @Override
public void subnetNotify(Subnet sub, boolean add) {
logger.debug("Received subnet notification: {} add={}", sub, add);
if (add) {
for (int i = 0; i < failedARPReqList.size(); i++) {
ARPPending arphost;
arphost = failedARPReqList.get(i);
- logger.debug(
- "Sending the ARP from FailedARPReqList fors IP: {}",
- arphost.getHostIP().getHostAddress());
+ logger.debug("Sending the ARP from FailedARPReqList fors IP: {}", arphost.getHostIP().getHostAddress());
hostFinder.find(arphost.getHostIP());
}
}
}
class OutStandingARPHandler extends TimerTask {
+ @Override
public void run() {
ARPPending arphost;
/* This routine runs every 4 seconds */
*/
hostFinder.find(arphost.getHostIP());
arphost.sent_count++;
- logger.debug("ARP Sent from ARPPending List, IP: {}",
- arphost.getHostIP().getHostAddress());
- } else if (arphost.getSent_count() >= switchManager
- .getHostRetryCount()) {
+ logger.debug("ARP Sent from ARPPending List, IP: {}", arphost.getHostIP().getHostAddress());
+ } else if (arphost.getSent_count() >= switchManager.getHostRetryCount()) {
/*
* Two ARP requests have been sent without receiving a
* reply, remove this from the pending list
*/
removePendingARPFromList(i);
- logger.debug(
- "ARP reply not received after two attempts, removing from Pending List IP: {}",
+ logger.debug("ARP reply not received after two attempts, removing from Pending List IP: {}",
arphost.getHostIP().getHostAddress());
/*
* Add this host to a different list which will be processed
* on link up events
*/
- logger.debug("Adding the host to FailedARPReqList IP: {}",
- arphost.getHostIP().getHostAddress());
+ logger.debug("Adding the host to FailedARPReqList IP: {}", arphost.getHostIP().getHostAddress());
failedARPReqList.add(arphost);
} else {
- logger.error(
- "Inavlid arp_sent count for entery at index: {}", i);
+ logger.error("Inavlid arp_sent count for entery at index: {}", i);
}
}
}
}
private class ARPRefreshHandler extends TimerTask {
+ @Override
@SuppressWarnings("deprecation")
public void run() {
- if ((clusterContainerService != null)
- && !clusterContainerService.amICoordinator()) {
+ if ((clusterContainerService != null) && !clusterContainerService.amICoordinator()) {
return;
}
- if ((switchManager != null)
- && !switchManager.isHostRefreshEnabled()) {
+ if ((switchManager != null) && !switchManager.isHostRefreshEnabled()) {
/*
* The host probe procedure was disabled by CLI
*/
logger.error("ARPRefreshHandler(): hostsDB is not allocated yet:");
return;
}
- for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
- .entrySet()) {
+ for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
HostNodeConnector host = entry.getValue();
if (host.isStaticHost()) {
/* this host was learned via API3, don't age it out */
if (logger.isTraceEnabled()) {
logger.trace(
"ARP Probing ({}) for {}({})",
- new Object[] {
- arp_cntdown,
- host.getNetworkAddress()
- .getHostAddress(),
- HexEncode.bytesToHexString(host
- .getDataLayerAddressBytes()) });
+ new Object[] { arp_cntdown, host.getNetworkAddress().getHostAddress(),
+ HexEncode.bytesToHexString(host.getDataLayerAddressBytes()) });
}
host.setArpSendCountDown(arp_cntdown);
hostFinder.probe(host);
* indicating the result of this action.
*/
- public Status addStaticHostReq(InetAddress networkAddr,
- byte[] dataLayerAddress, NodeConnector nc, short vlan) {
- if (dataLayerAddress.length != 6) {
+ public Status addStaticHostReq(InetAddress networkAddr, byte[] dataLayerAddress, NodeConnector nc, short vlan) {
+ if (dataLayerAddress.length != NetUtils.MACAddrLengthInBytes) {
return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
}
+ if (nc == null) {
+ return new Status(StatusCode.BADREQUEST, "Invalid NodeConnector");
+ }
+
HostNodeConnector host = null;
try {
- host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
- vlan);
+ host = new HostNodeConnector(dataLayerAddress, networkAddr, nc, vlan);
if (hostExists(host)) {
// This host is already learned either via ARP or through a
// northbound request
transHost.setStaticHost(true);
return new Status(StatusCode.SUCCESS, null);
}
+
+ if (hostsDB.get(networkAddr) != null) {
+ // There is already a host with this IP address (but behind
+ // a different (switch, port, vlan) tuple. Return an error
+ return new Status(StatusCode.CONFLICT, "Existing IP, Use PUT to update");
+ }
host.setStaticHost(true);
/*
* Before adding host, Check if the switch and the port have already
notifyHostLearnedOrRemoved(host, true);
} else {
inactiveStaticHosts.put(nc, host);
- logger.debug(
- "Switch or switchport is not up, adding host {} to inactive list",
+ logger.debug("Switch or switchport is not up, adding host {} to inactive list",
networkAddr.getHostName());
}
return new Status(StatusCode.SUCCESS, null);
} catch (ConstructionException e) {
- return new Status(StatusCode.INTERNALERROR,
- "Host could not be created");
+ logger.error("", e);
+ return new Status(StatusCode.INTERNALERROR, "Host could not be created");
}
}
* @param vlan
* Vlan of which this host is member of
*
- * @return boolean true if the host was added successfully, false otherwise
+ * @return Status The status object as described in {@code Status}
+ * indicating the result of this action.
*/
- public boolean updateHostReq(InetAddress networkAddr,
- byte[] dataLayerAddress, NodeConnector nc, short vlan) {
+ public Status updateHostReq(InetAddress networkAddr, byte[] dataLayerAddress, NodeConnector nc, short vlan) {
+ HostNodeConnector tobeUpdatedHost;
+ HostNodeConnector host = null;
+
+ if (dataLayerAddress.length != NetUtils.MACAddrLengthInBytes) {
+ return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
+ }
+
if (nc == null) {
- return false;
+ return new Status(StatusCode.BADREQUEST, "Invalid NodeConnector");
}
- HostNodeConnector host = null;
+
try {
- host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
- vlan);
- if (!hostExists(host)) {
- if ((inactiveStaticHosts.get(nc)) != null) {
- inactiveStaticHosts.replace(nc, host);
- return true;
+ host = new HostNodeConnector(dataLayerAddress, networkAddr, nc, vlan);
+ if (hostExists(host)) {
+ return new Status(StatusCode.BADREQUEST, "Host already exists");
+ }
+
+ if ((tobeUpdatedHost = hostsDB.get(networkAddr)) != null) {
+ if (hostsDB.replace(networkAddr, tobeUpdatedHost, host)) {
+ logger.debug("Host replaced from hostsDB. Old host: {} New Host: {}", tobeUpdatedHost, host);
+ notifyHostLearnedOrRemoved(tobeUpdatedHost, false);
+ notifyHostLearnedOrRemoved(host, true);
+ return new Status(StatusCode.SUCCESS);
+ } else {
+ logger.error("Static host replacement failed from hostsDB, Replaced Host: {}, New Host: {}",
+ tobeUpdatedHost, host);
+ return new Status(StatusCode.INTERNALERROR,
+ "Host Replacement Failed due to presence of another host with same IP");
}
- return false;
}
- hostsDB.replace(networkAddr, host);
- return true;
+
+ // Check if the host exists in inactive hosts database
+ if ((tobeUpdatedHost = inactiveStaticHosts.get(nc)) != null) {
+ if (inactiveStaticHosts.replace(nc, tobeUpdatedHost, host)) {
+ logger.debug("Host replaced from inactive hostsDB. Old host: {} New Host: {}", tobeUpdatedHost,
+ host);
+ return new Status(StatusCode.SUCCESS);
+ } else {
+ logger.error("Static host replacement failed, Replaced Host: {}, New Host: {}", tobeUpdatedHost,
+ host);
+ return new Status(StatusCode.INTERNALERROR,
+ "Host Replacement Failed due to presence of another host with same IP");
+ }
+ }
+
+ // Host doesn't exist
+ return new Status(StatusCode.BADREQUEST, "Host doesn't exists, can't update");
} catch (ConstructionException e) {
+ logger.error("", e);
+ return new Status(StatusCode.INTERNALERROR, "host object creation failure");
}
- return false;
}
/**
if (host != null) {
// Validation check
if (!host.isStaticHost()) {
- return new Status(StatusCode.FORBIDDEN, "Host "
- + networkAddress.getHostName() + " is not static");
+ return new Status(StatusCode.FORBIDDEN, "Host " + networkAddress.getHostName() + " is not static");
}
// Remove and notify
notifyHostLearnedOrRemoved(host, false);
host = entry.getValue();
// Validation check
if (!host.isStaticHost()) {
- return new Status(StatusCode.FORBIDDEN, "Host "
- + networkAddress.getHostName() + " is not static");
+ return new Status(StatusCode.FORBIDDEN, "Host " + networkAddress.getHostName() + " is not static");
}
this.removeHostFromInactiveDB(networkAddress);
return new Status(StatusCode.SUCCESS, null);
}
@Override
- public void notifyNode(Node node, UpdateType type,
- Map<String, Property> propMap) {
+ public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
if (node == null)
return;
switch (type) {
case REMOVED:
logger.debug("Received removed node {}", node);
- for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
- .entrySet()) {
+ for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
HostNodeConnector host = entry.getValue();
if (host.getnodeconnectorNode().equals(node)) {
logger.debug("Node: {} is down, remove from Hosts_DB", node);
}
@Override
- public void notifyNodeConnector(NodeConnector nodeConnector,
- UpdateType type, Map<String, Property> propMap) {
+ public void notifyNodeConnector(NodeConnector nodeConnector, UpdateType type, Map<String, Property> propMap) {
if (nodeConnector == null)
return;
}
@Override
- public Status addStaticHost(String networkAddress, String dataLayerAddress,
- NodeConnector nc, String vlan) {
+ public Status addStaticHost(String networkAddress, String dataLayerAddress, NodeConnector nc, String vlan) {
try {
InetAddress ip = InetAddress.getByName(networkAddress);
if (nc == null) {
return new Status(StatusCode.BADREQUEST, "Invalid NodeId");
}
- return addStaticHostReq(ip,
- HexEncode.bytesFromHexString(dataLayerAddress), nc,
- Short.valueOf(vlan));
+ return addStaticHostReq(ip, HexEncode.bytesFromHexString(dataLayerAddress), nc, Short.valueOf(vlan));
} catch (UnknownHostException e) {
logger.error("", e);
return new Status(StatusCode.BADREQUEST, "Invalid Address");
for (int i = 0; i < failedARPReqList.size(); i++) {
arphost = failedARPReqList.get(i);
- logger.debug("Sending the ARP from FailedARPReqList fors IP: {}",
- arphost.getHostIP().getHostAddress());
+ logger.debug("Sending the ARP from FailedARPReqList fors IP: {}", arphost.getHostIP().getHostAddress());
hostFinder.find(arphost.getHostIP());
}
HostNodeConnector host = inactiveStaticHosts.get(nodeConnector);
for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
HostNodeConnector host = entry.getValue();
if (host.getnodeConnector().equals(nodeConnector)) {
- logger.debug(
- " NodeConnector: {} is down, remove from Hosts_DB",
- nodeConnector);
+ logger.debug(" NodeConnector: {} is down, remove from Hosts_DB", nodeConnector);
removeKnownHost(entry.getKey());
notifyHostLearnedOrRemoved(host, false);
}
*/
public IEntityClass getEntityClass();
+ public boolean isStaticHost();
+
+ public void setStaticHost(boolean isStatic);
+
public HostNodeConnector toHostNodeConnector();
}
protected final Short[] vlanIds;
protected volatile String dhcpClientName;
+ private boolean staticHost;
+
/**
* These are the old attachment points for the device that were valid no
* more than INACTIVITY_TIME ago.
byte[] macAddr = macLongToByte(this.getMACAddress());
HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n,
(short) 0);
+ nc.setStaticHost(this.isStaticHost());
return nc;
} catch (Exception e) {
return null;
return macAddr;
}
+ public boolean isStaticHost(){
+ return this.staticHost;
+ }
+
+ public void setStaticHost(boolean isStatic){
+ this.staticHost = isStatic;
+ }
+
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
import static org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl.DeviceUpdate.Change.DELETE;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import org.opendaylight.controller.hosttracker.IfNewHostNotify;
import org.opendaylight.controller.hosttracker.SwitchPort;
import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
+import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Host;
+import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
+import org.opendaylight.controller.sal.core.Tier;
+import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.packet.ARP;
import org.opendaylight.controller.sal.packet.Ethernet;
import org.opendaylight.controller.sal.packet.IDataPacketService;
import org.opendaylight.controller.sal.packet.Packet;
import org.opendaylight.controller.sal.packet.PacketResult;
import org.opendaylight.controller.sal.packet.RawPacket;
+import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
+import org.opendaylight.controller.sal.packet.address.EthernetAddress;
import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
+import org.opendaylight.controller.sal.utils.HexEncode;
import org.opendaylight.controller.sal.utils.ListenerDispatcher;
import org.opendaylight.controller.sal.utils.MultiIterator;
+import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.SingletonTask;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.topologymanager.ITopologyManager;
import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
logger.info("Primary index {}", primaryIndex);
ArrayList<Long> deleteQueue = null;
LinkedList<DeviceUpdate> deviceUpdates = null;
+ Device oldDevice = null;
Device device = null;
// we may need to restart the learning process if we detect
// modified this Device).
if (!res)
continue;
-
+ oldDevice = device;
device = newDevice;
// update indices
if (!updateIndices(device, deviceKey)) {
if (moved) {
// we count device moved events in
// sendDeviceMovedNotification()
- sendDeviceMovedNotification(device);
+ sendDeviceMovedNotification(device, oldDevice);
if (logger.isTraceEnabled()) {
logger.trace("Device moved: attachment points {},"
+ "entities {}", device.attachmentPoints,
protected void notifyListeners(List<IDeviceListener> listeners,
DeviceUpdate update) {
+ // Topology update is for some reason outside of listeners registry
+ // logic
+ Entity[] ents = update.device.getEntities();
+ Entity e = ents[ents.length-1];
+ NodeConnector p = e.getPort();
+ Node node = p.getNode();
+ Host h = null;
+ try {
+ byte[] mac = NetUtils.longToByteArray6(e.getMacAddress());
+ DataLinkAddress dla = new EthernetAddress(
+ mac);
+ e.getIpv4Address();
+ InetAddress.getAllByName(e.getIpv4Address().toString());
+ h = new org.opendaylight.controller.sal.core.Host(dla,
+ InetAddress.getByName(e.getIpv4Address().toString()));
+ } catch (ConstructionException ce) {
+ p = null;
+ h = null;
+ } catch (UnknownHostException ue){
+ p = null;
+ h = null;
+ }
+
+ if (topology != null && p != null && h != null) {
+ if (update.change.equals(DeviceUpdate.Change.ADD)) {
+ Tier tier = new Tier(1);
+ switchManager.setNodeProp(node, tier);
+ topology.updateHostLink(p, h, UpdateType.ADDED, null);
+ } else {
+ // No need to reset the tiering if no other hosts are currently
+ // connected
+ // If this switch was discovered to be an access switch, it
+ // still is even if the host is down
+ Tier tier = new Tier(0);
+ switchManager.setNodeProp(node, tier);
+ topology.updateHostLink(p, h, UpdateType.REMOVED, null);
+ }
+ }
+
if (listeners == null && newHostNotify.isEmpty()) {
return;
}
case ADD:
notify.notifyHTClient(update.device.toHostNodeConnector());
break;
+ case DELETE:
+ notify.notifyHTClientHostRemoved(update.device.toHostNodeConnector());
+ break;
+ case CHANGE:
}
}
}
}
}
+ /**
+ * Send update notifications to listeners.
+ * IfNewHostNotify listeners need to remove old device and add new device.
+ * @param device
+ * @param oldDevice
+ */
+ protected void sendDeviceMovedNotification(Device device, Device oldDevice){
+ for (IfNewHostNotify notify : newHostNotify){
+ notify.notifyHTClientHostRemoved(oldDevice.toHostNodeConnector());
+ notify.notifyHTClient(device.toHostNodeConnector());
+ }
+ sendDeviceMovedNotification(device);
+ }
/**
* this method will reclassify and reconcile a device - possibilities are -
@Override
public Set<HostNodeConnector> getActiveStaticHosts() {
- // TODO Auto-generated method stub
- return null;
+ Collection<Device> devices = Collections
+ .unmodifiableCollection(deviceMap.values());
+ Iterator<Device> i = devices.iterator();
+ Set<HostNodeConnector> nc = new HashSet<HostNodeConnector>();
+ while (i.hasNext()) {
+ Device device = i.next();
+ if(device.isStaticHost())
+ nc.add(device.toHostNodeConnector());
+ }
+ return nc;
}
@Override
@Override
public Status addStaticHost(String networkAddress, String dataLayerAddress,
NodeConnector nc, String vlan) {
- // TODO Auto-generated method stub
- return null;
+ Long mac = HexEncode.stringToLong(dataLayerAddress);
+ try{
+ InetAddress addr = InetAddress.getByName(networkAddress);
+ int ip = toIPv4Address(addr.getAddress());
+ Entity e = new Entity(mac, Short.valueOf(vlan), ip, nc, new Date());
+ Device d = this.learnDeviceByEntity(e);
+ d.setStaticHost(true);
+ return new Status(StatusCode.SUCCESS);
+ }catch(UnknownHostException e){
+ return new Status(StatusCode.INTERNALERROR);
+ }
}
@Override
public Status removeStaticHost(String networkAddress) {
- // TODO Auto-generated method stub
- return null;
+ Integer addr;
+ try {
+ addr = toIPv4Address(InetAddress.getByName(networkAddress).getAddress());
+ } catch (UnknownHostException e) {
+ return new Status(StatusCode.NOTFOUND, "Host does not exist");
+ }
+ Iterator<Device> di = this.getDeviceIteratorForQuery(null, null, addr, null);
+ List<IDeviceListener> listeners = deviceListeners
+ .getOrderedListeners();
+ while(di.hasNext()){
+ Device d = di.next();
+ if(d.isStaticHost()){
+ deleteDevice(d);
+ for (IfNewHostNotify notify : newHostNotify)
+ notify.notifyHTClientHostRemoved(d.toHostNodeConnector());
+ for (IDeviceListener listener : listeners)
+ listener.deviceRemoved(d);
+ }
+ }
+ return new Status(StatusCode.SUCCESS);
}
/**
package org.opendaylight.controller.northbound.commons.utils;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.Response;
+
import org.opendaylight.controller.containermanager.IContainerAuthorization;
import org.opendaylight.controller.sal.authorization.Privilege;
import org.opendaylight.controller.sal.authorization.UserLevel;
import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.usermanager.IUserManager;
public class NorthboundUtils {
+ private static final Map<StatusCode, Response.Status> ResponseStatusMapping = new HashMap<StatusCode, Response.Status>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(StatusCode.SUCCESS, Response.Status.OK);
+ put(StatusCode.BADREQUEST, Response.Status.BAD_REQUEST);
+ put(StatusCode.UNAUTHORIZED, Response.Status.UNAUTHORIZED);
+ put(StatusCode.FORBIDDEN, Response.Status.FORBIDDEN);
+ put(StatusCode.NOTFOUND, Response.Status.NOT_FOUND);
+ put(StatusCode.NOTALLOWED, Response.Status.FORBIDDEN);
+ put(StatusCode.NOTACCEPTABLE, Response.Status.NOT_ACCEPTABLE);
+ put(StatusCode.TIMEOUT, Response.Status.GONE);
+ put(StatusCode.CONFLICT, Response.Status.CONFLICT);
+ put(StatusCode.GONE, Response.Status.GONE);
+ put(StatusCode.UNSUPPORTED, Response.Status.BAD_REQUEST);
+ put(StatusCode.INTERNALERROR, Response.Status.INTERNAL_SERVER_ERROR);
+ put(StatusCode.NOTIMPLEMENTED, Response.Status.NOT_ACCEPTABLE);
+ put(StatusCode.NOSERVICE, Response.Status.SERVICE_UNAVAILABLE);
+ put(StatusCode.UNDEFINED, Response.Status.BAD_REQUEST);
+ }
+ };
+
+ // Suppress default constructor for noninstantiability
+ private NorthboundUtils() {
+ }
+
+ /**
+ * Returns Response.Status for a given status. If the status is null or if
+ * the corresponding StatusCode is not present in the ResponseStatusMapping,
+ * it returns null.
+ *
+ * @param status
+ * The Status
+ * @return The Response.Status for a given status
+ */
+ public static Response.Status getResponseStatus(Status status) {
+ return ResponseStatusMapping.get(status.getCode());
+ }
+
+ /**
+ * Returns Response for a given status. If the status provided is null or if
+ * the corresponding StatusCode is not present in the ResponseStatusMapping,
+ * it returns Response with StatusType as INTERNAL_SERVER_ERROR.
+ *
+ * @param status
+ * The Status
+ * @return The Response for a given status.
+ */
+ public static Response getResponse(Status status) {
+ if ((status == null) || (!ResponseStatusMapping.containsKey(status.getCode()))) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Action Result Unknown").build();
+ }
+ return Response.status(ResponseStatusMapping.get(status.getCode())).entity(status.getDescription()).build();
+ }
/**
* Returns whether the current user has the required privilege on the
* Class from where the function is invoked
* @return The Status of the request, either Success or Unauthorized
*/
- public static boolean isAuthorized(String userName, String containerName,
- Privilege required,Object bundle) {
+ public static boolean isAuthorized(String userName, String containerName, Privilege required, Object bundle) {
- if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
- IUserManager auth = (IUserManager) ServiceHelper.getGlobalInstance(
- IUserManager.class, bundle);
+ if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ IUserManager auth = (IUserManager) ServiceHelper.getGlobalInstance(IUserManager.class, bundle);
switch (required) {
case WRITE:
}
} else {
- IContainerAuthorization auth = (IContainerAuthorization) ServiceHelper
- .getGlobalInstance(IContainerAuthorization.class, bundle);
+ IContainerAuthorization auth = (IContainerAuthorization) ServiceHelper.getGlobalInstance(
+ IContainerAuthorization.class, bundle);
if (auth == null) {
return false;
}
- Privilege current = auth.getResourcePrivilege(userName,
- containerName);
+ Privilege current = auth.getResourcePrivilege(userName, containerName);
if (required.ordinal() > current.ordinal()) {
return false;
}
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.codehaus.jettison.json.JSONTokener;
import org.opendaylight.controller.hosttracker.IfIptoHost;
+import org.opendaylight.controller.sal.core.Bandwidth;
import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Latency;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.State;
import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
+import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.usermanager.IUserManager;
private BundleContext bc;
private IUserManager users = null;
private IInventoryListener invtoryListener = null;
+ private IListenTopoUpdates topoUpdates = null;
+
+ private Boolean debugMsg = false;
private String stateToString(int state) {
switch (state) {
for (int i = 0; i < b.length; i++) {
int state = b[i].getState();
if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
- log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
- + stateToString(state));
+ log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + stateToString(state));
debugit = true;
}
}
if (debugit) {
- log.debug("Do some debugging because some bundle is "
- + "unresolved");
+ log.debug("Do some debugging because some bundle is " + "unresolved");
}
// Assert if true, if false we are good to go!
assertFalse(debugit);
- ServiceReference r = bc.getServiceReference(IUserManager.class
- .getName());
+ ServiceReference r = bc.getServiceReference(IUserManager.class.getName());
if (r != null) {
this.users = (IUserManager) bc.getService(r);
}
// If inventoryListener is null, cannot run hosttracker tests.
assertNotNull(this.invtoryListener);
+ r = bc.getServiceReference(IListenTopoUpdates.class.getName());
+ if (r != null) {
+ this.topoUpdates = (IListenTopoUpdates) bc.getService(r);
+ }
+
+ // If topologyManager is null, cannot run topology North tests.
+ assertNotNull(this.topoUpdates);
+
}
// static variable to pass response code from getJsonResult()
// initialize response code to indicate error
httpResponseCode = 400;
+ if (debugMsg) {
+ System.out.println("HTTP method: " + method + " url: " + restUrl.toString());
+ if (body != null)
+ System.out.println("body: " + body);
+ }
+
try {
URL url = new URL(restUrl);
this.users.getAuthorizationList();
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
- HttpURLConnection connection = (HttpURLConnection) url
- .openConnection();
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
- connection.setRequestProperty("Authorization", "Basic "
- + authStringEnc);
+ connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
if (body != null) {
connection.setDoOutput(true);
- OutputStreamWriter wr = new OutputStreamWriter(
- connection.getOutputStream());
+ OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(body);
wr.flush();
}
if (httpResponseCode > 299)
return httpResponseCode.toString();
+ if (debugMsg) {
+ System.out.println("HTTP response code: " + connection.getResponseCode());
+ System.out.println("HTTP response message: " + connection.getResponseMessage());
+ }
+
InputStream is = connection.getInputStream();
- BufferedReader rd = new BufferedReader(new InputStreamReader(is,
- Charset.forName("UTF-8")));
+ BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
}
}
- private void testNodeProperties(JSONObject node, Integer nodeId,
- String nodeType, Integer timestamp, String timestampName,
- Integer actionsValue, Integer capabilitiesValue,
- Integer tablesValue, Integer buffersValue) throws JSONException {
+ private void testNodeProperties(JSONObject node, Integer nodeId, String nodeType, Integer timestamp,
+ String timestampName, Integer actionsValue, Integer capabilitiesValue, Integer tablesValue,
+ Integer buffersValue) throws JSONException {
JSONObject nodeInfo = node.getJSONObject("node");
Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("@id"));
if (timestamp == null || timestampName == null) {
Assert.assertFalse(properties.has("timeStamp"));
} else {
- Assert.assertEquals(
- timestamp,
- (Integer) properties.getJSONObject("timeStamp").getInt(
- "timestamp"));
- Assert.assertEquals(
- timestampName,
- properties.getJSONObject("timeStamp").getString(
- "timestampName"));
+ Assert.assertEquals(timestamp, (Integer) properties.getJSONObject("timeStamp").getInt("timestamp"));
+ Assert.assertEquals(timestampName, properties.getJSONObject("timeStamp").getString("timestampName"));
}
if (actionsValue == null) {
Assert.assertFalse(properties.has("actions"));
} else {
- Assert.assertEquals(actionsValue, (Integer) properties
- .getJSONObject("actions").getInt("actionsValue"));
+ Assert.assertEquals(actionsValue, (Integer) properties.getJSONObject("actions").getInt("actionsValue"));
}
if (capabilitiesValue == null) {
Assert.assertFalse(properties.has("capabilities"));
} else {
- Assert.assertEquals(capabilitiesValue, (Integer) properties
- .getJSONObject("capabilities").getInt("capabilitiesValue"));
+ Assert.assertEquals(capabilitiesValue,
+ (Integer) properties.getJSONObject("capabilities").getInt("capabilitiesValue"));
}
if (tablesValue == null) {
Assert.assertFalse(properties.has("tables"));
} else {
- Assert.assertEquals(tablesValue, (Integer) properties
- .getJSONObject("tables").getInt("tablesValue"));
+ Assert.assertEquals(tablesValue, (Integer) properties.getJSONObject("tables").getInt("tablesValue"));
}
if (buffersValue == null) {
Assert.assertFalse(properties.has("buffers"));
} else {
- Assert.assertEquals(buffersValue, (Integer) properties
- .getJSONObject("buffers").getInt("buffersValue"));
+ Assert.assertEquals(buffersValue, (Integer) properties.getJSONObject("buffers").getInt("buffersValue"));
}
}
- private void testNodeConnectorProperties(
- JSONObject nodeConnectorProperties, Integer ncId, String ncType,
- Integer nodeId, String nodeType, Integer state,
- Integer capabilities, Integer bandwidth) throws JSONException {
+ private void testNodeConnectorProperties(JSONObject nodeConnectorProperties, Integer ncId, String ncType,
+ Integer nodeId, String nodeType, Integer state, Integer capabilities, Integer bandwidth)
+ throws JSONException {
- JSONObject nodeConnector = nodeConnectorProperties
- .getJSONObject("nodeconnector");
+ JSONObject nodeConnector = nodeConnectorProperties.getJSONObject("nodeconnector");
JSONObject node = nodeConnector.getJSONObject("node");
- JSONObject properties = nodeConnectorProperties
- .getJSONObject("properties");
+ JSONObject properties = nodeConnectorProperties.getJSONObject("properties");
Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("@id"));
Assert.assertEquals(ncType, nodeConnector.getString("@type"));
if (state == null) {
Assert.assertFalse(properties.has("state"));
} else {
- Assert.assertEquals(
- state,
- (Integer) properties.getJSONObject("state").getInt(
- "stateValue"));
+ Assert.assertEquals(state, (Integer) properties.getJSONObject("state").getInt("stateValue"));
}
if (capabilities == null) {
Assert.assertFalse(properties.has("capabilities"));
} else {
- Assert.assertEquals(capabilities, (Integer) properties
- .getJSONObject("capabilities").getInt("capabilitiesValue"));
+ Assert.assertEquals(capabilities,
+ (Integer) properties.getJSONObject("capabilities").getInt("capabilitiesValue"));
}
if (bandwidth == null) {
Assert.assertFalse(properties.has("bandwidth"));
} else {
- Assert.assertEquals(
- bandwidth,
- (Integer) properties.getJSONObject("bandwidth").getInt(
- "bandwidthValue"));
+ Assert.assertEquals(bandwidth, (Integer) properties.getJSONObject("bandwidth").getInt("bandwidthValue"));
}
}
@Test
public void testSubnetsNorthbound() throws JSONException {
+ System.out.println("Starting Subnets JAXB client.");
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnet/";
String name1 = "testSubnet1";
Assert.assertEquals(404, httpResponseCode.intValue());
// Test POST subnet1
- String queryParameter = new QueryParameter("subnetName", name1).add(
- "subnet", subnet1).getString();
- result = getJsonResult(baseURL + "default/" + name1 + queryParameter,
- "POST");
+ String queryParameter = new QueryParameter("subnetName", name1).add("subnet", subnet1).getString();
+ result = getJsonResult(baseURL + "default/" + name1 + queryParameter, "POST");
Assert.assertEquals(201, httpResponseCode.intValue());
// Test GET subnet1
Assert.assertEquals(subnet1, json.getString("@subnet"));
// Test POST subnet2
- queryParameter = new QueryParameter("subnetName", name2).add("subnet",
- subnet2).getString();
- result = getJsonResult(baseURL + "default/" + name2 + queryParameter,
- "POST");
+ queryParameter = new QueryParameter("subnetName", name2).add("subnet", subnet2).getString();
+ result = getJsonResult(baseURL + "default/" + name2 + queryParameter, "POST");
Assert.assertEquals(201, httpResponseCode.intValue());
// Test GET all subnets in default container
@Test
public void testStaticRoutingNorthbound() throws JSONException {
+ System.out.println("Starting StaticRouting JAXB client.");
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/staticroute/";
String name1 = "testRoute1";
Assert.assertEquals("{}", result);
// Test insert static route
- String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\""
- + prefix1 + "\", \"nextHop\":\"" + nextHop1 + "\"}";
- result = getJsonResult(baseURL + "default/" + name1, "POST",
- requestBody);
+ String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\"" + prefix1 + "\", \"nextHop\":\"" + nextHop1
+ + "\"}";
+ result = getJsonResult(baseURL + "default/" + name1, "POST", requestBody);
Assert.assertEquals(201, httpResponseCode.intValue());
- requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2
- + "\", \"nextHop\":\"" + nextHop2 + "\"}";
- result = getJsonResult(baseURL + "default/" + name2, "POST",
- requestBody);
+ requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2 + "\", \"nextHop\":\"" + nextHop2 + "\"}";
+ result = getJsonResult(baseURL + "default/" + name2, "POST", requestBody);
Assert.assertEquals(201, httpResponseCode.intValue());
// Test Get all static routes
@Test
public void testSwitchManager() throws JSONException {
+ System.out.println("Starting SwitchManager JAXB client.");
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switch/default/";
// define Node/NodeConnector attributes for test
// Test for first node
JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
Assert.assertNotNull(node);
- testNodeProperties(node, nodeId_1, nodeType, timestamp_1,
- timestampName_1, actionsValue_1, capabilitiesValue_1,
+ testNodeProperties(node, nodeId_1, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
tablesValue_1, buffersValue_1);
// Test 2nd node, properties of 2nd node same as first node
node = getJsonInstance(json, "nodeProperties", nodeId_2);
Assert.assertNotNull(node);
- testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
- timestampName_1, actionsValue_1, capabilitiesValue_1,
+ testNodeProperties(node, nodeId_2, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
tablesValue_1, buffersValue_1);
// Test 3rd node, properties of 3rd node same as first node
node = getJsonInstance(json, "nodeProperties", nodeId_3);
Assert.assertNotNull(node);
- testNodeProperties(node, nodeId_3, nodeType, timestamp_1,
- timestampName_1, actionsValue_1, capabilitiesValue_1,
+ testNodeProperties(node, nodeId_3, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
tablesValue_1, buffersValue_1);
// Test GET nodeConnectors of a node
result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
jt = new JSONTokener(result);
json = new JSONObject(jt);
- JSONObject nodeConnectorProperties = json
- .getJSONObject("nodeConnectorProperties");
+ JSONObject nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
- ncType, nodeId_1, nodeType, ncState, ncCapabilities,
- ncBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, ncState,
+ ncCapabilities, ncBandwidth);
// Test second node
result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
json = new JSONObject(jt);
nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2,
- ncType, nodeId_2, nodeType, ncState, ncCapabilities,
- ncBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
+ ncCapabilities, ncBandwidth);
// Test third node
result = getJsonResult(baseURL + "node/STUB/" + nodeId_3);
json = new JSONObject(jt);
nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_3,
- ncType, nodeId_3, nodeType, ncState, ncCapabilities,
- ncBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_3, ncType, nodeId_3, nodeType, ncState,
+ ncCapabilities, ncBandwidth);
// Test delete node property
// Delete timestamp property from node1
- result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
- + "/property/timeStamp", "DELETE");
+ result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/timeStamp", "DELETE");
Assert.assertEquals(200, httpResponseCode.intValue());
// Check node1
json = new JSONObject(jt);
node = getJsonInstance(json, "nodeProperties", nodeId_1);
Assert.assertNotNull(node);
- testNodeProperties(node, nodeId_1, nodeType, null, null,
- actionsValue_1, capabilitiesValue_1, tablesValue_1,
+ testNodeProperties(node, nodeId_1, nodeType, null, null, actionsValue_1, capabilitiesValue_1, tablesValue_1,
buffersValue_1);
// Delete actions property from node2
- result = getJsonResult(baseURL + "node/STUB/" + nodeId_2
- + "/property/actions", "DELETE");
+ result = getJsonResult(baseURL + "node/STUB/" + nodeId_2 + "/property/actions", "DELETE");
Assert.assertEquals(200, httpResponseCode.intValue());
// Check node2
json = new JSONObject(jt);
node = getJsonInstance(json, "nodeProperties", nodeId_2);
Assert.assertNotNull(node);
- testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
- timestampName_1, null, capabilitiesValue_1, tablesValue_1,
- buffersValue_1);
+ testNodeProperties(node, nodeId_2, nodeType, timestamp_1, timestampName_1, null, capabilitiesValue_1,
+ tablesValue_1, buffersValue_1);
// Test add property to node
// Add Tier and Bandwidth property to node1
- result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
- + "/property/tier/1001", "PUT");
+ result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/tier/1001", "PUT");
Assert.assertEquals(201, httpResponseCode.intValue());
- result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
- + "/property/bandwidth/1002", "PUT");
+ result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/bandwidth/1002", "PUT");
Assert.assertEquals(201, httpResponseCode.intValue());
// Test for first node
json = new JSONObject(jt);
node = getJsonInstance(json, "nodeProperties", nodeId_1);
Assert.assertNotNull(node);
- Assert.assertEquals(1001, node.getJSONObject("properties")
- .getJSONObject("tier").getInt("tierValue"));
- Assert.assertEquals(1002, node.getJSONObject("properties")
- .getJSONObject("bandwidth").getInt("bandwidthValue"));
+ Assert.assertEquals(1001, node.getJSONObject("properties").getJSONObject("tier").getInt("tierValue"));
+ Assert.assertEquals(1002, node.getJSONObject("properties").getJSONObject("bandwidth").getInt("bandwidthValue"));
// Test delete nodeConnector property
// Delete state property of nodeconnector1
- result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1
- + "/STUB/" + nodeConnectorId_1 + "/property/state", "DELETE");
+ result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
+ + "/property/state", "DELETE");
Assert.assertEquals(200, httpResponseCode.intValue());
result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
json = new JSONObject(jt);
nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
- ncType, nodeId_1, nodeType, null, ncCapabilities, ncBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
+ ncCapabilities, ncBandwidth);
// Delete capabilities property of nodeconnector2
- result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2
- + "/STUB/" + nodeConnectorId_2 + "/property/capabilities",
- "DELETE");
+ result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2 + "/STUB/" + nodeConnectorId_2
+ + "/property/capabilities", "DELETE");
Assert.assertEquals(200, httpResponseCode.intValue());
result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
json = new JSONObject(jt);
nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2,
- ncType, nodeId_2, nodeType, ncState, null, ncBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
+ null, ncBandwidth);
// Test PUT nodeConnector property
int newBandwidth = 1001;
// Add Name/Bandwidth property to nodeConnector1
- result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1
- + "/STUB/" + nodeConnectorId_1 + "/property/bandwidth/"
- + newBandwidth, "PUT");
+ result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
+ + "/property/bandwidth/" + newBandwidth, "PUT");
Assert.assertEquals(201, httpResponseCode.intValue());
result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
// Check for new bandwidth value, state value removed from previous
// test
- testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
- ncType, nodeId_1, nodeType, null, ncCapabilities, newBandwidth);
+ testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
+ ncCapabilities, newBandwidth);
}
@Test
public void testStatistics() throws JSONException {
- String actionTypes[] = { "drop", "loopback", "flood", "floodAll",
- "controller", "swPath", "hwPath", "output", "setDlSrc",
- "setDlDst", "setDlType", "setVlanId", "setVlanPcp",
- "setVlanCfi", "popVlan", "pushVlan", "setNwSrc", "setNwDst",
- "setNwTos", "setTpSrc", "setTpDst" };
+ String actionTypes[] = { "drop", "loopback", "flood", "floodAll", "controller", "swPath", "hwPath", "output",
+ "setDlSrc", "setDlDst", "setDlType", "setVlanId", "setVlanPcp", "setVlanCfi", "popVlan", "pushVlan",
+ "setNwSrc", "setNwDst", "setNwTos", "setTpSrc", "setTpDst" };
System.out.println("Starting Statistics JAXB client.");
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/statistics/default/";
String result = getJsonResult(baseURL + "flowstats");
JSONTokener jt = new JSONTokener(result);
JSONObject json = new JSONObject(jt);
- JSONObject flowStatistics = getJsonInstance(json, "flowStatistics",
- 0xCAFE);
+ JSONObject flowStatistics = getJsonInstance(json, "flowStatistics", 0xCAFE);
JSONObject node = flowStatistics.getJSONObject("node");
// test that node was returned properly
Assert.assertTrue(node.getInt("@id") == 0xCAFE);
- Assert.assertTrue(node.getString("@type").equals("STUB"));
+ Assert.assertEquals(node.getString("@type"), "STUB");
// test that flow statistics results are correct
JSONArray flowStats = flowStatistics.getJSONArray("flowStat");
result = getJsonResult(baseURL + "portstats");
jt = new JSONTokener(result);
json = new JSONObject(jt);
- JSONObject portStatistics = getJsonInstance(json, "portStatistics",
- 0xCAFE);
+ JSONObject portStatistics = getJsonInstance(json, "portStatistics", 0xCAFE);
JSONObject node2 = portStatistics.getJSONObject("node");
// test that node was returned properly
Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
- Assert.assertTrue(node2.getString("@type").equals("STUB"));
+ Assert.assertEquals(node2.getString("@type"), "STUB");
// test that port statistic results are correct
JSONObject portStat = portStatistics.getJSONObject("portStat");
node = json.getJSONObject("node");
// test that node was returned properly
Assert.assertTrue(node.getInt("@id") == 0xCAFE);
- Assert.assertTrue(node.getString("@type").equals("STUB"));
+ Assert.assertEquals(node.getString("@type"), "STUB");
// test that flow statistics results are correct
flowStats = json.getJSONArray("flowStat");
node2 = json.getJSONObject("node");
// test that node was returned properly
Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
- Assert.assertTrue(node2.getString("@type").equals("STUB"));
+ Assert.assertEquals(node2.getString("@type"), "STUB");
// test that port statistic results are correct
portStat = json.getJSONObject("portStat");
Assert.assertTrue(portStat.getInt("collisionCount") == 4);
}
- private void testFlowStat(JSONObject flowStat, String actionType)
- throws JSONException {
+ private void testFlowStat(JSONObject flowStat, String actionType) throws JSONException {
Assert.assertTrue(flowStat.getInt("tableId") == 1);
Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
Assert.assertTrue(flow.getInt("id") == 12345);
- JSONObject match = (flow.getJSONObject("match")
- .getJSONObject("matchField"));
+ JSONObject match = (flow.getJSONObject("match").getJSONObject("matchField"));
Assert.assertTrue(match.getString("type").equals("NW_DST"));
Assert.assertTrue(match.getString("value").equals("1.1.1.1"));
}
if (act.getString("@type").equals("setDlSrc")) {
- byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2,
- (byte) 1 };
+ byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
String src = act.getString("address");
byte srcBytes[] = new byte[5];
srcBytes[0] = Byte.parseByte(src.substring(0, 2));
}
if (act.getString("@type").equals("setDlDst")) {
- byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4,
- (byte) 5 };
+ byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
String dst = act.getString("address");
byte dstBytes[] = new byte[5];
dstBytes[0] = Byte.parseByte(dst.substring(0, 2));
@Test
public void testFlowProgrammer() throws JSONException {
+ System.out.println("Starting FlowProgrammer JAXB client.");
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/flow/default/";
// Attempt to get a flow that doesn't exit. Should return 404
// status.
Assert.assertTrue(httpResponseCode == 200);
JSONTokener jt = new JSONTokener(result);
JSONObject json = new JSONObject(jt);
- Assert.assertTrue(json.getString("name").equals("test1"));
- Assert.assertTrue(json.getString("actions").equals("DROP"));
- Assert.assertTrue(json.getString("installInHw").equals("true"));
+ Assert.assertEquals(json.getString("name"), "test1");
+ Assert.assertEquals(json.getString("actions"), "DROP");
+ Assert.assertEquals(json.getString("installInHw"), "true");
JSONObject node = json.getJSONObject("node");
- Assert.assertTrue(node.getString("@type").equals("STUB"));
- Assert.assertTrue(node.getString("@id").equals("51966"));
+ Assert.assertEquals(node.getString("@type"), "STUB");
+ Assert.assertEquals(node.getString("@id"), "51966");
// test adding same flow again fails due to repeat name..return 409
// code
result = getJsonResult(baseURL + "STUB/51966/test1", "POST", fc);
// This is specifically written for statistics manager northbound REST
// interface
// array_name should be either "flowStatistics" or "portStatistics"
- private JSONObject getJsonInstance(JSONObject json, String array_name,
- Integer nodeId) throws JSONException {
+ private JSONObject getJsonInstance(JSONObject json, String array_name, Integer nodeId) throws JSONException {
JSONObject result = null;
if (json.get(array_name) instanceof JSONArray) {
JSONArray json_array = json.getJSONArray(array_name);
String baseURL = "http://127.0.0.1:8080/controller/nb/v2/host/default";
// test POST method: addHost()
- String queryParameter = new QueryParameter("dataLayerAddress",
- dataLayerAddress_1).add("nodeType", nodeType_1)
- .add("nodeId", nodeId_1.toString())
- .add("nodeConnectorType", nodeConnectorType_1)
- .add("nodeConnectorId", nodeConnectorId_1.toString())
- .add("vlan", vlan_1).getString();
+ String queryParameter = new QueryParameter("dataLayerAddress", dataLayerAddress_1).add("nodeType", nodeType_1)
+ .add("nodeId", nodeId_1.toString()).add("nodeConnectorType", nodeConnectorType_1)
+ .add("nodeConnectorId", nodeConnectorId_1.toString()).add("vlan", vlan_1).getString();
- String result = getJsonResult(baseURL + "/" + networkAddress_1
- + queryParameter, "POST");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 201);
+ String result = getJsonResult(baseURL + "/" + networkAddress_1 + queryParameter, "POST");
+ Assert.assertTrue(httpResponseCode == 201);
// vlan is not passed through query parameter but should be
// defaulted to "0"
- queryParameter = new QueryParameter("dataLayerAddress",
- dataLayerAddress_2).add("nodeType", nodeType_2)
- .add("nodeId", nodeId_2.toString())
- .add("nodeConnectorType", nodeConnectorType_2)
- .add("nodeConnectorId", nodeConnectorId_2.toString())
- .getString();
+ queryParameter = new QueryParameter("dataLayerAddress", dataLayerAddress_2).add("nodeType", nodeType_2)
+ .add("nodeId", nodeId_2.toString()).add("nodeConnectorType", nodeConnectorType_2)
+ .add("nodeConnectorId", nodeConnectorId_2.toString()).getString();
- result = getJsonResult(baseURL + "/" + networkAddress_2
- + queryParameter, "POST");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 201);
+ result = getJsonResult(baseURL + "/" + networkAddress_2 + queryParameter, "POST");
+ Assert.assertTrue(httpResponseCode == 201);
// define variables for decoding returned strings
String networkAddress;
// the two hosts should be in inactive host DB
// test GET method: getInactiveHosts()
result = getJsonResult(baseURL + "/inactive", "GET");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
JSONTokener jt = new JSONTokener(result);
JSONObject json = new JSONObject(jt);
networkAddress = host_jo.getString("networkAddress");
if (networkAddress.equalsIgnoreCase(networkAddress_1)) {
- Assert.assertTrue(dl_jo.getString("macAddress")
- .equalsIgnoreCase(dataLayerAddress_1));
- Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
- nodeConnectorType_1));
- Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_1);
- Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
- nodeType_1));
- Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_1);
- Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(
- vlan_1));
+ Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_1));
+ Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_1));
+ Assert.assertTrue(nc_jo.getInt("@id") == nodeConnectorId_1);
+ Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_1));
+ Assert.assertTrue(node_jo.getInt("@id") == nodeId_1);
+ Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_1));
} else if (networkAddress.equalsIgnoreCase(networkAddress_2)) {
- Assert.assertTrue(dl_jo.getString("macAddress")
- .equalsIgnoreCase(dataLayerAddress_2));
- Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
- nodeConnectorType_2));
- Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_2);
- Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
- nodeType_2));
- Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_2);
- Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(
- vlan_2));
+ Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_2));
+ Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_2));
+ Assert.assertTrue(nc_jo.getInt("@id") == nodeConnectorId_2);
+ Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_2));
+ Assert.assertTrue(node_jo.getInt("@id") == nodeId_2);
+ Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_2));
} else {
Assert.assertTrue(false);
}
// test GET method: getActiveHosts() - no host expected
result = getJsonResult(baseURL, "GET");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
jt = new JSONTokener(result);
json = new JSONObject(jt);
try {
nd = new Node(nodeType_1, nodeId_1);
ndc = new NodeConnector(nodeConnectorType_1, nodeConnectorId_1, nd);
- this.invtoryListener.notifyNodeConnector(ndc, UpdateType.ADDED,
- null);
+ this.invtoryListener.notifyNodeConnector(ndc, UpdateType.ADDED, null);
} catch (ConstructionException e) {
ndc = null;
nd = null;
// verify the host shows up in active host DB
result = getJsonResult(baseURL, "GET");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
jt = new JSONTokener(result);
json = new JSONObject(jt);
// test GET method for getHostDetails()
result = getJsonResult(baseURL + "/" + networkAddress_1, "GET");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
jt = new JSONTokener(result);
json = new JSONObject(jt);
nc_jo = json.getJSONObject("nodeConnector");
node_jo = nc_jo.getJSONObject("node");
- Assert.assertTrue(json.getString("networkAddress").equalsIgnoreCase(
- networkAddress_1));
- Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(
- dataLayerAddress_1));
- Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
- nodeConnectorType_1));
+ Assert.assertTrue(json.getString("networkAddress").equalsIgnoreCase(networkAddress_1));
+ Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_1));
+ Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_1));
Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_1);
- Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
- nodeType_1));
+ Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_1));
Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_1);
Assert.assertTrue(json.getString("vlan").equalsIgnoreCase(vlan_1));
// test DELETE method for deleteFlow()
result = getJsonResult(baseURL + "/" + networkAddress_1, "DELETE");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
// verify host_1 removed from active host DB
// test GET method: getActiveHosts() - no host expected
result = getJsonResult(baseURL, "GET");
- Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
+ Assert.assertTrue(httpResponseCode == 200);
jt = new JSONTokener(result);
json = new JSONObject(jt);
}
- private Boolean hostInJson(JSONObject json, String hostIp)
- throws JSONException {
+ private Boolean hostInJson(JSONObject json, String hostIp) throws JSONException {
// input JSONObject may be empty
if (json.length() == 0) {
return false;
}
}
+ @Test
+ public void testTopology() throws JSONException, ConstructionException {
+ System.out.println("Starting Topology JAXB client.");
+ String baseURL = "http://127.0.0.1:8080/controller/nb/v2/topology/default";
+
+ // === test GET method for getTopology()
+ short state_1 = State.EDGE_UP, state_2 = State.EDGE_DOWN;
+ long bw_1 = Bandwidth.BW10Gbps, bw_2 = Bandwidth.BW100Mbps;
+ long lat_1 = Latency.LATENCY100ns, lat_2 = Latency.LATENCY1ms;
+ String nodeType = "STUB";
+ String nodeConnType = "STUB";
+ int headNC1_nodeId = 1, headNC1_nodeConnId = 11;
+ int tailNC1_nodeId = 2, tailNC1_nodeConnId = 22;
+ int headNC2_nodeId = 2, headNC2_nodeConnId = 21;
+ int tailNC2_nodeId = 1, tailNC2_nodeConnId = 12;
+
+ List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
+ NodeConnector headnc1 = new NodeConnector(nodeConnType, headNC1_nodeConnId, new Node(nodeType, headNC1_nodeId));
+ NodeConnector tailnc1 = new NodeConnector(nodeConnType, tailNC1_nodeConnId, new Node(nodeType, tailNC1_nodeId));
+ Edge e1 = new Edge(tailnc1, headnc1);
+ Set<Property> props_1 = new HashSet<Property>();
+ props_1.add(new State(state_1));
+ props_1.add(new Bandwidth(bw_1));
+ props_1.add(new Latency(lat_1));
+ TopoEdgeUpdate teu1 = new TopoEdgeUpdate(e1, props_1, UpdateType.ADDED);
+ topoedgeupdateList.add(teu1);
+
+ NodeConnector headnc2 = new NodeConnector(nodeConnType, headNC2_nodeConnId, new Node(nodeType, headNC2_nodeId));
+ NodeConnector tailnc2 = new NodeConnector(nodeConnType, tailNC2_nodeConnId, new Node(nodeType, tailNC2_nodeId));
+ Edge e2 = new Edge(tailnc2, headnc2);
+ Set<Property> props_2 = new HashSet<Property>();
+ props_2.add(new State(state_2));
+ props_2.add(new Bandwidth(bw_2));
+ props_2.add(new Latency(lat_2));
+
+ TopoEdgeUpdate teu2 = new TopoEdgeUpdate(e2, props_2, UpdateType.ADDED);
+ topoedgeupdateList.add(teu2);
+
+ topoUpdates.edgeUpdate(topoedgeupdateList);
+
+ // HTTP request
+ String result = getJsonResult(baseURL, "GET");
+ Assert.assertTrue(httpResponseCode == 200);
+ if (debugMsg) {
+ System.out.println("Get Topology: " + result);
+ }
+
+ // returned data must be an array of edges
+ JSONTokener jt = new JSONTokener(result);
+ JSONObject json = new JSONObject(jt);
+ Assert.assertTrue(json.get("edgeProperties") instanceof JSONArray);
+ JSONArray ja = json.getJSONArray("edgeProperties");
+
+ for (int i = 0; i < ja.length(); i++) {
+ JSONObject edgeProp = ja.getJSONObject(i);
+ JSONObject edge = edgeProp.getJSONObject("edge");
+ JSONObject tailNC = edge.getJSONObject("tailNodeConnector");
+ JSONObject tailNode = tailNC.getJSONObject("node");
+
+ JSONObject headNC = edge.getJSONObject("headNodeConnector");
+ JSONObject headNode = headNC.getJSONObject("node");
+ JSONObject Props = edgeProp.getJSONObject("properties");
+ JSONObject bandw = Props.getJSONObject("bandwidth");
+ JSONObject stt = Props.getJSONObject("state");
+ JSONObject ltc = Props.getJSONObject("latency");
+
+ if (headNC.getInt("@id") == headNC1_nodeConnId) {
+ Assert.assertEquals(headNode.getString("@type"), nodeType);
+ Assert.assertEquals(headNode.getLong("@id"), headNC1_nodeId);
+ Assert.assertEquals(headNC.getString("@type"), nodeConnType);
+ Assert.assertEquals(tailNode.getString("@type"),nodeType);
+ Assert.assertEquals(tailNode.getString("@type"), nodeConnType);
+ Assert.assertEquals(tailNC.getLong("@id"), tailNC1_nodeConnId);
+ Assert.assertEquals(bandw.getLong("bandwidthValue"), bw_1);
+ Assert.assertTrue((short) stt.getInt("stateValue") == state_1);
+ Assert.assertEquals(ltc.getLong("latencyValue"), lat_1);
+ } else if (headNC.getInt("@id") == headNC2_nodeConnId) {
+ Assert.assertEquals(headNode.getString("@type"),nodeType);
+ Assert.assertEquals(headNode.getLong("@id"), headNC2_nodeId);
+ Assert.assertEquals(headNC.getString("@type"), nodeConnType);
+ Assert.assertEquals(tailNode.getString("@type"), nodeType);
+ Assert.assertTrue(tailNode.getInt("@id") == tailNC2_nodeId);
+ Assert.assertEquals(tailNC.getString("@type"), nodeConnType);
+ Assert.assertEquals(tailNC.getLong("@id"), tailNC2_nodeConnId);
+ Assert.assertEquals(bandw.getLong("bandwidthValue"), bw_2);
+ Assert.assertTrue((short) stt.getInt("stateValue") == state_2);
+ Assert.assertEquals(ltc.getLong("latencyValue"), lat_2);
+ }
+ }
+
+ // === test POST method for addUserLink()
+ // define 2 sample nodeConnectors for user link configuration tests
+ String nodeType_1 = "STUB";
+ Integer nodeId_1 = 3366;
+ String nodeConnectorType_1 = "STUB";
+ Integer nodeConnectorId_1 = 12;
+
+ String nodeType_2 = "STUB";
+ Integer nodeId_2 = 4477;
+ String nodeConnectorType_2 = "STUB";
+ Integer nodeConnectorId_2 = 34;
+
+ JSONObject jo = new JSONObject()
+ .append("name", "userLink_1")
+ .append("srcNodeConnector",
+ nodeConnectorType_1 + "|" + nodeConnectorId_1 + "@" + nodeType_1 + "|" + nodeId_1)
+ .append("dstNodeConnector",
+ nodeConnectorType_2 + "|" + nodeConnectorId_2 + "@" + nodeType_2 + "|" + nodeId_2);
+ // execute HTTP request and verify response code
+ result = getJsonResult(baseURL + "/userLink", "POST", jo.toString());
+ Assert.assertTrue(httpResponseCode == 201);
+
+ // === test GET method for getUserLinks()
+ result = getJsonResult(baseURL + "/userLink", "GET");
+ Assert.assertTrue(httpResponseCode == 200);
+ if (debugMsg) {
+ System.out.println("result:" + result);
+ }
+
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+
+ // should have at least one object returned
+ Assert.assertFalse(json.length() == 0);
+ JSONObject userlink = new JSONObject();
+
+ if (json.get("userLinks") instanceof JSONArray) {
+ ja = json.getJSONArray("userLinks");
+ int i;
+ for (i = 0; i < ja.length(); i++) {
+ userlink = ja.getJSONObject(i);
+ if (userlink.getString("name").equalsIgnoreCase("userLink_1"))
+ break;
+ }
+ Assert.assertFalse(i == ja.length());
+ } else {
+ userlink = json.getJSONObject("userLinks");
+ Assert.assertTrue(userlink.getString("name").equalsIgnoreCase("userLink_1"));
+ }
+
+ String[] level_1, level_2;
+ level_1 = userlink.getString("srcNodeConnector").split("\\@");
+ level_2 = level_1[0].split("\\|");
+ Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_1));
+ Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_1);
+ level_2 = level_1[1].split("\\|");
+ Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_1));
+ Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_1);
+ level_1 = userlink.getString("dstNodeConnector").split("\\@");
+ level_2 = level_1[0].split("\\|");
+ Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_2));
+ Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_2);
+ level_2 = level_1[1].split("\\|");
+ Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_2));
+ Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_2);
+
+ // === test DELETE method for deleteUserLink()
+ String userName = "userLink_1";
+ result = getJsonResult(baseURL + "/userLink/" + userName, "DELETE");
+ Assert.assertTrue(httpResponseCode == 200);
+
+ // execute another getUserLinks() request to verify that userLink_1 is
+ // removed
+ result = getJsonResult(baseURL + "/userLink", "GET");
+ Assert.assertTrue(httpResponseCode == 200);
+ if (debugMsg) {
+ System.out.println("result:" + result);
+ }
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+
+ if (json.length() != 0) {
+ if (json.get("userLinks") instanceof JSONArray) {
+ ja = json.getJSONArray("userLinks");
+ for (int i = 0; i < ja.length(); i++) {
+ userlink = ja.getJSONObject(i);
+ Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
+ }
+ } else {
+ userlink = json.getJSONObject("userLinks");
+ Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
+ }
+ }
+ }
+
// Configure the OSGi container
@Configuration
public Option[] config() {
return options(
//
systemProperty("logback.configurationFile").value(
- "file:" + PathUtils.getBaseDir()
- + "/src/test/resources/logback.xml"),
+ "file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
// To start OSGi console for inspection remotely
systemProperty("osgi.console").value("2401"),
- systemProperty("org.eclipse.gemini.web.tomcat.config.path")
- .value(PathUtils.getBaseDir()
- + "/src/test/resources/tomcat-server.xml"),
+ systemProperty("org.eclipse.gemini.web.tomcat.config.path").value(
+ PathUtils.getBaseDir() + "/src/test/resources/tomcat-server.xml"),
// setting default level. Jersey bundles will need to be started
// earlier.
mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
- mavenBundle("org.apache.felix",
- "org.apache.felix.dependencymanager", "3.1.0"),
+ mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager", "3.1.0"),
// the plugin stub to get data for the tests
- mavenBundle("org.opendaylight.controller",
- "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
// List all the opendaylight modules
- mavenBundle("org.opendaylight.controller", "security",
- "0.4.0-SNAPSHOT").noStart(),
- mavenBundle("org.opendaylight.controller", "sal",
- "0.5.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "sal.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "statisticsmanager",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "statisticsmanager.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "containermanager",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "containermanager.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "forwardingrulesmanager.implementation",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "arphandler",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "clustering.services", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "clustering.services-implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "switchmanager",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "switchmanager.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "configuration",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "configuration.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "hosttracker",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "hosttracker.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "arphandler",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "routing.dijkstra_implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "topologymanager",
- "0.4.0-SNAPSHOT"),
-
- mavenBundle("org.opendaylight.controller", "usermanager",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "usermanager.implementation", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "logging.bridge",
- "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller", "clustering.test",
- "0.4.0-SNAPSHOT"),
-
- mavenBundle("org.opendaylight.controller",
- "forwarding.staticrouting", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "security", "0.4.0-SNAPSHOT").noStart(),
+ mavenBundle("org.opendaylight.controller", "sal", "0.5.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "sal.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "containermanager", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "containermanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "forwardingrulesmanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "arphandler", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "clustering.services", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "clustering.services-implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "switchmanager", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "switchmanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "configuration", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "configuration.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "hosttracker", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "hosttracker.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "arphandler", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "routing.dijkstra_implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "topologymanager", "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.opendaylight.controller", "usermanager", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "usermanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "logging.bridge", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "clustering.test", "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.opendaylight.controller", "forwarding.staticrouting", "0.4.0-SNAPSHOT"),
// Northbound bundles
- mavenBundle("org.opendaylight.controller",
- "commons.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "forwarding.staticrouting.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "statistics.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "topology.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "hosttracker.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "switchmanager.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "flowprogrammer.northbound", "0.4.0-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller",
- "subnets.northbound", "0.4.0-SNAPSHOT"),
-
- mavenBundle("org.codehaus.jackson", "jackson-mapper-asl",
- "1.9.8"),
+ mavenBundle("org.opendaylight.controller", "commons.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "forwarding.staticrouting.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "statistics.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "topology.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "hosttracker.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "switchmanager.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "flowprogrammer.northbound", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "subnets.northbound", "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.codehaus.jackson", "jackson-mapper-asl", "1.9.8"),
mavenBundle("org.codehaus.jackson", "jackson-core-asl", "1.9.8"),
mavenBundle("org.codehaus.jackson", "jackson-jaxrs", "1.9.8"),
mavenBundle("org.codehaus.jettison", "jettison", "1.3.3"),
mavenBundle("commons-fileupload", "commons-fileupload", "1.2.2"),
- mavenBundle("equinoxSDK381", "javax.servlet",
- "3.0.0.v201112011016"),
- mavenBundle("equinoxSDK381", "javax.servlet.jsp",
- "2.2.0.v201112011158"),
- mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
- "1.4.0.v20120522-1841"),
+ mavenBundle("equinoxSDK381", "javax.servlet", "3.0.0.v201112011016"),
+ mavenBundle("equinoxSDK381", "javax.servlet.jsp", "2.2.0.v201112011158"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds", "1.4.0.v20120522-1841"),
mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
- mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
- "1.0.400.v20120522-2049"),
- mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
- "3.3.100.v20120522-1822"),
- mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
- "0.8.0.v201108120515"),
- mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
- "0.8.0.v201108120515"),
- mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
- "0.8.0.v201110170705"),
- mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm",
- "1.0.400.v20120522-1841"),
- mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
- "1.0.0.v20120522-1841"),
- mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher",
- "1.3.0.v20120522-1813"),
-
- mavenBundle("geminiweb", "org.eclipse.gemini.web.core",
- "2.2.0.RELEASE"),
- mavenBundle("geminiweb", "org.eclipse.gemini.web.extender",
- "2.2.0.RELEASE"),
- mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat",
- "2.2.0.RELEASE"),
- mavenBundle("geminiweb",
- "org.eclipse.virgo.kernel.equinox.extensions",
- "3.6.0.RELEASE").noStart(),
- mavenBundle("geminiweb", "org.eclipse.virgo.util.common",
- "3.6.0.RELEASE"),
- mavenBundle("geminiweb", "org.eclipse.virgo.util.io",
- "3.6.0.RELEASE"),
- mavenBundle("geminiweb", "org.eclipse.virgo.util.math",
- "3.6.0.RELEASE"),
- mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi",
- "3.6.0.RELEASE"),
- mavenBundle("geminiweb",
- "org.eclipse.virgo.util.osgi.manifest", "3.6.0.RELEASE"),
- mavenBundle("geminiweb",
- "org.eclipse.virgo.util.parser.manifest",
- "3.6.0.RELEASE"),
-
- mavenBundle("org.apache.felix",
- "org.apache.felix.dependencymanager", "3.1.0"),
- mavenBundle("org.apache.felix",
- "org.apache.felix.dependencymanager.shell", "3.0.1"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.util", "1.0.400.v20120522-2049"),
+ mavenBundle("equinoxSDK381", "org.eclipse.osgi.services", "3.3.100.v20120522-1822"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command", "0.8.0.v201108120515"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime", "0.8.0.v201108120515"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell", "0.8.0.v201110170705"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm", "1.0.400.v20120522-1841"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.console", "1.0.0.v20120522-1841"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher", "1.3.0.v20120522-1813"),
+
+ mavenBundle("geminiweb", "org.eclipse.gemini.web.core", "2.2.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.gemini.web.extender", "2.2.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat", "2.2.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.kernel.equinox.extensions", "3.6.0.RELEASE").noStart(),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.common", "3.6.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.io", "3.6.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.math", "3.6.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi", "3.6.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi.manifest", "3.6.0.RELEASE"),
+ mavenBundle("geminiweb", "org.eclipse.virgo.util.parser.manifest", "3.6.0.RELEASE"),
+
+ mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager", "3.1.0"),
+ mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager.shell", "3.0.1"),
mavenBundle("com.google.code.gson", "gson", "2.1"),
- mavenBundle("org.jboss.spec.javax.transaction",
- "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
- mavenBundle("org.apache.felix", "org.apache.felix.fileinstall",
- "3.1.6"),
+ mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
+ mavenBundle("org.apache.felix", "org.apache.felix.fileinstall", "3.1.6"),
mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
mavenBundle("commons-codec", "commons-codec"),
- mavenBundle("virgomirror",
- "org.eclipse.jdt.core.compiler.batch",
- "3.8.0.I20120518-2145"),
- mavenBundle("eclipselink", "javax.persistence",
- "2.0.4.v201112161009"),
+ mavenBundle("virgomirror", "org.eclipse.jdt.core.compiler.batch", "3.8.0.I20120518-2145"),
+ mavenBundle("eclipselink", "javax.persistence", "2.0.4.v201112161009"),
mavenBundle("orbit", "javax.activation", "1.1.0.v201211130549"),
mavenBundle("orbit", "javax.annotation", "1.1.0.v201209060031"),
mavenBundle("orbit", "javax.ejb", "3.1.1.v201204261316"),
mavenBundle("orbit", "javax.el", "2.2.0.v201108011116"),
- mavenBundle("orbit", "javax.mail.glassfish",
- "1.4.1.v201108011116"),
+ mavenBundle("orbit", "javax.mail.glassfish", "1.4.1.v201108011116"),
mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
- mavenBundle("orbit", "org.apache.catalina",
- "7.0.32.v201211201336"),
+ mavenBundle("orbit", "org.apache.catalina", "7.0.32.v201211201336"),
// these are bundle fragments that can't be started on its own
- mavenBundle("orbit", "org.apache.catalina.ha",
- "7.0.32.v201211201952").noStart(),
- mavenBundle("orbit", "org.apache.catalina.tribes",
- "7.0.32.v201211201952").noStart(),
- mavenBundle("orbit", "org.apache.coyote",
- "7.0.32.v201211201952").noStart(),
- mavenBundle("orbit", "org.apache.jasper",
- "7.0.32.v201211201952").noStart(),
+ mavenBundle("orbit", "org.apache.catalina.ha", "7.0.32.v201211201952").noStart(),
+ mavenBundle("orbit", "org.apache.catalina.tribes", "7.0.32.v201211201952").noStart(),
+ mavenBundle("orbit", "org.apache.coyote", "7.0.32.v201211201952").noStart(),
+ mavenBundle("orbit", "org.apache.jasper", "7.0.32.v201211201952").noStart(),
mavenBundle("orbit", "org.apache.el", "7.0.32.v201211081135"),
- mavenBundle("orbit", "org.apache.juli.extras",
- "7.0.32.v201211081135"),
- mavenBundle("orbit", "org.apache.tomcat.api",
- "7.0.32.v201211081135"),
- mavenBundle("orbit", "org.apache.tomcat.util",
- "7.0.32.v201211201952").noStart(),
- mavenBundle("orbit", "javax.servlet.jsp.jstl",
- "1.2.0.v201105211821"),
- mavenBundle("orbit", "javax.servlet.jsp.jstl.impl",
- "1.2.0.v201210211230"),
+ mavenBundle("orbit", "org.apache.juli.extras", "7.0.32.v201211081135"),
+ mavenBundle("orbit", "org.apache.tomcat.api", "7.0.32.v201211081135"),
+ mavenBundle("orbit", "org.apache.tomcat.util", "7.0.32.v201211201952").noStart(),
+ mavenBundle("orbit", "javax.servlet.jsp.jstl", "1.2.0.v201105211821"),
+ mavenBundle("orbit", "javax.servlet.jsp.jstl.impl", "1.2.0.v201210211230"),
mavenBundle("org.ops4j.pax.exam", "pax-exam-container-native"),
mavenBundle("org.ops4j.pax.exam", "pax-exam-junit4"),
mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn"),
mavenBundle("org.ops4j.pax.url", "pax-url-aether"),
- mavenBundle("org.springframework", "org.springframework.asm",
- "3.1.3.RELEASE"),
- mavenBundle("org.springframework", "org.springframework.aop",
- "3.1.3.RELEASE"),
- mavenBundle("org.springframework",
- "org.springframework.context", "3.1.3.RELEASE"),
- mavenBundle("org.springframework",
- "org.springframework.context.support", "3.1.3.RELEASE"),
- mavenBundle("org.springframework", "org.springframework.core",
- "3.1.3.RELEASE"),
- mavenBundle("org.springframework", "org.springframework.beans",
- "3.1.3.RELEASE"),
- mavenBundle("org.springframework",
- "org.springframework.expression", "3.1.3.RELEASE"),
- mavenBundle("org.springframework", "org.springframework.web",
- "3.1.3.RELEASE"),
-
- mavenBundle("org.aopalliance",
- "com.springsource.org.aopalliance", "1.0.0"),
- mavenBundle("org.springframework",
- "org.springframework.web.servlet", "3.1.3.RELEASE"),
- mavenBundle("org.springframework.security",
- "spring-security-config", "3.1.3.RELEASE"),
- mavenBundle("org.springframework.security",
- "spring-security-core", "3.1.3.RELEASE"),
- mavenBundle("org.springframework.security",
- "spring-security-web", "3.1.3.RELEASE"),
- mavenBundle("org.springframework.security",
- "spring-security-taglibs", "3.1.3.RELEASE"),
- mavenBundle("org.springframework",
- "org.springframework.transaction", "3.1.3.RELEASE"),
-
- mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans",
- "1.0.0"),
- mavenBundle("org.opendaylight.controller.thirdparty",
- "net.sf.jung2", "2.0.1-SNAPSHOT"),
- mavenBundle("org.opendaylight.controller.thirdparty",
- "com.sun.jersey.jersey-servlet", "1.17-SNAPSHOT"),
+ mavenBundle("org.springframework", "org.springframework.asm", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.aop", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.context", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.context.support", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.core", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.beans", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.expression", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.web", "3.1.3.RELEASE"),
+
+ mavenBundle("org.aopalliance", "com.springsource.org.aopalliance", "1.0.0"),
+ mavenBundle("org.springframework", "org.springframework.web.servlet", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework.security", "spring-security-config", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework.security", "spring-security-core", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework.security", "spring-security-web", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework.security", "spring-security-taglibs", "3.1.3.RELEASE"),
+ mavenBundle("org.springframework", "org.springframework.transaction", "3.1.3.RELEASE"),
+
+ mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans", "1.0.0"),
+ mavenBundle("org.opendaylight.controller.thirdparty", "net.sf.jung2", "2.0.1-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller.thirdparty", "com.sun.jersey.jersey-servlet", "1.17-SNAPSHOT"),
// Jersey needs to be started before the northbound application
// bundles, using a lower start level
mavenBundle("com.sun.jersey", "jersey-client", "1.17"),
- mavenBundle("com.sun.jersey", "jersey-server", "1.17")
- .startLevel(2),
- mavenBundle("com.sun.jersey", "jersey-core", "1.17")
- .startLevel(2),
- mavenBundle("com.sun.jersey", "jersey-json", "1.17")
- .startLevel(2), junitBundles());
+ mavenBundle("com.sun.jersey", "jersey-server", "1.17").startLevel(2),
+ mavenBundle("com.sun.jersey", "jersey-core", "1.17").startLevel(2),
+ mavenBundle("com.sun.jersey", "jersey-json", "1.17").startLevel(2), junitBundles());
}
+
}
// only 1 switch state listener
private ISwitchStateListener switchStateListener;
private AtomicInteger switchInstanceNumber;
+ private int MAXQUEUESIZE = 50000;
/*
* this thread monitors the switchEvents queue for new incoming events from
public void init() {
logger.debug("Initializing!");
this.switches = new ConcurrentHashMap<Long, ISwitch>();
- this.switchEvents = new LinkedBlockingQueue<SwitchEvent>();
+ this.switchEvents = new LinkedBlockingQueue<SwitchEvent>(MAXQUEUESIZE);
this.messageListeners = new ConcurrentHashMap<OFType, IMessageListener>();
this.switchStateListener = null;
this.switchInstanceNumber = new AtomicInteger(0);
running = true;
while (running) {
try {
- if (!transmitQ.isEmpty()) {
+ while (!transmitQ.isEmpty()) {
PriorityMessage pmsg = transmitQ.poll();
msgReadWriteService.asyncSend(pmsg.msg);
logger.trace("Message sent: {}", pmsg);
package org.opendaylight.controller.protocol_plugin.openflow.internal;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
/**
* The class describes neighbor discovery service for an OpenFlow network.
*/
-public class DiscoveryService implements IInventoryShimExternalListener,
- IDataPacketListen, IContainerListener, CommandProvider {
- private static Logger logger = LoggerFactory
- .getLogger(DiscoveryService.class);
+public class DiscoveryService implements IInventoryShimExternalListener, IDataPacketListen, IContainerListener,
+ CommandProvider {
+ private static Logger logger = LoggerFactory.getLogger(DiscoveryService.class);
private IController controller = null;
private IDiscoveryListener discoveryListener = null;
private IInventoryProvider inventoryProvider = null;
private IDataPacketMux iDataPacketMux = null;
-
- private List<NodeConnector> readyListHi = null; // newly added ports go into
- // this list and will be
- // served first
- private List<NodeConnector> readyListLo = null; // come here after served at
- // least once
- private List<NodeConnector> waitingList = null; // staging area during quiet
- // period
- private ConcurrentMap<NodeConnector, Integer> pendingMap = null;// wait for
- // response
- // back
- private ConcurrentMap<NodeConnector, Edge> edgeMap = null; // openflow edges
- // keyed by head
- // connector
- private ConcurrentMap<NodeConnector, Integer> agingMap = null; // aging
- // entries
- // keyed by
- // edge port
- private ConcurrentMap<NodeConnector, Edge> prodMap = null; // production
- // edges keyed by
- // edge port
-
- private Timer discoveryTimer; // discovery timer
- private DiscoveryTimerTask discoveryTimerTask; // timer task
+ // Newly added ports go into this list and will be served first
+ private List<NodeConnector> readyListHi = null;
+ // Come here after served at least once
+ private List<NodeConnector> readyListLo = null;
+ // Staging area during quiet period
+ private List<NodeConnector> waitingList = null;
+ // Wait for next discovery packet. The map contains the time elapsed since
+ // the last received LLDP frame on each node connector
+ private ConcurrentMap<NodeConnector, Integer> pendingMap = null;
+ // openflow edges keyed by head connector
+ private ConcurrentMap<NodeConnector, Edge> edgeMap = null;
+ // Aging entries keyed by head edge connector
+ private ConcurrentMap<NodeConnector, Integer> agingMap = null;
+ // Production edges keyed by head edge connector
+ private ConcurrentMap<NodeConnector, Edge> prodMap = null;
+
+ private Timer discoveryTimer;
+ private DiscoveryTimerTask discoveryTimerTask;
private long discoveryTimerTick = 1L * 1000; // per tick in msec
private int discoveryTimerTickCount = 0; // main tick counter
- private int discoveryBatchMaxPorts = 500; // max # of ports handled in one
- // batch
- private int discoveryBatchRestartTicks = getDiscoveryInterval(); // periodically
- // restart
- // batching
- // process
+ // Max # of ports handled in one batch
+ private int discoveryBatchMaxPorts = 500;
+ // Periodically restart batching process
+ private int discoveryBatchRestartTicks = getDiscoveryInterval();
private int discoveryBatchPausePeriod = 5; // pause for few secs
- private int discoveryBatchPauseTicks = discoveryBatchRestartTicks
- - discoveryBatchPausePeriod; // pause after this point
- private int discoveryRetry = getDiscoveryRetry(); // number of retries after
- // initial timeout
+ // Pause after this point
+ private int discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod;
+ // Number of retries after initial timeout
+ private int discoveryRetry = getDiscoveryRetry();
private int discoveryTimeoutTicks = getDiscoveryTimeout(); // timeout in sec
private int discoveryAgeoutTicks = 120; // age out 2 min
- private int discoveryConsistencyCheckMultiple = 2; // multiple of
- // discoveryBatchRestartTicks
- private int discoveryConsistencyCheckTickCount = discoveryBatchPauseTicks; // CC
- // tick
- // counter
- private int discoveryConsistencyCheckCallingTimes = 0; // # of times CC gets
- // called
- private int discoveryConsistencyCheckCorrected = 0; // # of cases CC
- // corrected
- private boolean discoveryConsistencyCheckEnabled = true;// enable or disable
- // CC
- private boolean discoveryAgingEnabled = true; // enable or disable aging
- private boolean discoverySnoopingEnabled = true; // global flag to enable or
- // disable LLDP snooping
- private List<NodeConnector> discoverySnoopingDisableList; // the list of
- // ports that will
- // not do LLDP
- // snooping
+ // multiple of discoveryBatchRestartTicks
+ private int discoveryConsistencyCheckMultiple = 2;
+ // CC tick counter
+ private int discoveryConsistencyCheckTickCount = discoveryBatchPauseTicks;
+ // # of times CC getscalled
+ private int discoveryConsistencyCheckCallingTimes = 0;
+ // # of cases CC corrected
+ private int discoveryConsistencyCheckCorrected = 0;
+ // Enable or disable CC
+ private boolean discoveryConsistencyCheckEnabled = true;
+ // Enable or disable aging
+ private boolean discoveryAgingEnabled = true;
+ // Global flag to enable or disable LLDP snooping
+ private boolean discoverySnoopingEnabled = true;
+ // The list of ports that will not do LLDP snooping
+ private List<NodeConnector> discoverySnoopingDisableList;
private BlockingQueue<NodeConnector> transmitQ;
private Thread transmitThread;
private Boolean throttling = false; // if true, no more batching.
this.transmitQ = transmitQ;
}
+ @Override
public void run() {
while (true) {
try {
nodeConnector = null;
} catch (InterruptedException e1) {
logger.warn("DiscoveryTransmit interupted", e1.getMessage());
- if (shuttingDown)
+ if (shuttingDown) {
return;
+ }
} catch (Exception e2) {
logger.error("", e2);
}
}
class DiscoveryTimerTask extends TimerTask {
+ @Override
public void run() {
checkTimeout();
checkAging();
}
private RawPacket createDiscoveryPacket(NodeConnector nodeConnector) {
- String nodeId = HexEncode.longToHexString((Long) nodeConnector
- .getNode().getID());
+ String nodeId = HexEncode.longToHexString((Long) nodeConnector.getNode().getID());
// Create LLDP ChassisID TLV
byte[] cidValue = LLDPTLV.createChassisIDTLVValue(nodeId);
- chassisIdTlv.setType((byte) LLDPTLV.TLVType.ChassisID.getValue())
- .setLength((short) cidValue.length).setValue(cidValue);
+ chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()).setLength((short) cidValue.length)
+ .setValue(cidValue);
// Create LLDP PortID TLV
String portId = nodeConnector.getNodeConnectorIDString();
byte[] pidValue = LLDPTLV.createPortIDTLVValue(portId);
- portIdTlv.setType((byte) LLDPTLV.TLVType.PortID.getValue())
- .setLength((short) pidValue.length).setValue(pidValue);
+ portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()).setLength((short) pidValue.length).setValue(pidValue);
// Create LLDP Custom TLV
- byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnector
- .toString());
- customTlv.setType((byte) LLDPTLV.TLVType.Custom.getValue())
- .setLength((short) customValue.length).setValue(customValue);
+ byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnector.toString());
+ customTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customValue.length)
+ .setValue(customValue);
// Create LLDP Custom Option list
List<LLDPTLV> customList = new ArrayList<LLDPTLV>();
// Create discovery pkt
LLDP discoveryPkt = new LLDP();
- discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv)
- .setTtl(ttlTlv).setOptionalTLVList(customList);
+ discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv).setTtl(ttlTlv).setOptionalTLVList(customList);
RawPacket rawPkt = null;
try {
// Create ethernet pkt
- byte[] sourceMac = getSouceMACFromNodeID(nodeId);
+ byte[] sourceMac = getSourceMACFromNodeID(nodeId);
Ethernet ethPkt = new Ethernet();
- ethPkt.setSourceMACAddress(sourceMac)
- .setDestinationMACAddress(LLDP.LLDPMulticastMac)
- .setEtherType(EtherTypes.LLDP.shortValue())
- .setPayload(discoveryPkt);
+ ethPkt.setSourceMACAddress(sourceMac).setDestinationMACAddress(LLDP.LLDPMulticastMac)
+ .setEtherType(EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt);
byte[] data = ethPkt.serialize();
rawPkt = new RawPacket(data);
rawPkt.setOutgoingNodeConnector(nodeConnector);
} catch (ConstructionException cex) {
- logger.warn("RawPacket creation caught exception {}",
- cex.getMessage());
+ logger.warn("RawPacket creation caught exception {}", cex.getMessage());
} catch (Exception e) {
logger.error("Failed to serialize the LLDP packet: " + e);
}
return rawPkt;
}
- private void sendDiscoveryPacket(NodeConnector nodeConnector,
- RawPacket outPkt) {
+ private void sendDiscoveryPacket(NodeConnector nodeConnector, RawPacket outPkt) {
if (nodeConnector == null) {
logger.debug("Can not send discovery packet out since nodeConnector is null");
return;
ISwitch sw = controller.getSwitches().get(sid);
if (sw == null) {
- logger.debug(
- "Can not send discovery packet out since switch {} is null",
- sid);
+ logger.debug("Can not send discovery packet out since switch {} is null", sid);
return;
}
if (!sw.isOperational()) {
- logger.debug(
- "Can not send discovery packet out since switch {} is not operational",
- sw);
+ logger.debug("Can not send discovery packet out since switch {} is not operational", sw);
return;
}
return PacketResult.IGNORED;
}
- if (((Short) inPkt.getIncomingNodeConnector().getID())
- .equals(NodeConnector.SPECIALNODECONNECTORID)) {
+ if (((Short) inPkt.getIncomingNodeConnector().getID()).equals(NodeConnector.SPECIALNODECONNECTORID)) {
logger.trace("Ignoring ethernet packet received on special port: "
+ inPkt.getIncomingNodeConnector().toString());
return PacketResult.IGNORED;
try {
ethPkt.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
} catch (Exception e) {
- logger.warn("Failed to decode LLDP packet from {}: {}",
- inPkt.getIncomingNodeConnector(), e);
+ logger.warn("Failed to decode LLDP packet from {}: {}", inPkt.getIncomingNodeConnector(), e);
return PacketResult.IGNORED;
}
NodeConnector dst = inPkt.getIncomingNodeConnector();
if (isEnabled(dst)) {
if (!processDiscoveryPacket(dst, ethPkt)) {
- /* Snoop the discovery pkt if not generated from us */
+ // Snoop the discovery pkt if not generated from us
snoopDiscoveryPacket(dst, ethPkt);
}
return PacketResult.CONSUME;
* Snoop incoming discovery frames generated by the production network
* neighbor switch
*/
- private void snoopDiscoveryPacket(NodeConnector dstNodeConnector,
- Ethernet ethPkt) {
- if (!this.discoverySnoopingEnabled
- || discoverySnoopingDisableList.contains(dstNodeConnector)) {
- logger.trace(
- "Discarded received discovery packet on {} since snooping is turned off",
- dstNodeConnector);
+ private void snoopDiscoveryPacket(NodeConnector dstNodeConnector, Ethernet ethPkt) {
+ if (!this.discoverySnoopingEnabled || discoverySnoopingDisableList.contains(dstNodeConnector)) {
+ logger.trace("Discarded received discovery packet on {} since snooping is turned off", dstNodeConnector);
return;
}
LLDP lldp = (LLDP) ethPkt.getPayload();
try {
- String nodeId = LLDPTLV.getHexStringValue(lldp.getChassisId()
- .getValue(), lldp.getChassisId().getLength());
- String portId = LLDPTLV.getStringValue(lldp.getPortId().getValue(),
- lldp.getPortId().getLength());
+ String nodeId = LLDPTLV.getHexStringValue(lldp.getChassisId().getValue(), lldp.getChassisId().getLength());
+ String portId = LLDPTLV.getStringValue(lldp.getPortId().getValue(), lldp.getPortId().getLength());
byte[] systemNameBytes = null;
// get system name if present in the LLDP pkt
for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) {
break;
}
}
- String nodeName = (systemNameBytes == null) ? nodeId : new String(
- systemNameBytes);
+ String nodeName = (systemNameBytes == null) ? nodeId
+ : new String(systemNameBytes, Charset.defaultCharset());
Node srcNode = new Node(Node.NodeIDType.PRODUCTION, nodeName);
- NodeConnector srcNodeConnector = NodeConnectorCreator
- .createNodeConnector(
- NodeConnector.NodeConnectorIDType.PRODUCTION,
- portId, srcNode);
+ NodeConnector srcNodeConnector = NodeConnectorCreator.createNodeConnector(
+ NodeConnector.NodeConnectorIDType.PRODUCTION, portId, srcNode);
Edge edge = null;
Set<Property> props = null;
*
* @return true if it's a success
*/
- private boolean processDiscoveryPacket(NodeConnector dstNodeConnector,
- Ethernet ethPkt) {
+ private boolean processDiscoveryPacket(NodeConnector dstNodeConnector, Ethernet ethPkt) {
if ((dstNodeConnector == null) || (ethPkt == null)) {
logger.trace("Ignoring processing of discovery packet: Null node connector or packet");
return false;
}
- logger.trace("Handle discovery packet {} from {}", ethPkt,
- dstNodeConnector);
+ logger.trace("Handle discovery packet {} from {}", ethPkt, dstNodeConnector);
LLDP lldp = (LLDP) ethPkt.getPayload();
List<LLDPTLV> optionalTLVList = lldp.getOptionalTLVList();
if (optionalTLVList == null) {
- logger.info("The discovery packet with null custom option from {}",
- dstNodeConnector);
+ logger.info("The discovery packet with null custom option from {}", dstNodeConnector);
return false;
}
NodeConnector srcNodeConnector = null;
for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) {
if (lldptlv.getType() == LLDPTLV.TLVType.Custom.getValue()) {
- String ncString = LLDPTLV.getCustomString(lldptlv.getValue(),
- lldptlv.getLength());
+ String ncString = LLDPTLV.getCustomString(lldptlv.getValue(), lldptlv.getLength());
srcNodeConnector = NodeConnector.fromString(ncString);
if (srcNodeConnector != null) {
srcNode = srcNodeConnector.getNode();
- /* Check if it's expected */
- if (isTracked(srcNodeConnector)) {
- break;
- } else {
- srcNode = null;
- srcNodeConnector = null;
- }
}
}
}
if ((srcNode == null) || (srcNodeConnector == null)) {
- logger.trace(
- "Received non-controller generated discovery packet from {}",
- dstNodeConnector);
+ logger.trace("Received non-controller generated discovery packet from {}", dstNodeConnector);
return false;
}
logger.error("Caught exception ", e);
}
addEdge(edge, props);
+ pendingMap.put(dstNodeConnector, 0);
logger.trace("Received discovery packet for Edge {}", edge);
return null;
}
- Map<NodeConnector, Map<String, Property>> props = inventoryProvider
- .getNodeConnectorProps(false);
+ Map<NodeConnector, Map<String, Property>> props = inventoryProvider.getNodeConnectorProps(false);
if (props == null) {
return null;
}
return null;
}
- Property prop = (Property) propMap.get(propName);
+ Property prop = propMap.get(propName);
return prop;
}
Config config = (Config) getProp(nodeConnector, Config.ConfigPropName);
State state = (State) getProp(nodeConnector, State.StatePropName);
- return ((config != null) && (config.getValue() == Config.ADMIN_UP)
- && (state != null) && (state.getValue() == State.EDGE_UP));
+ return ((config != null) && (config.getValue() == Config.ADMIN_UP) && (state != null) && (state.getValue() == State.EDGE_UP));
}
private boolean isTracked(NodeConnector nodeConnector) {
private void addDiscovery(Node node) {
Map<Long, ISwitch> switches = controller.getSwitches();
- ISwitch sw = switches.get((Long) node.getID());
+ ISwitch sw = switches.get(node.getID());
List<OFPhysicalPort> ports = sw.getEnabledPorts();
if (ports == null) {
return;
}
for (OFPhysicalPort port : ports) {
- NodeConnector nodeConnector = NodeConnectorCreator
- .createOFNodeConnector(port.getPortNumber(), node);
+ NodeConnector nodeConnector = NodeConnectorCreator.createOFNodeConnector(port.getPortNumber(), node);
if (!readyListHi.contains(nodeConnector)) {
readyListHi.add(nodeConnector);
}
readyListHi.add(nodeConnector);
}
- private Set<NodeConnector> getRemoveSet(Collection<NodeConnector> c,
- Node node) {
+ private Set<NodeConnector> getRemoveSet(Collection<NodeConnector> c, Node node) {
Set<NodeConnector> removeSet = new HashSet<NodeConnector>();
if (c == null) {
return removeSet;
private void checkTimeout() {
Set<NodeConnector> removeSet = new HashSet<NodeConnector>();
Set<NodeConnector> retrySet = new HashSet<NodeConnector>();
- int sentCount;
+ int ticks;
Set<NodeConnector> pendingSet = pendingMap.keySet();
if (pendingSet != null) {
for (NodeConnector nodeConnector : pendingSet) {
- sentCount = pendingMap.get(nodeConnector);
- pendingMap.put(nodeConnector, ++sentCount);
- if (sentCount > getDiscoveryFinalTimeoutInterval()) {
+ ticks = pendingMap.get(nodeConnector);
+ pendingMap.put(nodeConnector, ++ticks);
+ if (ticks > getDiscoveryFinalTimeoutInterval()) {
// timeout the edge
removeSet.add(nodeConnector);
logger.trace("Discovery timeout {}", nodeConnector);
- } else if (sentCount % discoveryTimeoutTicks == 0) {
+ } else if (ticks % discoveryTimeoutTicks == 0) {
retrySet.add(nodeConnector);
}
}
}
Set<NodeConnector> removeSet = new HashSet<NodeConnector>();
- int sentCount;
+ int ticks;
Set<NodeConnector> agingSet = agingMap.keySet();
if (agingSet != null) {
for (NodeConnector nodeConnector : agingSet) {
- sentCount = agingMap.get(nodeConnector);
- agingMap.put(nodeConnector, ++sentCount);
- if (sentCount > discoveryAgeoutTicks) {
+ ticks = agingMap.get(nodeConnector);
+ agingMap.put(nodeConnector, ++ticks);
+ if (ticks > discoveryAgeoutTicks) {
// age out the edge
removeSet.add(nodeConnector);
logger.trace("Discovery age out {}", nodeConnector);
private void doDiscovery() {
if (++discoveryTimerTickCount <= discoveryBatchPauseTicks) {
for (NodeConnector nodeConnector : getWorkingSet()) {
- pendingMap.put(nodeConnector, 0);
transmitQ.add(nodeConnector);
}
} else if (discoveryTimerTickCount >= discoveryBatchRestartTicks) {
discoveryTimerTickCount = 0;
for (NodeConnector nodeConnector : waitingList) {
- if (!readyListLo.contains(nodeConnector))
+ if (!readyListLo.contains(nodeConnector)) {
readyListLo.add(nodeConnector);
+ }
}
waitingList.removeAll(readyListLo);
}
return;
}
- if (++discoveryConsistencyCheckTickCount
- % getDiscoveryConsistencyCheckInterval() != 0) {
+ if (++discoveryConsistencyCheckTickCount % getDiscoveryConsistencyCheckInterval() != 0) {
return;
}
if (!isEnabled(nodeConnector)) {
removeSet.add(nodeConnector);
discoveryConsistencyCheckCorrected++;
- logger.debug("ConsistencyChecker: remove disabled {}",
- nodeConnector);
+ logger.debug("ConsistencyChecker: remove disabled {}", nodeConnector);
continue;
}
if (!isTracked(nodeConnector)) {
waitingList.add(nodeConnector);
discoveryConsistencyCheckCorrected++;
- logger.debug("ConsistencyChecker: add back untracked {}",
- nodeConnector);
+ logger.debug("ConsistencyChecker: add back untracked {}", nodeConnector);
continue;
}
}
if (!isEnabled(nodeConnector)) {
removeSet.add(nodeConnector);
discoveryConsistencyCheckCorrected++;
- logger.debug("ConsistencyChecker: remove disabled {}",
- nodeConnector);
+ logger.debug("ConsistencyChecker: remove disabled {}", nodeConnector);
}
}
waitingList.removeAll(removeSet);
for (ISwitch sw : switches.values()) {
for (OFPhysicalPort port : sw.getEnabledPorts()) {
Node node = NodeCreator.createOFNode(sw.getId());
- NodeConnector nodeConnector = NodeConnectorCreator
- .createOFNodeConnector(port.getPortNumber(), node);
+ NodeConnector nodeConnector = NodeConnectorCreator.createOFNodeConnector(port.getPortNumber(), node);
if (!isTracked(nodeConnector)) {
waitingList.add(nodeConnector);
discoveryConsistencyCheckCorrected++;
- logger.debug("ConsistencyChecker: add back untracked {}",
- nodeConnector);
+ logger.debug("ConsistencyChecker: add back untracked {}", nodeConnector);
}
}
}
NodeConnector src = edge.getTailNodeConnector();
if (!src.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
pendingMap.remove(src);
- if (!waitingList.contains(src)) {
- waitingList.add(src);
- }
} else {
NodeConnector dst = edge.getHeadNodeConnector();
agingMap.put(dst, 0);
}
- // notify routeEngine
+ // notify
updateEdge(edge, UpdateType.ADDED, props);
logger.trace("Add edge {}", edge);
}
/* Do not update in case there is an existing OpenFlow link */
if (edgeMap.get(edgePort) != null) {
- logger.trace(
- "Discarded edge {} since there is an existing OF link {}",
- edge, edgeMap.get(edgePort));
+ logger.trace("Discarded edge {} since there is an existing OF link {}", edge, edgeMap.get(edgePort));
return;
}
this.discoveryListener.notifyEdge(edge, type, props);
- NodeConnector src = edge.getTailNodeConnector(), dst = edge
- .getHeadNodeConnector();
+ NodeConnector src = edge.getTailNodeConnector(), dst = edge.getHeadNodeConnector();
if (!src.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
if (type == UpdateType.ADDED) {
edgeMap.put(dst, edge);
}
}
- private void moreToReadyListHi(NodeConnector nodeConnector) {
+ private void moveToReadyListHi(NodeConnector nodeConnector) {
if (readyListLo.contains(nodeConnector)) {
readyListLo.remove(nodeConnector);
- readyListHi.add(nodeConnector);
} else if (waitingList.contains(nodeConnector)) {
waitingList.remove(nodeConnector);
- readyListHi.add(nodeConnector);
}
+ readyListHi.add(nodeConnector);
}
private void registerWithOSGIConsole() {
- BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- bundleContext.registerService(CommandProvider.class.getName(), this,
- null);
+ BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ bundleContext.registerService(CommandProvider.class.getName(), this, null);
}
private int getDiscoveryConsistencyCheckInterval() {
}
public void _ppl(CommandInterpreter ci) {
- ci.println("PendingList\n");
- for (NodeConnector nodeConnector : pendingMap.keySet()) {
- if (nodeConnector == null) {
- continue;
- }
- ci.println(nodeConnector);
+ ci.println("pendingMap\n");
+ ci.println(" NodeConnector Last rx LLDP (s)");
+ for (ConcurrentMap.Entry<NodeConnector, Integer> entry: pendingMap.entrySet()) {
+ ci.println(entry.getKey() + "\t\t" + entry.getValue());
}
}
}
ci.println("Interval " + getDiscoveryConsistencyCheckInterval());
ci.println("Multiple " + discoveryConsistencyCheckMultiple);
- ci.println("Number of times called "
- + discoveryConsistencyCheckCallingTimes);
+ ci.println("Number of times called " + discoveryConsistencyCheckCallingTimes);
ci.println("Corrected count " + discoveryConsistencyCheckCorrected);
}
}
public void _psize(CommandInterpreter ci) {
- ci.println("readyListLo size " + readyListLo.size() + "\n"
- + "readyListHi size " + readyListHi.size() + "\n"
- + "waitingList size " + waitingList.size() + "\n"
- + "pendingMap size " + pendingMap.size() + "\n"
- + "edgeMap size " + edgeMap.size() + "\n" + "prodMap size "
- + prodMap.size() + "\n" + "agingMap size " + agingMap.size());
+ ci.println("readyListLo size " + readyListLo.size() + "\n" + "readyListHi size " + readyListHi.size() + "\n"
+ + "waitingList size " + waitingList.size() + "\n" + "pendingMap size " + pendingMap.size() + "\n"
+ + "edgeMap size " + edgeMap.size() + "\n" + "prodMap size " + prodMap.size() + "\n" + "agingMap size "
+ + agingMap.size());
}
public void _page(CommandInterpreter ci) {
public void _sage(CommandInterpreter ci) {
String val = ci.nextArgument();
if (val == null) {
- ci.println("Please enter aging time limit. Current value "
- + this.discoveryAgeoutTicks);
+ ci.println("Please enter aging time limit. Current value " + this.discoveryAgeoutTicks);
return;
}
try {
public void _scc(CommandInterpreter ci) {
String val = ci.nextArgument();
if (val == null) {
- ci.println("Please enter CC multiple. Current multiple "
- + discoveryConsistencyCheckMultiple + " (interval "
- + getDiscoveryConsistencyCheckInterval()
- + ") calling times "
+ ci.println("Please enter CC multiple. Current multiple " + discoveryConsistencyCheckMultiple
+ + " (interval " + getDiscoveryConsistencyCheckInterval() + ") calling times "
+ discoveryConsistencyCheckCallingTimes);
return;
}
NodeConnector nodeConnector = NodeConnector.fromString(val);
if (nodeConnector != null) {
discoverySnoopingDisableList.remove(nodeConnector);
- ci.println("Discovery snooping is locally enabled on port "
- + nodeConnector);
+ ci.println("Discovery snooping is locally enabled on port " + nodeConnector);
} else {
ci.println("Entered invalid NodeConnector " + val);
}
NodeConnector nodeConnector = NodeConnector.fromString(val);
if (nodeConnector != null) {
discoverySnoopingDisableList.add(nodeConnector);
- ci.println("Discovery snooping is locally disabled on port "
- + nodeConnector);
+ ci.println("Discovery snooping is locally disabled on port " + nodeConnector);
} else {
ci.println("Entered invalid NodeConnector " + val);
}
public void _spause(CommandInterpreter ci) {
String val = ci.nextArgument();
- String out = "Please enter pause period less than "
- + discoveryBatchRestartTicks + ". Current pause period is "
- + discoveryBatchPausePeriod + " pause tick is "
- + discoveryBatchPauseTicks + ".";
+ String out = "Please enter pause period less than " + discoveryBatchRestartTicks + ". Current pause period is "
+ + discoveryBatchPausePeriod + " pause tick is " + discoveryBatchPauseTicks + ".";
if (val != null) {
try {
int pause = Integer.parseInt(val);
if (pause < discoveryBatchRestartTicks) {
discoveryBatchPausePeriod = pause;
- discoveryBatchPauseTicks = discoveryBatchRestartTicks
- - discoveryBatchPausePeriod;
+ discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod;
return;
}
} catch (Exception e) {
public void _sdi(CommandInterpreter ci) {
String val = ci.nextArgument();
- String out = "Please enter discovery interval greater than "
- + discoveryBatchPausePeriod + ". Current value is "
- + discoveryBatchRestartTicks + ".";
+ String out = "Please enter discovery interval greater than " + discoveryBatchPausePeriod
+ + ". Current value is " + discoveryBatchRestartTicks + ".";
if (val != null) {
try {
int restart = Integer.parseInt(val);
if (restart > discoveryBatchPausePeriod) {
discoveryBatchRestartTicks = restart;
- discoveryBatchPauseTicks = discoveryBatchRestartTicks
- - discoveryBatchPausePeriod;
+ discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod;
return;
}
} catch (Exception e) {
public void _sports(CommandInterpreter ci) {
String val = ci.nextArgument();
if (val == null) {
- ci.println("Please enter max ports per batch. Current value is "
- + discoveryBatchMaxPorts);
+ ci.println("Please enter max ports per batch. Current value is " + discoveryBatchMaxPorts);
return;
}
try {
public void _sretry(CommandInterpreter ci) {
String val = ci.nextArgument();
if (val == null) {
- ci.println("Please enter number of retries. Current value is "
- + discoveryRetry);
+ ci.println("Please enter number of retries. Current value is " + discoveryRetry);
return;
}
try {
public void _stm(CommandInterpreter ci) {
String val = ci.nextArgument();
- String out = "Please enter timeout tick value less than "
- + discoveryBatchRestartTicks + ". Current value is "
+ String out = "Please enter timeout tick value less than " + discoveryBatchRestartTicks + ". Current value is "
+ discoveryTimeoutTicks;
if (val != null) {
try {
}
@Override
- public void updateNodeConnector(NodeConnector nodeConnector,
- UpdateType type, Set<Property> props) {
+ public void updateNodeConnector(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
Config config = null;
State state = null;
boolean enabled = false;
state = (State) prop;
}
}
- enabled = ((config != null) && (config.getValue() == Config.ADMIN_UP)
- && (state != null) && (state.getValue() == State.EDGE_UP));
+ enabled = ((config != null) && (config.getValue() == Config.ADMIN_UP) && (state != null) && (state.getValue() == State.EDGE_UP));
switch (type) {
case ADDED:
}
public void addNode(Node node, Set<Property> props) {
- if (node == null)
+ if (node == null) {
return;
+ }
addDiscovery(node);
}
public void removeNode(Node node) {
- if (node == null)
+ if (node == null) {
return;
+ }
removeDiscovery(node);
}
private void initDiscoveryPacket() {
// Create LLDP ChassisID TLV
chassisIdTlv = new LLDPTLV();
- chassisIdTlv.setType((byte) LLDPTLV.TLVType.ChassisID.getValue());
+ chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue());
// Create LLDP PortID TLV
portIdTlv = new LLDPTLV();
- portIdTlv.setType((byte) LLDPTLV.TLVType.PortID.getValue());
+ portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue());
// Create LLDP TTL TLV
byte[] ttl = new byte[] { (byte) 0, (byte) 120 };
ttlTlv = new LLDPTLV();
- ttlTlv.setType((byte) LLDPTLV.TLVType.TTL.getValue())
- .setLength((short) ttl.length).setValue(ttl);
+ ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue()).setLength((short) ttl.length).setValue(ttl);
customTlv = new LLDPTLV();
}
*
*/
void start() {
- discoveryTimer.schedule(discoveryTimerTask, discoveryTimerTick,
- discoveryTimerTick);
+ discoveryTimer.schedule(discoveryTimerTask, discoveryTimerTick, discoveryTimerTick);
transmitThread.start();
}
}
@Override
- public void tagUpdated(String containerName, Node n, short oldTag,
- short newTag, UpdateType t) {
+ public void tagUpdated(String containerName, Node n, short oldTag, short newTag, UpdateType t) {
}
@Override
- public void containerFlowUpdated(String containerName,
- ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) {
+ public void containerFlowUpdated(String containerName, ContainerFlow previousFlow, ContainerFlow currentFlow,
+ UpdateType t) {
}
@Override
- public void nodeConnectorUpdated(String containerName, NodeConnector p,
- UpdateType t) {
+ public void nodeConnectorUpdated(String containerName, NodeConnector p, UpdateType t) {
switch (t) {
case ADDED:
- moreToReadyListHi(p);
+ moveToReadyListHi(p);
break;
default:
break;
// do nothing
}
- private byte[] getSouceMACFromNodeID(String nodeId) {
+ private byte[] getSourceMACFromNodeID(String nodeId) {
byte[] cid = HexEncode.bytesFromHexString(nodeId);
byte[] sourceMac = new byte[6];
int pos = cid.length - sourceMac.length;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
package org.opendaylight.controller.sal.action;
+import java.io.Serializable;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.LoggerFactory;
/**
- * Represents the generic action to be applied to the matched frame/packet/message
+ * Represents the generic action to be applied to the matched
+ * frame/packet/message
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-@XmlSeeAlso({Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class,
- PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class,
- SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class, SwPath.class})
-public abstract class Action {
+@XmlSeeAlso({ Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class,
+ PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class,
+ SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class,
+ SwPath.class })
+public abstract class Action implements Serializable {
+ private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(Action.class);
- private static boolean debug = false; // Enable to find where in the code an invalid assignment is made
+ private static boolean debug = false; // Enable to find where in the code an
+ // invalid assignment is made
@XmlTransient
protected ActionType type;
private transient boolean isValid = true;
/* Dummy constructor for JAXB */
- public Action () {
+ public Action() {
}
/*
- public Action (ActionType type, Object value) {
- this.type = type;
- this.value = value;
- this.isValid = true;
- } */
+ * public Action (ActionType type, Object value) { this.type = type;
+ * this.value = value; this.isValid = true; }
+ */
/**
* Checks if the passed value is in the valid range for this action
}
/**
- * Checks if the passed value is in the valid range for the passed action type
- * This method is used for complex Action types which are
+ * Checks if the passed value is in the valid range for the passed action
+ * type This method is used for complex Action types which are
*
* @param value
* @return boolean
* @return void
*/
private void throwValueException(int value) {
- String error = "Invalid field value assignement. For type: "
- + type.getId() + " Expected: " + type.getRange() + ", Got: 0x"
- + Integer.toHexString(value);
+ String error = "Invalid field value assignement. For type: " + type.getId() + " Expected: " + type.getRange()
+ + ", Got: 0x" + Integer.toHexString(value);
try {
throw new Exception(error);
} catch (Exception e) {
logger.error(e.getMessage());
if (debug) {
- logger.error("",e);
+ logger.error("", e);
}
}
}
/**
* Returns whether the Action is valid or not
*
- * @return boolean
+ * @return boolean
*/
public boolean isValid() {
return isValid;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Action other = (Action) obj;
- if (type != other.type)
+ if (type != other.type) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* The enumeration of actions supported by the controller
* Each entry has a unique id and the values range for the action element where applicable
- *
- *
- *
*/
public enum ActionType {
DROP("drop", 0, 0),
}
public String getRange() {
- return "[0x" + Long.toHexString(minValue) + "-0x"
- + Long.toHexString(maxValue) + "]";
+ return "[0x" + Long.toHexString(minValue) + "-0x" + Long.toHexString(maxValue) + "]";
}
public boolean takesParameter() {
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represents the action of punting the packet to the controller
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class Controller extends Action {
+ private static final long serialVersionUID = 1L;
public Controller() {
type = ActionType.CONTROLLER;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represent the action of dropping the matched packet
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Drop extends Action {
+ private static final long serialVersionUID = 1L;
+
public Drop() {
type = ActionType.DROP;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represents the action of flooding the packet out
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class Flood extends Action {
+ private static final long serialVersionUID = 1L;
public Flood() {
type = ActionType.FLOOD;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import javax.xml.bind.annotation.XmlRootElement;
/**
- * Represents the action of flooding the packet out all the physical ports except the input port
- *
- *
- *
+ * Represents the action of flooding the packet out all the physical ports
+ * except the input port
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class FloodAll extends Action {
+ private static final long serialVersionUID = 1L;
public FloodAll() {
type = ActionType.FLOOD_ALL;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import javax.xml.bind.annotation.XmlRootElement;
/**
- * Represents the action of sending the packet to the local hardware path for processing
- *
- *
- *
+ * Represents the action of sending the packet to the local hardware path for
+ * processing
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class HwPath extends Action {
+ private static final long serialVersionUID = 1L;
public HwPath() {
type = ActionType.HW_PATH;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represents the action of looping the packet back the port it came in from
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class Loopback extends Action {
+ private static final long serialVersionUID = 1L;
public Loopback() {
type = ActionType.LOOPBACK;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represents the action of sending the packet out of a physical port
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class Output extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private NodeConnector port;
/* Dummy constructor for JAXB */
- private Output () {
+ @SuppressWarnings("unused")
+ private Output() {
}
public Output(NodeConnector port) {
type = ActionType.OUTPUT;
this.port = port;
- //checkValue(port);
+ // checkValue(port);
}
public NodeConnector getPort() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Output other = (Output) obj;
if (port == null) {
- if (other.port != null)
+ if (other.port != null) {
return false;
- } else if (!port.equals(other.port))
+ }
+ } else if (!port.equals(other.port)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Pop vlan action (strip the outermost 802.1q header)
- *
- *
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class PopVlan extends Action {
+ private static final long serialVersionUID = 1L;
public PopVlan() {
type = ActionType.POP_VLAN;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import org.opendaylight.controller.sal.utils.EtherTypes;
/**
- * Insert a 802.1q (outermost) header action
- * Execute it multiple times to achieve QinQ
- *
- * 802.1q = [TPID(16) + TCI(16)]
- * TCI = [PCP(3) + CFI(1) + VID(12)]
- *
- *
+ * Insert a 802.1q (outermost) header action Execute it multiple times to
+ * achieve QinQ
*
+ * 802.1q = [TPID(16) + TCI(16)] TCI = [PCP(3) + CFI(1) + VID(12)]
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class PushVlan extends Action {
+ private static final long serialVersionUID = 1L;
private int tag; // TPID - 16 bits
private int pcp; // PCP - 3 bits
private int cfi; // CFI - 1 bit (drop eligible)
private transient int header; // full 802.1q header [TPID + TCI] - 32 bits
/* Dummy constructor for JAXB */
- private PushVlan () {
+ @SuppressWarnings("unused")
+ private PushVlan() {
}
public PushVlan(int tag, int pcp, int cfi, int vlanId) {
}
private int createHeader() {
- return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12
- | (vlanId & 0xfff);
+ return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
}
private void runChecks() {
checkValue(tci);
// Run action specific check which cannot be run by parent
- if (tag != EtherTypes.VLANTAGGED.intValue()
- && tag != EtherTypes.QINQ.intValue()
- && tag != EtherTypes.OLDQINQ.intValue()
- && tag != EtherTypes.CISCOQINQ.intValue()) {
- // pass a value which will tell fail and tell something about the original wrong value
+ if (tag != EtherTypes.VLANTAGGED.intValue() && tag != EtherTypes.QINQ.intValue()
+ && tag != EtherTypes.OLDQINQ.intValue() && tag != EtherTypes.CISCOQINQ.intValue()) {
+ // pass a value which will tell fail and tell something about the
+ // original wrong value
checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
}
}
/**
- * Returns the VID portion of the 802.1q header this action will insert
- * VID - (12 bits)
+ * Returns the VID portion of the 802.1q header this action will insert VID
+ * - (12 bits)
+ *
* @return byte[]
*/
public int getVlanId() {
}
/**
- * Returns the CFI portion of the 802.1q header this action will insert
- * CFI - (1 bit)
+ * Returns the CFI portion of the 802.1q header this action will insert CFI
+ * - (1 bit)
+ *
* @return
*/
public int getCfi() {
/**
* Returns the vlan PCP portion of the 802.1q header this action will insert
* PCP - (3 bits)
+ *
* @return byte[]
*/
public int getPcp() {
}
/**
- * Returns the TCI portion of the 802.1q header this action will insert
- * TCI = [PCP + CFI + VID] - (16 bits)
+ * Returns the TCI portion of the 802.1q header this action will insert TCI
+ * = [PCP + CFI + VID] - (16 bits)
+ *
* @return
*/
public int getTci() {
}
/**
- * Returns the full 802.1q header this action will insert
- * header = [TPID + TIC] (32 bits)
+ * Returns the full 802.1q header this action will insert header = [TPID +
+ * TIC] (32 bits)
*
* @return int
*/
- @XmlElement(name="VlanHeader")
+ @XmlElement(name = "VlanHeader")
public int getHeader() {
return header;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
PushVlan other = (PushVlan) obj;
- if (cfi != other.cfi)
+ if (cfi != other.cfi) {
return false;
- if (pcp != other.pcp)
+ }
+ if (pcp != other.pcp) {
return false;
- if (tag != other.tag)
+ }
+ if (tag != other.tag) {
return false;
- if (vlanId != other.vlanId)
+ }
+ if (vlanId != other.vlanId) {
return false;
+ }
return true;
}
@Override
public String toString() {
- return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi
- + ", vlanId = " + vlanId + "]";
+ return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi + ", vlanId = " + vlanId + "]";
}
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Set destination datalayer address action
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetDlDst extends Action {
+ private static final long serialVersionUID = 1L;
private byte[] address;
/* Dummy constructor for JAXB */
- private SetDlDst () {
+ @SuppressWarnings("unused")
+ private SetDlDst() {
}
public SetDlDst(byte[] dlAddress) {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetDlDst other = (SetDlDst) obj;
- if (!Arrays.equals(address, other.address))
+ if (!Arrays.equals(address, other.address)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetDlSrc extends Action {
+ private static final long serialVersionUID = 1L;
private byte[] address;
/* Dummy constructor for JAXB */
- private SetDlSrc () {
+ @SuppressWarnings("unused")
+ private SetDlSrc() {
}
public SetDlSrc(byte[] dlAddress) {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetDlSrc other = (SetDlSrc) obj;
- if (!Arrays.equals(address, other.address))
+ if (!Arrays.equals(address, other.address)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetDlType extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int dlType;
/* Dummy constructor for JAXB */
- private SetDlType () {
+ @SuppressWarnings("unused")
+ private SetDlType() {
}
public SetDlType(int dlType) {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetDlType other = (SetDlType) obj;
- if (dlType != other.dlType)
+ if (dlType != other.dlType) {
return false;
+ }
return true;
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class SetNextHop extends Action {
+ private static final long serialVersionUID = 1L;
@XmlElement
private InetAddress address;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetNwDst extends Action {
+ private static final long serialVersionUID = 1L;
InetAddress address;
/* Dummy constructor for JAXB */
- private SetNwDst () {
+ @SuppressWarnings("unused")
+ private SetNwDst() {
}
public SetNwDst(InetAddress address) {
/**
* Returns the network address this action will set
*
- * @return InetAddress
+ * @return InetAddress
*/
public InetAddress getAddress() {
return address;
}
- @XmlElement (name="address")
+ @XmlElement(name = "address")
public String getAddressAsString() {
return address.getHostAddress();
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetNwDst other = (SetNwDst) obj;
if (address == null) {
- if (other.address != null)
+ if (other.address != null) {
return false;
- } else if (!address.equals(other.address))
+ }
+ } else if (!address.equals(other.address)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetNwSrc extends Action {
+ private static final long serialVersionUID = 1L;
InetAddress address;
/* Dummy constructor for JAXB */
- private SetNwSrc () {
+ @SuppressWarnings("unused")
+ private SetNwSrc() {
}
public SetNwSrc(InetAddress address) {
/**
* Returns the network address this action will set
*
- * @return InetAddress
+ * @return InetAddress
*/
public InetAddress getAddress() {
return address;
}
- @XmlElement (name="address")
+ @XmlElement(name = "address")
public String getAddressAsString() {
return address.getHostAddress();
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetNwSrc other = (SetNwSrc) obj;
if (address == null) {
- if (other.address != null)
+ if (other.address != null) {
return false;
- } else if (!address.equals(other.address))
+ }
+ } else if (!address.equals(other.address)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetNwTos extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int tos;
/* Dummy constructor for JAXB */
- private SetNwTos () {
+ @SuppressWarnings("unused")
+ private SetNwTos() {
}
public SetNwTos(int tos) {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetNwTos other = (SetNwTos) obj;
- if (tos != other.tos)
+ if (tos != other.tos) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetTpDst extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int port;
/* Dummy constructor for JAXB */
- private SetTpDst () {
+ @SuppressWarnings("unused")
+ private SetTpDst() {
}
public SetTpDst(int port) {
/**
* Returns the transport port the action will set
+ *
* @return
*/
public int getPort() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetTpDst other = (SetTpDst) obj;
- if (port != other.port)
+ if (port != other.port) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetTpSrc extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int port;
/* Dummy constructor for JAXB */
- private SetTpSrc () {
+ @SuppressWarnings("unused")
+ private SetTpSrc() {
}
public SetTpSrc(int port) {
/**
* Returns the transport port the action will set
+ *
* @return
*/
public int getPort() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetTpSrc other = (SetTpSrc) obj;
- if (port != other.port)
+ if (port != other.port) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetVlanCfi extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int cfi;
/* Dummy constructor for JAXB */
- private SetVlanCfi () {
+ @SuppressWarnings("unused")
+ private SetVlanCfi() {
}
public SetVlanCfi(int cfi) {
/**
* Returns the 802.1q CFI value that this action will set
+ *
* @return
*/
public int getCfi() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetVlanCfi other = (SetVlanCfi) obj;
- if (cfi != other.cfi)
+ if (cfi != other.cfi) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetVlanId extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int vlanId;
- private SetVlanId() {
+ @SuppressWarnings("unused")
+ private SetVlanId() {
- }
+ }
public SetVlanId(int vlanId) {
type = ActionType.SET_VLAN_ID;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetVlanId other = (SetVlanId) obj;
- if (vlanId != other.vlanId)
+ if (vlanId != other.vlanId) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SetVlanPcp extends Action {
- @XmlElement
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private int pcp;
- private SetVlanPcp() {
+ @SuppressWarnings("unused")
+ private SetVlanPcp() {
- }
+ }
public SetVlanPcp(int pcp) {
type = ActionType.SET_VLAN_PCP;
/**
* Returns the value of the vlan PCP this action will set
+ *
* @return int
*/
public int getPcp() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SetVlanPcp other = (SetVlanPcp) obj;
- if (pcp != other.pcp)
+ if (pcp != other.pcp) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import javax.xml.bind.annotation.XmlRootElement;
/**
- * Represents the action of sending the packet to the local software path for processing
+ * Represents the action of sending the packet to the local software path for
+ * processing
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-
public class SwPath extends Action {
+ private static final long serialVersionUID = 1L;
public SwPath() {
type = ActionType.SW_PATH;
package org.opendaylight.controller.sal.core;
+import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
@XmlRootElement
public class Latency extends Property {
private static final long serialVersionUID = 1L;
- private long latency;
+
+ @XmlElement
+ private long latencyValue;
public static final long LATENCYUNK = 0;
public static final long LATENCY1ns = (long) Math.pow(10, 3);
*/
private Latency() {
super(LatencyPropName);
- this.latency = LATENCYUNK;
+ this.latencyValue = LATENCYUNK;
}
public Latency(long latency) {
super(LatencyPropName);
- this.latency = latency;
+ this.latencyValue = latency;
}
public Latency(int latency) {
super(LatencyPropName);
- this.latency = (long) latency;
+ this.latencyValue = (long) latency;
}
public Latency(short latency) {
super(LatencyPropName);
- this.latency = (long) latency;
+ this.latencyValue = (long) latency;
}
public Latency clone() {
- return new Latency(this.latency);
+ return new Latency(this.latencyValue);
}
public long getValue() {
- return this.latency;
+ return this.latencyValue;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
- result = prime * result + (int) (latency ^ (latency >>> 32));
+ result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
return result;
}
if (getClass() != obj.getClass())
return false;
Latency other = (Latency) obj;
- if (latency != other.latency)
+ if (latencyValue != other.latencyValue)
return false;
return true;
}
StringBuffer sb = new StringBuffer();
sb.append("Latency[");
- if (this.latency == 0) {
+ if (this.latencyValue == 0) {
sb.append("UnKnown");
- } else if (this.latency < LATENCY1ns) {
- sb.append(this.latency + "psec");
- } else if (this.latency < LATENCY1us) {
- sb.append(Long.toString(this.latency / LATENCY1ns) + "nsec");
- } else if (this.latency < LATENCY1ms) {
- sb.append(Long.toString(this.latency / LATENCY1us) + "usec");
- } else if (this.latency < LATENCY1s) {
- sb.append(Long.toString(this.latency / LATENCY1ms) + "msec");
+ } else if (this.latencyValue < LATENCY1ns) {
+ sb.append(this.latencyValue + "psec");
+ } else if (this.latencyValue < LATENCY1us) {
+ sb.append(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
+ } else if (this.latencyValue < LATENCY1ms) {
+ sb.append(Long.toString(this.latencyValue / LATENCY1us) + "usec");
+ } else if (this.latencyValue < LATENCY1s) {
+ sb.append(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
}
sb.append("]");
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
/**
* Represent a flow: match + actions + flow specific properties
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Flow implements Cloneable, Serializable {
- protected static final Logger logger = LoggerFactory
- .getLogger(Flow.class);
- private static final long serialVersionUID = 1L;
- @XmlElement
+ protected static final Logger logger = LoggerFactory.getLogger(Flow.class);
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private Match match;
@XmlElement
private List<Action> actions;
try {
throw new Exception("Conflicting Match and Action list");
} catch (Exception e) {
- logger.error("",e);
+ logger.error("", e);
}
} else {
this.match = match;
}
/**
- * Set the Match for this flow
- * This operation will overwrite an existing Match if present
+ * Set the Match for this flow This operation will overwrite an existing
+ * Match if present
*
* @param match
*/
/**
* Returns a copy of the actions list of this flow
+ *
* @return
*/
public List<Action> getActions() {
}
/**
- * Set the actions list for this flow
- * If a list is already present, it will be
- * replaced with the passed one. During
- * addition, only the valid actions will be added
- * It is a no op if the passed actions is null
- * An empty actions is a vlaid input
+ * Set the actions list for this flow If a list is already present, it will
+ * be replaced with the passed one. During addition, only the valid actions
+ * will be added It is a no op if the passed actions is null An empty
+ * actions is a vlaid input
*
* @param actions
*/
}
/**
- * Returns whether the Flow is for IPv4 or IPv6
- * Information is derived from match and actions list
+ * Returns whether the Flow is for IPv4 or IPv6 Information is derived from
+ * match and actions list
*
* @return
*/
}
/**
- * Returns true if it finds at least one action which is for IPv6
- * in the list of actions for this Flow
+ * Returns true if it finds at least one action which is for IPv6 in the
+ * list of actions for this Flow
*
* @return
*/
}
break;
case SET_DL_TYPE:
- if (((SetDlType) action).getDlType() == EtherTypes.IPv6
- .intValue()) {
+ if (((SetDlType) action).getDlType() == EtherTypes.IPv6.intValue()) {
return true;
}
break;
cloned.match = this.getMatch();
cloned.actions = this.getActions();
} catch (CloneNotSupportedException e) {
- logger.error("",e);
+ logger.error("", e);
}
return cloned;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Flow other = (Flow) obj;
if (actions == null) {
- if (other.actions != null)
+ if (other.actions != null) {
return false;
- } else if (!actions.equals(other.actions))
+ }
+ } else if (!actions.equals(other.actions)) {
return false;
- if (hardTimeout != other.hardTimeout)
+ }
+ if (hardTimeout != other.hardTimeout) {
return false;
- if (id != other.id)
+ }
+ if (id != other.id) {
return false;
- if (idleTimeout != other.idleTimeout)
+ }
+ if (idleTimeout != other.idleTimeout) {
return false;
+ }
if (match == null) {
- if (other.match != null)
+ if (other.match != null) {
return false;
- } else if (!match.equals(other.match))
+ }
+ } else if (!match.equals(other.match)) {
return false;
- if (priority != other.priority)
+ }
+ if (priority != other.priority) {
return false;
+ }
return true;
}
@Override
public String toString() {
- return "Flow[match = " + match + ", actions = " + actions
- + ", priority = " + priority + ", id = " + id
- + ", idleTimeout = " + idleTimeout + ", hardTimeout = "
- + hardTimeout + "]";
+ return "Flow[match = " + match + ", actions = " + actions + ", priority = " + priority + ", id = " + id
+ + ", idleTimeout = " + idleTimeout + ", hardTimeout = " + hardTimeout + "]";
}
public short getPriority() {
* Adds the specified action to the list of action of this flow
*
* @param action
- * @return false if the passed action is null or not valid or if it fails to add it
+ * @return false if the passed action is null or not valid or if it fails to
+ * add it
*/
public boolean addAction(Action action) {
if (action == null || !action.isValid()) {
}
/**
- * remove ALL actions of type actionType from the list of actions of this flow
+ * remove ALL actions of type actionType from the list of actions of this
+ * flow
*
* @param actionType
- * @return false if an action of that type is present and it fails to remove it
+ * @return false if an action of that type is present and it fails to remove
+ * it
*/
public boolean removeAction(ActionType actionType) {
Iterator<Action> actionIter = this.getActions().iterator();
while (actionIter.hasNext()) {
Action action = actionIter.next();
if (action.getType() == actionType) {
- if (!this.removeAction(action))
+ if (!this.removeAction(action)) {
return false;
+ }
}
}
return true;
* functional modules the asynchronous messages related to flow programming
* coming from the network nodes.
*/
-public interface IFlowProgrammerListener extends
- IPluginOutFlowProgrammerService {
+public interface IFlowProgrammerListener extends IPluginOutFlowProgrammerService {
}
Match cloned = null;
try {
cloned = (Match) super.clone();
+ cloned.matches = matches;
cloned.fields = new HashMap<MatchType, MatchField>();
for (Entry<MatchType, MatchField> entry : this.fields.entrySet()) {
cloned.fields.put(entry.getKey(), entry.getValue().clone());
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Match other = (Match) obj;
if (fields == null) {
- if (other.fields != null)
+ if (other.fields != null) {
return false;
- } else if (!fields.equals(other.fields))
+ }
+ } else if (!fields.equals(other.fields)) {
return false;
- if (matches != other.matches)
+ }
+ if (matches != other.matches) {
return false;
+ }
return true;
}
@XmlAccessorType(XmlAccessType.NONE)
public class MatchField implements Cloneable, Serializable {
private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory
- .getLogger(MatchField.class);
+ private static final Logger logger = LoggerFactory.getLogger(MatchField.class);
private MatchType type; // the field we want to match
private Object value; // the value of the field we want to match
private Object mask; // the value of the mask we want to match on the
- // specified field
+ // specified field
private transient boolean isValid;
// To satisfy JAXB
private boolean checkValueType() {
if (type.isCongruentType(value, mask) == false) {
- String valueClass = (value == null) ? "null" : value.getClass()
- .getSimpleName();
- String maskClass = (mask == null) ? "null" : mask.getClass()
- .getSimpleName();
- String error = "Invalid match field's value or mask types.For field: "
- + type.id()
- + " Expected:"
- + type.dataType().getSimpleName()
- + " or equivalent,"
- + " Got:(" + valueClass + "," + maskClass + ")";
+ String valueClass = (value == null) ? "null" : value.getClass().getSimpleName();
+ String maskClass = (mask == null) ? "null" : mask.getClass().getSimpleName();
+ String error = "Invalid match field's value or mask types.For field: " + type.id() + " Expected:"
+ + type.dataType().getSimpleName() + " or equivalent," + " Got:(" + valueClass + "," + maskClass
+ + ")";
throwException(error);
return false;
}
if (type.isValid(value, mask) == false) {
String maskString = (mask == null) ? "null" : ("0x" + Integer
.toHexString(Integer.parseInt(mask.toString())));
- String error = "Invalid match field's value or mask assignement.For field: "
- + type.id()
- + " Expected: "
- + type.getRange()
- + ", Got:(0x"
- + Integer.toHexString(Integer.parseInt(value.toString()))
- + "," + maskString + ")";
+ String error = "Invalid match field's value or mask assignement.For field: " + type.id() + " Expected: "
+ + type.getRange() + ", Got:(0x" + Integer.toHexString(Integer.parseInt(value.toString())) + ","
+ + maskString + ")";
throwException(error);
return false;
}
}
} catch (CloneNotSupportedException e) {
- logger.error("",e);
+ logger.error("", e);
}
return cloned;
}
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((mask == null) ? 0 : mask.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
+ return type.hashCode(value, mask);
}
@Override
if (type != other.type) {
return false;
}
- return (type.equalValues(this.value, other.value) && type.equalMasks(
- this.mask, other.mask));
+ return (type.equalValues(this.value, other.value) && type.equalMasks(this.mask, other.mask));
}
}
package org.opendaylight.controller.sal.match;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.Arrays;
* Represents the binding between the id, the value and mask type and the range
* values of the elements type that can be matched on the network
* frame/packet/message
- *
- *
- *
*/
public enum MatchType {
IN_PORT("inPort", 1 << 0, NodeConnector.class, 1, 0),
private long minValue;
private long maxValue;
- private MatchType(String id, int index, Class<?> dataType, long minValue,
- long maxValue) {
+ private MatchType(String id, int index, Class<?> dataType, long minValue, long maxValue) {
this.id = id;
this.index = index;
this.dataType = dataType;
}
public String getRange() {
- return "[0x" + Long.toHexString(minValue) + "-0x"
- + Long.toHexString(maxValue) + "]";
+ return "[0x" + Long.toHexString(minValue) + "-0x" + Long.toHexString(maxValue) + "]";
}
/**
val = ((Integer) value).intValue();
msk = (mask != null) ? ((Integer) mask).intValue() : 0;
- } else if (value.getClass() == Short.class
- || value.getClass() == short.class) {
+ } else if (value.getClass() == Short.class || value.getClass() == short.class) {
val = ((Short) value).intValue() & 0xffff;
msk = (mask != null) ? ((Short) mask).intValue() & 0xffff : 0;
- } else if (value.getClass() == Byte.class
- || value.getClass() == byte.class) {
+ } else if (value.getClass() == Byte.class || value.getClass() == byte.class) {
val = ((Byte) value).intValue() & 0xff;
msk = (mask != null) ? ((Byte) mask).intValue() & 0xff : 0;
}
byte mac[] = (byte[]) mask;
long bitmask = 0;
for (short i = 0; i < 6; i++) {
- bitmask |= (((long) mac[i] & 0xffL) << ((5 - i) * 8));
+ bitmask |= ((mac[i] & 0xffL) << ((5 - i) * 8));
}
return bitmask;
}
if (this.dataType == Integer.class || this.dataType == int.class) {
- return (mask == null) ? this.maxValue : ((Integer) mask)
- .longValue();
+ return (mask == null) ? this.maxValue : ((Integer) mask).longValue();
}
if (this.dataType == Short.class || this.dataType == short.class) {
return HexEncode.bytesToHexStringFormat((byte[]) value);
case DL_TYPE:
case DL_VLAN:
- return ((Integer) NetUtils.getUnsignedShort((Short) value))
- .toString();
+ return ((Integer) NetUtils.getUnsignedShort((Short) value)).toString();
case NW_SRC:
case NW_DST:
return ((InetAddress) value).getHostAddress();
case NW_TOS:
- return ((Integer) NetUtils.getUnsignedByte((Byte) value))
- .toString();
+ return ((Integer) NetUtils.getUnsignedByte((Byte) value)).toString();
case TP_SRC:
case TP_DST:
- return ((Integer) NetUtils.getUnsignedShort((Short) value))
- .toString();
+ return ((Integer) NetUtils.getUnsignedShort((Short) value)).toString();
default:
break;
}
return value.toString();
}
+ public int valueHashCode(Object o) {
+ if (o == null) {
+ return 0;
+ }
+ switch (this) {
+ case DL_SRC:
+ case DL_DST:
+ return NetUtils.byteArray4ToInt((byte[])o);
+ default:
+ return o.hashCode();
+ }
+ }
+
+ public int hashCode(Object v, Object m) {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + this.hashCode();
+
+ switch (this) {
+ case DL_SRC:
+ case DL_DST:
+ result = prime * result + ((v == null)? 0 : NetUtils.byteArray4ToInt((byte[])v));
+ result = prime * result + ((m == null)? 0 : NetUtils.byteArray4ToInt((byte[])m));
+ break;
+ case NW_SRC:
+ case NW_DST:
+ result = prime * result + ((v == null)? 0 : v.hashCode());
+ result = prime * result + ((m == null)? NetUtils.gethighestIP(v instanceof Inet6Address).hashCode() : m.hashCode());
+ break;
+ default:
+ result = prime * result + ((v == null)? 0 : v.hashCode());
+ result = prime * result + ((m == null)? 0 : m.hashCode());
+ }
+ return result;
+ }
public boolean equalValues(Object a, Object b) {
if (a == b) {
return true;
// Now adding the rest of the bits if any
if (extranumBits != 0) {
if (extranumBits < (NetUtils.NumBitsInAByte - extraOffsetBits)) {
- valfromnext = (byte) (data[startByteOffset + i + 1] & ((getMSBMask(extranumBits)) >> extraOffsetBits));
+ valfromnext = (byte) (data[startByteOffset + i] & ((getMSBMask(extranumBits)) >> extraOffsetBits));
bytes[i] = (byte) (valfromnext << extraOffsetBits);
} else if (extranumBits == (NetUtils.NumBitsInAByte - extraOffsetBits)) {
valfromcurr = (data[startByteOffset + i])
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.opendaylight.controller.sal.utils.NetUtils;
/**
* Class that represents the Ethernet frame objects
etherTypeClassMap.put(EtherTypes.ARP.shortValue(), ARP.class);
etherTypeClassMap.put(EtherTypes.IPv4.shortValue(), IPv4.class);
etherTypeClassMap.put(EtherTypes.LLDP.shortValue(), LLDP.class);
+ etherTypeClassMap.put(EtherTypes.VLANTAGGED.shortValue(), IEEE8021Q.class);
+ etherTypeClassMap.put(EtherTypes.OLDQINQ.shortValue(), IEEE8021Q.class);
+ etherTypeClassMap.put(EtherTypes.QINQ.shortValue(), IEEE8021Q.class);
+ etherTypeClassMap.put(EtherTypes.CISCOQINQ.shortValue(), IEEE8021Q.class);
}
private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
private static final long serialVersionUID = 1L;
return BitBufferHelper.getShort(fieldValues.get(ETHT));
}
+ public boolean isBroadcast(){
+ return NetUtils.isBroadcastMACAddr(getDestinationMACAddress());
+ }
+
+ public boolean isMulticast(){
+ return NetUtils.isMulticastMACAddr(getDestinationMACAddress());
+ }
+
/**
* Sets the destination MAC address for the current Ethernet object instance
* @param byte[] - the destinationMACAddress to set
*/
short computeChecksum(byte[] data, int start) {
int sum = 0, carry = 0, finalSum = 0;
+ int wordData;
int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte
+ rawPayload.length;
int checksumStartByte = start + getfieldOffset(CHECKSUM)
if (i == checksumStartByte) {
continue;
}
- StringBuffer sbuffer = new StringBuffer();
- sbuffer.append(String.format("%02X", data[i]));
- if (i < (data.length - 1)) {
- sbuffer.append(String.format("%02X", data[i + 1]));
- }
- sum += Integer.valueOf(sbuffer.toString(), 16);
+ wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF);
+ sum = sum + wordData;
}
carry = (sum >> 16) & 0xFF;
finalSum = (sum & 0xFFFF) + carry;
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.sal.packet;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Class that represents the IEEE 802.1Q objects
+ */
+public class IEEE8021Q extends Packet {
+ private static final String PCP = "PriorityCodePoint";
+ private static final String CFI = "CanonicalFormatIndicator";
+ private static final String VID = "VlanIdentifier";
+ private static final String ETHT = "EtherType";
+
+ private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(PCP, new ImmutablePair<Integer, Integer>(0, 3));
+ put(CFI, new ImmutablePair<Integer, Integer>(3, 1));
+ put(VID, new ImmutablePair<Integer, Integer>(4, 12));
+ put(ETHT, new ImmutablePair<Integer, Integer>(16, 16));
+ }
+ };
+ private final Map<String, byte[]> fieldValues;
+
+ /**
+ * Default constructor that creates and sets the HashMap
+ */
+ public IEEE8021Q() {
+ super();
+ fieldValues = new HashMap<String, byte[]>();
+ hdrFieldCoordMap = fieldCoordinates;
+ hdrFieldsMap = fieldValues;
+ }
+
+ /**
+ * Constructor that sets the access level for the packet and creates and
+ * sets the HashMap
+ */
+ public IEEE8021Q(boolean writeAccess) {
+ super(writeAccess);
+ fieldValues = new HashMap<String, byte[]>();
+ hdrFieldCoordMap = fieldCoordinates;
+ hdrFieldsMap = fieldValues;
+ }
+
+ @Override
+ /**
+ * Store the value read from data stream in hdrFieldMap
+ */
+ public void setHeaderField(String headerField, byte[] readValue) {
+ if (headerField.equals(ETHT)) {
+ payloadClass = Ethernet.etherTypeClassMap.get(BitBufferHelper.getShort(readValue));
+ }
+ hdrFieldsMap.put(headerField, readValue);
+ }
+
+ /**
+ * Gets the priority code point(PCP) stored
+ *
+ * @return byte - the PCP
+ */
+ public byte getPcp() {
+ return BitBufferHelper.getByte(fieldValues.get(PCP));
+ }
+
+ /**
+ * Gets the canonical format indicator(CFI) stored
+ *
+ * @return byte - the CFI
+ */
+ public byte getCfi() {
+ return BitBufferHelper.getByte(fieldValues.get(CFI));
+ }
+
+ /**
+ * Gets the VLAN identifier(VID) stored
+ *
+ * @return short - the VID
+ */
+ public short getVid() {
+ return BitBufferHelper.getShort(fieldValues.get(VID));
+ }
+
+ /**
+ * Gets the etherType stored
+ *
+ * @return short - the etherType
+ */
+ public short getEtherType() {
+ return BitBufferHelper.getShort(fieldValues.get(ETHT));
+ }
+
+ /**
+ * Sets the priority code point(PCP) for the current IEEE 802.1Q object
+ * instance
+ *
+ * @param byte - the PCP to set
+ */
+ public IEEE8021Q setPcp(byte pcp) {
+ byte[] priorityCodePoint = BitBufferHelper.toByteArray(pcp);
+ fieldValues.put(PCP, priorityCodePoint);
+ return this;
+ }
+
+ /**
+ * Sets the canonical format indicator(CFI) for the current IEEE 802.1Q
+ * object instance
+ *
+ * @param byte - the CFI to set
+ */
+ public IEEE8021Q setCfi(byte cfi) {
+ byte[] canonicalFormatIndicator = BitBufferHelper.toByteArray(cfi);
+ fieldValues.put(CFI, canonicalFormatIndicator);
+ return this;
+ }
+
+ /**
+ * Sets the VLAN identifier(VID) for the current IEEE 802.1Q instance
+ *
+ * @param short - the VID to set
+ */
+ public IEEE8021Q setVid(short vid) {
+ byte[] vlanIdentifier = BitBufferHelper.toByteArray(vid);
+ fieldValues.put(VID, vlanIdentifier);
+ return this;
+ }
+
+ /**
+ * Sets the etherType for the current IEEE 802.1Q object instance
+ *
+ * @param short - the etherType to set
+ */
+ public IEEE8021Q setEtherType(short etherType) {
+ byte[] ethType = BitBufferHelper.toByteArray(etherType);
+ fieldValues.put(ETHT, ethType);
+ return this;
+ }
+
+}
int end = start + getHeaderLen();
short checkSum = (short) 0;
int sum = 0, carry = 0, finalSum = 0;
- int parsedHex = 0;
+ int wordData;
int checksumStart = start
+ (getfieldOffset(CHECKSUM) / NetUtils.NumBitsInAByte);
if (i == checksumStart) {
continue;
}
- StringBuffer sbuffer = new StringBuffer();
- sbuffer.append(String.format("%02X", data[i]));
- if (i < (data.length - 1)) {
- sbuffer.append(String.format("%02X", data[i + 1]));
- }
-
- parsedHex = Integer.valueOf(sbuffer.toString(), 16);
- sum += parsedHex;
+ wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF);
+ sum = sum + wordData;
}
carry = (sum >> 16) & 0xFF;
finalSum = (sum & 0xFFFF) + carry;
private long byteCount;
/* Dummy constructor for JAXB */
+ @SuppressWarnings("unused")
private FlowOnNode () {
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import org.slf4j.LoggerFactory;
/**
- * Utility class containing the common utility functions needed
- * for operating on networking data structures
- *
- *
- *
+ * Utility class containing the common utility functions needed for operating on
+ * networking data structures
*/
public abstract class NetUtils {
- protected static final Logger logger = LoggerFactory
- .getLogger(NetUtils.class);
+ protected static final Logger logger = LoggerFactory.getLogger(NetUtils.class);
/**
* Constant holding the number of bits in a byte
*/
public static final int NumBitsInAByte = 8;
+ /**
+ * Constant holding the number of bytes in MAC Address
+ */
+ public static final int MACAddrLengthInBytes = 6;
+
+ /**
+ * Constant holding the number of words in MAC Address
+ */
+ public static final int MACAddrLengthInWords = 3;
+
+ /**
+ * Constant holding the broadcast MAC address
+ */
+ public static byte[] BroadcastMACAddr = {-1, -1, -1, -1, -1, -1};
+
/**
* Converts a 4 bytes array into an integer number
*
- * @param ba the 4 bytes long byte array
- * @return the integer number
+ * @param ba
+ * the 4 bytes long byte array
+ * @return the integer number
*/
public static int byteArray4ToInt(byte[] ba) {
if (ba == null || ba.length != 4) {
return 0;
}
- return (0xff & ba[0]) << 24 | (0xff & ba[1]) << 16
- | (0xff & ba[2]) << 8 | (0xff & ba[3]);
+ return (0xff & ba[0]) << 24 | (0xff & ba[1]) << 16 | (0xff & ba[2]) << 8 | (0xff & ba[3]);
}
+ /**
+ * Converts a long to 6 bytes array for mac addresses
+ * @param addr
+ * @return
+ */
+
+ public static byte[] longToByteArray6(long addr){
+ byte[] mac = new byte[6];
+ for(int i = 0; i < 6; i++){
+ mac[i] = (byte) (addr >> (i*8));
+ }
+ return mac;
+ }
+
+
/**
* Converts an integer number into a 4 bytes array
*
- * @param i the integer number
- * @return the byte array
+ * @param i
+ * the integer number
+ * @return the byte array
*/
public static byte[] intToByteArray4(int i) {
- return new byte[] { (byte) ((i >> 24) & 0xff),
- (byte) ((i >> 16) & 0xff), (byte) ((i >> 8) & 0xff),
+ return new byte[] { (byte) ((i >> 24) & 0xff), (byte) ((i >> 16) & 0xff), (byte) ((i >> 8) & 0xff),
(byte) (i & 0xff) };
}
/**
- * Converts an IP address passed as integer value into the
- * respective InetAddress object
+ * Converts an IP address passed as integer value into the respective
+ * InetAddress object
*
- * @param address the IP address in integer form
- * @return the IP address in InetAddress form
+ * @param address
+ * the IP address in integer form
+ * @return the IP address in InetAddress form
*/
public static InetAddress getInetAddress(int address) {
InetAddress ip = null;
try {
ip = InetAddress.getByAddress(NetUtils.intToByteArray4(address));
} catch (UnknownHostException e) {
- logger.error("",e);
+ logger.error("", e);
}
return ip;
}
/**
- * Return the InetAddress Network Mask given the length of the prefix bit mask.
- * The prefix bit mask indicates the contiguous leading bits that are NOT masked out.
- * Example: A prefix bit mask length of 8 will give an InetAddress Network Mask of 255.0.0.0
+ * Return the InetAddress Network Mask given the length of the prefix bit
+ * mask. The prefix bit mask indicates the contiguous leading bits that are
+ * NOT masked out. Example: A prefix bit mask length of 8 will give an
+ * InetAddress Network Mask of 255.0.0.0
*
- * @param prefixMaskLength integer representing the length of the prefix network mask
- * @param isV6 boolean representing the IP version of the returned address
+ * @param prefixMaskLength
+ * integer representing the length of the prefix network mask
+ * @param isV6
+ * boolean representing the IP version of the returned address
* @return
*/
- public static InetAddress getInetNetworkMask(int prefixMaskLength,
- boolean isV6) {
- if (prefixMaskLength < 0 || (!isV6 && prefixMaskLength > 32)
- || (isV6 && prefixMaskLength > 128)) {
+ public static InetAddress getInetNetworkMask(int prefixMaskLength, boolean isV6) {
+ if (prefixMaskLength < 0 || (!isV6 && prefixMaskLength > 32) || (isV6 && prefixMaskLength > 128)) {
return null;
}
byte v4Address[] = { 0, 0, 0, 0 };
try {
return InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
- logger.error("",e);
+ logger.error("", e);
}
return null;
}
/**
- * Returns the number of contiguous bits belonging to the subnet, that have to be masked out
- * Example: A prefix network byte mask of ff.ff.ff.00 will give a subnet mask length of 8,
- * while ff.00.00.00 will return a subnet mask length of 24.
- * If the passed prefixMask object is null, 0 is returned
+ * Returns the number of contiguous bits belonging to the subnet, that have
+ * to be masked out Example: A prefix network byte mask of ff.ff.ff.00 will
+ * give a subnet mask length of 8, while ff.00.00.00 will return a subnet
+ * mask length of 24. If the passed prefixMask object is null, 0 is returned
*
- * @param prefixMask the prefix mask as byte array
- * @return the length of the prefix network mask
+ * @param prefixMask
+ * the prefix mask as byte array
+ * @return the length of the prefix network mask
*/
public static int getSubnetMaskLength(byte[] prefixMask) {
int maskLength = 0;
}
/**
- * Returns the number of contiguous bits belonging to the subnet, that have to be masked out
- * Example: A prefix network byte mask of ff.ff.ff.00 will give a subnet mask length of 8,
- * while ff.00.00.00 will return a subnet mask length of 24
- * If the passed prefixMask object is null, 0 is returned
+ * Returns the number of contiguous bits belonging to the subnet, that have
+ * to be masked out Example: A prefix network byte mask of ff.ff.ff.00 will
+ * give a subnet mask length of 8, while ff.00.00.00 will return a subnet
+ * mask length of 24 If the passed prefixMask object is null, 0 is returned
*
- * @param prefixMask the prefix mask as InetAddress
- * @return the length of the prefix network mask
+ * @param prefixMask
+ * the prefix mask as InetAddress
+ * @return the length of the prefix network mask
*/
public static int getSubnetMaskLength(InetAddress prefixMask) {
- return (prefixMask == null) ? 0 : NetUtils
- .getSubnetMaskLength(prefixMask.getAddress());
+ return (prefixMask == null) ? 0 : NetUtils.getSubnetMaskLength(prefixMask.getAddress());
}
/**
- * Given an IP address and a prefix network mask length, it returns
- * the equivalent subnet prefix IP address
- * Example: for ip = "172.28.30.254" and maskLen = 25 it will return "172.28.30.128"
+ * Given an IP address and a prefix network mask length, it returns the
+ * equivalent subnet prefix IP address Example: for ip = "172.28.30.254" and
+ * maskLen = 25 it will return "172.28.30.128"
*
- * @param ip the IP address in InetAddress form
- * @param maskLen the length of the prefix network mask
- * @return the subnet prefix IP address in InetAddress form
+ * @param ip
+ * the IP address in InetAddress form
+ * @param maskLen
+ * the length of the prefix network mask
+ * @return the subnet prefix IP address in InetAddress form
*/
public static InetAddress getSubnetPrefix(InetAddress ip, int maskLen) {
int bytes = maskLen / 8;
}
/**
- * Checks if the test address and mask conflicts with
- * the filter address and mask
+ * Checks if the test address and mask conflicts with the filter address and
+ * mask
*
- * For example:
- * testAddress: 172.28.2.23 testMask: 255.255.255.0
- * filtAddress: 172.28.1.10 testMask: 255.255.255.0
- * conflict
+ * For example: testAddress: 172.28.2.23 testMask: 255.255.255.0
+ * filtAddress: 172.28.1.10 testMask: 255.255.255.0 conflict
*
- * testAddress: 172.28.2.23 testMask: 255.255.255.0
- * filtAddress: 172.28.1.10 testMask: 255.255.0.0
- * do not conflict
+ * testAddress: 172.28.2.23 testMask: 255.255.255.0 filtAddress: 172.28.1.10
+ * testMask: 255.255.0.0 do not conflict
*
* Null parameters are permitted
*
* @param filterMask
* @return
*/
- public static boolean inetAddressConflict(InetAddress testAddress,
- InetAddress filterAddress, InetAddress testMask,
+ public static boolean inetAddressConflict(InetAddress testAddress, InetAddress filterAddress, InetAddress testMask,
InetAddress filterMask) {
// Sanity check
if ((testAddress == null) || (filterAddress == null)) {
/**
* Returns true if the passed MAC address is all zero
*
- * @param mac the byte array representing the MAC address
- * @return true if all MAC bytes are zero
+ * @param mac
+ * the byte array representing the MAC address
+ * @return true if all MAC bytes are zero
*/
public static boolean isZeroMAC(byte[] mac) {
for (short i = 0; i < 6; i++) {
return true;
}
+ /**
+ * Returns true if the MAC address is the broadcast MAC address and false
+ * otherwise.
+ *
+ * @param MACAddress
+ * @return
+ */
+ public static boolean isBroadcastMACAddr(byte[] MACAddress) {
+ if (MACAddress.length == MACAddrLengthInBytes) {
+ for (int i = 0; i < 6; i++) {
+ if (MACAddress[i] != BroadcastMACAddr[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if the MAC address is a multicast MAC address and false
+ * otherwise. Note that this explicitly returns false for the broadcast MAC
+ * address.
+ *
+ * @param MACAddress
+ * @return
+ */
+ public static boolean isMulticastMACAddr(byte[] MACAddress) {
+ if (MACAddress.length == MACAddrLengthInBytes && !isBroadcastMACAddr(MACAddress)) {
+ if (MACAddress[0] % 2 == 1) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns true if the passed InetAddress contains all zero
*
- * @param ip the IP address to test
- * @return true if the address is all zero
+ * @param ip
+ * the IP address to test
+ * @return true if the address is all zero
*/
public static boolean isAny(InetAddress ip) {
for (byte b : ip.getAddress()) {
try {
address = InetAddress.getByName(addressString);
} catch (UnknownHostException e) {
- logger.error("",e);
+ logger.error("", e);
}
return address;
}
/**
- * Checks if the passed IP v4 address in string form is valid
- * The address may specify a mask at the end as "/MM"
+ * Checks if the passed IP v4 address in string form is valid The address
+ * may specify a mask at the end as "/MM"
*
- * @param cidr the v4 address as A.B.C.D/MM
+ * @param cidr
+ * the v4 address as A.B.C.D/MM
* @return
*/
public static boolean isIPv4AddressValid(String cidr) {
}
/**
- * Checks if the passed IP v6 address in string form is valid
- * The address may specify a mask at the end as "/MMM"
+ * Checks if the passed IP v6 address in string form is valid The address
+ * may specify a mask at the end as "/MMM"
*
- * @param cidr the v6 address as A::1/MMM
+ * @param cidr
+ * the v6 address as A::1/MMM
* @return
*/
public static boolean isIPv6AddressValid(String cidr) {
String values[] = cidr.split("/");
try {
- //when given an IP address, InetAddress.getByName validates the ip address
+ // when given an IP address, InetAddress.getByName validates the ip
+ // address
InetAddress addr = InetAddress.getByName(values[0]);
if (!(addr instanceof Inet6Address)) {
return false;
* @return
*/
public static boolean isIPAddressValid(String cidr) {
- return NetUtils.isIPv4AddressValid(cidr)
- || NetUtils.isIPv6AddressValid(cidr);
+ return NetUtils.isIPv4AddressValid(cidr) || NetUtils.isIPv6AddressValid(cidr);
}
/*
- * Following utilities are useful when you need to
- * compare or bit shift java primitive type variable
- * which are inerently signed
+ * Following utilities are useful when you need to compare or bit shift java
+ * primitive type variable which are inerently signed
*/
/**
* Returns the unsigned value of the passed byte variable
*
- * @param b the byte value
+ * @param b
+ * the byte value
* @return the int variable containing the unsigned byte value
*/
public static int getUnsignedByte(byte b) {
- return (b > 0)? (int)b : (b & 0x7F | 0x80);
+ return (b > 0) ? (int) b : (b & 0x7F | 0x80);
}
/**
* Return the unsigned value of the passed short variable
*
- * @param s the short value
+ * @param s
+ * the short value
* @return the int variable containing the unsigned short value
*/
public static int getUnsignedShort(short s) {
- return (s > 0)? (int)s : (s & 0x7FFF | 0x8000);
+ return (s > 0) ? (int) s : (s & 0x7FFF | 0x8000);
+ }
+
+ /**
+ * Returns the highest v4 or v6 InetAddress
+ *
+ * @param v6
+ * true for IPv6, false for Ipv4
+ * @return The highest IPv4 or IPv6 address
+ */
+ public static InetAddress gethighestIP(boolean v6) {
+ try {
+ return (v6) ? InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") : InetAddress
+ .getByName("255.255.255.255");
+ } catch (UnknownHostException e) {
+ return null;
+ }
}
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
@Test
public void testMatchCreation() {
Node node = NodeCreator.createOFNode(7l);
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 6, node);
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 6, node);
MatchField field = new MatchField(MatchType.IN_PORT, port);
Assert.assertTrue(field != null);
field = new MatchField(MatchType.TP_SRC, 120000);
Assert.assertFalse(field.isValid());
- byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd,
- (byte) 11, (byte) 22 };
- byte mask[] = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff };
+ byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 11, (byte) 22 };
+ byte mask[] = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
field = null;
field = new MatchField(MatchType.DL_SRC, mac, mask);
Assert.assertFalse(field.getValue() == null);
public void testMatchSetGet() {
Match x = new Match();
short val = 2346;
- NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector(val,
- NodeCreator.createOFNode(1l));
+ NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector(val, NodeCreator.createOFNode(1l));
x.setField(MatchType.IN_PORT, inPort);
- Assert.assertTrue(((NodeConnector) x.getField(MatchType.IN_PORT)
- .getValue()).equals(inPort));
- Assert
- .assertTrue((Short) ((NodeConnector) x.getField(
- MatchType.IN_PORT).getValue()).getID() == val);
+ Assert.assertTrue(((NodeConnector) x.getField(MatchType.IN_PORT).getValue()).equals(inPort));
+ Assert.assertTrue((Short) ((NodeConnector) x.getField(MatchType.IN_PORT).getValue()).getID() == val);
}
@Test
public void testMatchSetGetMAC() {
Match x = new Match();
- byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd,
- (byte) 11, (byte) 22 };
+ byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 11, (byte) 22 };
byte mac2[] = { (byte) 0xaa, (byte) 0xbb, 0, 0, 0, (byte) 0xbb };
- byte mask1[] = { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44,
- (byte) 0x55, (byte) 0x66 };
- byte mask2[] = { (byte) 0xff, (byte) 0xff, (byte) 0, (byte) 0,
- (byte) 0, (byte) 0xff };
+ byte mask1[] = { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66 };
+ byte mask2[] = { (byte) 0xff, (byte) 0xff, (byte) 0, (byte) 0, (byte) 0, (byte) 0xff };
x.setField(MatchType.DL_SRC, mac.clone(), mask1);
x.setField(MatchType.DL_DST, mac2.clone(), mask2);
- Assert.assertTrue(Arrays.equals(mac, (byte[]) x.getField(
- MatchType.DL_SRC).getValue()));
- Assert.assertFalse(Arrays.equals((byte[]) x.getField(MatchType.DL_SRC)
- .getValue(), (byte[]) x.getField(MatchType.DL_DST).getValue()));
- Assert.assertFalse(x.getField(MatchType.DL_SRC).getBitMask() == x
- .getField(MatchType.DL_DST).getBitMask());
+ Assert.assertTrue(Arrays.equals(mac, (byte[]) x.getField(MatchType.DL_SRC).getValue()));
+ Assert.assertFalse(Arrays.equals((byte[]) x.getField(MatchType.DL_SRC).getValue(),
+ (byte[]) x.getField(MatchType.DL_DST).getValue()));
+ Assert.assertFalse(x.getField(MatchType.DL_SRC).getBitMask() == x.getField(MatchType.DL_DST).getBitMask());
x.setField(new MatchField(MatchType.DL_DST, mac.clone(), mask1));
- Assert.assertTrue(Arrays.equals((byte[]) x.getField(MatchType.DL_SRC)
- .getValue(), (byte[]) x.getField(MatchType.DL_DST).getValue()));
+ Assert.assertTrue(Arrays.equals((byte[]) x.getField(MatchType.DL_SRC).getValue(),
+ (byte[]) x.getField(MatchType.DL_DST).getValue()));
}
@Test
InetAddress mask = InetAddress.getByName("255.255.0.0");
x.setField(MatchType.NW_SRC, address, mask);
- Assert.assertTrue(ip.equals(((InetAddress) x.getField(MatchType.NW_SRC)
- .getValue()).getHostAddress()));
+ Assert.assertTrue(ip.equals(((InetAddress) x.getField(MatchType.NW_SRC).getValue()).getHostAddress()));
Assert.assertTrue(x.getField(MatchType.NW_SRC).getMask().equals(mask));
}
public void testMatchSetGetEtherType() throws UnknownHostException {
Match x = new Match();
- x.setField(MatchType.DL_TYPE, EtherTypes.QINQ.shortValue(),
- (short) 0xffff);
- Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue())
- .equals(EtherTypes.QINQ.shortValue()));
- Assert
- .assertFalse(x.getField(MatchType.DL_TYPE).getValue() == EtherTypes.QINQ);
- Assert.assertFalse(x.getField(MatchType.DL_TYPE).getValue().equals(
- EtherTypes.QINQ));
-
- x.setField(MatchType.DL_TYPE, EtherTypes.LLDP.shortValue(),
- (short) 0xffff);
- Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue())
- .equals(EtherTypes.LLDP.shortValue()));
- Assert.assertFalse(x.getField(MatchType.DL_TYPE).equals(
- EtherTypes.LLDP.intValue()));
+ x.setField(MatchType.DL_TYPE, EtherTypes.QINQ.shortValue(), (short) 0xffff);
+ Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue()).equals(EtherTypes.QINQ.shortValue()));
+ Assert.assertFalse(x.getField(MatchType.DL_TYPE).getValue() == EtherTypes.QINQ);
+ Assert.assertFalse(x.getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.QINQ));
+
+ x.setField(MatchType.DL_TYPE, EtherTypes.LLDP.shortValue(), (short) 0xffff);
+ Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue()).equals(EtherTypes.LLDP.shortValue()));
+ Assert.assertFalse(x.getField(MatchType.DL_TYPE).equals(EtherTypes.LLDP.intValue()));
}
@Test
@Test
public void testMatchMask() {
Match x = new Match();
- NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector(
- (short) 6, NodeCreator.createOFNode(3l));
+ NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector((short) 6, NodeCreator.createOFNode(3l));
x.setField(MatchType.IN_PORT, inPort);
x.setField(MatchType.DL_VLAN, (short) 28, (short) 0xfff);
Assert.assertFalse(x.getMatches() == 0);
- Assert
- .assertTrue(x.getMatches() == (MatchType.IN_PORT.getIndex() | MatchType.DL_VLAN
- .getIndex()));
+ Assert.assertTrue(x.getMatches() == (MatchType.IN_PORT.getIndex() | MatchType.DL_VLAN.getIndex()));
}
@Test
public void testMatchBitMask() {
- byte mac[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 22, (byte) 12 };
- byte mask[] = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0 };
- NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector(
- (short) 4095, NodeCreator.createOFNode(7l));
+ byte mac[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 22, (byte) 12 };
+ byte mask[] = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0 };
+ NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector((short) 4095, NodeCreator.createOFNode(7l));
MatchField x = new MatchField(MatchType.IN_PORT, inPort);
Assert.assertTrue((x.getMask()) == null);
@Test
public void testNullMask() {
- byte mac[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 22, (byte) 12 };
- NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector(
- (short) 2000, NodeCreator.createOFNode(7l));
+ byte mac[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 22, (byte) 12 };
+ NodeConnector inPort = NodeConnectorCreator.createOFNodeConnector((short) 2000, NodeCreator.createOFNode(7l));
MatchField x = new MatchField(MatchType.IN_PORT, inPort);
Assert.assertTrue(x.getBitMask() == 0);
@Test
public void testEquality() throws Exception {
Node node = NodeCreator.createOFNode(7l);
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- NodeConnector port2 = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- byte srcMac2[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac2[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- InetAddress srcIP = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMask = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMaskd = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
- InetAddress srcIP2 = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP2 = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMask2 = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMaskd2 = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ NodeConnector port2 = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ byte srcMac2[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac2[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMask = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMaskd = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ InetAddress srcIP2 = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP2 = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMask2 = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMaskd2 = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
short ethertype = EtherTypes.IPv6.shortValue();
short ethertype2 = EtherTypes.IPv6.shortValue();
short vlan = (short) 27, vlan2 = (short) 27;
byte vlanPr = (byte) 3, vlanPr2 = (byte) 3;
Byte tos = 4, tos2 = 4;
- byte proto = IPProtocols.UDP.byteValue(), proto2 = IPProtocols.UDP
- .byteValue();
+ byte proto = IPProtocols.UDP.byteValue(), proto2 = IPProtocols.UDP.byteValue();
short src = (short) 5500, src2 = (short) 5500;
short dst = 80, dst2 = 80;
// Make sure all values are equals
for (MatchType type : MatchType.values()) {
if (match1.isPresent(type)) {
- Assert.assertTrue(match1.getField(type).equals(
- match2.getField(type)));
+ Assert.assertTrue(match1.getField(type).equals(match2.getField(type)));
}
}
Assert.assertTrue(match1.equals(match2));
}
+ @Test
+ public void testHashCode() throws Exception {
+ byte srcMac1[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte srcMac2[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac1[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ byte dstMac2[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ short ethertype = EtherTypes.IPv4.shortValue();
+ short ethertype2 = EtherTypes.IPv4.shortValue();
+ InetAddress srcIP1 = InetAddress.getByName("1.1.1.1");
+ InetAddress ipMask1 = InetAddress.getByName("255.255.255.255");
+ InetAddress srcIP2 = InetAddress.getByName("1.1.1.1");
+ InetAddress ipMask2 = InetAddress.getByName("255.255.255.255");
+
+ Match match1 = new Match();
+ Match match2 = new Match();
+
+ MatchField field1 = new MatchField(MatchType.DL_SRC, srcMac1);
+ MatchField field2 = new MatchField(MatchType.DL_SRC, srcMac2);
+ Assert.assertTrue(field1.hashCode() == field2.hashCode());
+
+ match1.setField(field1);
+ match2.setField(field2);
+ Assert.assertTrue(match1.hashCode() == match2.hashCode());
+
+ MatchField field3 = new MatchField(MatchType.DL_DST, dstMac1);
+ MatchField field4 = new MatchField(MatchType.DL_DST, dstMac2);
+ Assert.assertTrue(field3.hashCode() == field4.hashCode());
+
+ match1.setField(field3);
+ match2.setField(field4);
+ Assert.assertTrue(match1.hashCode() == match2.hashCode());
+
+ MatchField field5 = new MatchField(MatchType.DL_TYPE, ethertype);
+ MatchField field6 = new MatchField(MatchType.DL_TYPE, ethertype2);
+ Assert.assertTrue(field5.hashCode() == field6.hashCode());
+
+ match1.setField(field5);
+ match2.setField(field6);
+ Assert.assertTrue(match1.hashCode() == match2 .hashCode());
+
+ MatchField field7 = new MatchField(MatchType.NW_SRC, srcIP1, ipMask1);
+ MatchField field8 = new MatchField(MatchType.NW_SRC, srcIP2, ipMask2);
+ Assert.assertTrue(field7.hashCode() == field8.hashCode());
+
+ match1.setField(field7);
+ match2.setField(field8);
+ Assert.assertTrue(match1.hashCode() == match2.hashCode());
+
+ }
+
@Test
public void testCloning() throws Exception {
Node node = NodeCreator.createOFNode(7l);
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- InetAddress srcIP = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMasks = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMaskd = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMasks = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMaskd = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
short ethertype = EtherTypes.IPv6.shortValue();
short vlan = (short) 27;
byte vlanPr = (byte) 3;
for (MatchType type : MatchType.values()) {
if (match.isPresent(type)) {
if (!match.getField(type).equals(cloned.getField(type))) {
- Assert.assertTrue(match.getField(type).equals(
- cloned.getField(type)));
+ Assert.assertTrue(match.getField(type).equals(cloned.getField(type)));
}
}
}
- // Make sure none of the fields couples are pointing to the same reference
+ // Make sure none of the fields couples are pointing to the same
+ // reference
MatchField a = null, b = null;
for (MatchType type : MatchType.values()) {
a = match.getField(type);
Assert.assertTrue(match.equals(cloned));
- Assert.assertFalse(match.getField(MatchType.DL_SRC) == cloned
- .getField(MatchType.DL_SRC));
- Assert.assertFalse(match.getField(MatchType.NW_DST) == cloned
- .getField(MatchType.NW_DST));
- Assert.assertTrue(match.getField(MatchType.NW_DST).getMask().equals(
- cloned.getField(MatchType.NW_DST).getMask()));
+ Assert.assertFalse(match.getField(MatchType.DL_SRC) == cloned.getField(MatchType.DL_SRC));
+ Assert.assertFalse(match.getField(MatchType.NW_DST) == cloned.getField(MatchType.NW_DST));
+ Assert.assertTrue(match.getField(MatchType.NW_DST).getMask()
+ .equals(cloned.getField(MatchType.NW_DST).getMask()));
+ Assert.assertTrue(match.hashCode() == cloned.hashCode());
}
@Test
public void testFlip() throws Exception {
Node node = NodeCreator.createOFNode(7l);
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- InetAddress srcIP = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMasks = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMaskd = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMasks = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMaskd = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
short ethertype = EtherTypes.IPv6.shortValue();
short vlan = (short) 27;
byte vlanPr = (byte) 3;
Match flipped = match.reverse();
- Assert.assertTrue(match.getField(MatchType.DL_TYPE).equals(
- flipped.getField(MatchType.DL_TYPE)));
- Assert.assertTrue(match.getField(MatchType.DL_VLAN).equals(
- flipped.getField(MatchType.DL_VLAN)));
-
- Assert.assertTrue(match.getField(MatchType.DL_DST).getValue().equals(
- flipped.getField(MatchType.DL_SRC).getValue()));
- Assert.assertTrue(match.getField(MatchType.DL_DST).getMask() == flipped
- .getField(MatchType.DL_SRC).getMask());
-
- Assert.assertTrue(match.getField(MatchType.NW_DST).getValue().equals(
- flipped.getField(MatchType.NW_SRC).getValue()));
- Assert.assertTrue(match.getField(MatchType.NW_DST).getMask() == flipped
- .getField(MatchType.NW_SRC).getMask());
-
- Assert.assertTrue(match.getField(MatchType.TP_DST).getValue().equals(
- flipped.getField(MatchType.TP_SRC).getValue()));
- Assert.assertTrue(match.getField(MatchType.TP_DST).getMask() == flipped
- .getField(MatchType.TP_SRC).getMask());
+ Assert.assertTrue(match.getField(MatchType.DL_TYPE).equals(flipped.getField(MatchType.DL_TYPE)));
+ Assert.assertTrue(match.getField(MatchType.DL_VLAN).equals(flipped.getField(MatchType.DL_VLAN)));
+
+ Assert.assertTrue(match.getField(MatchType.DL_DST).getValue()
+ .equals(flipped.getField(MatchType.DL_SRC).getValue()));
+ Assert.assertTrue(match.getField(MatchType.DL_DST).getMask() == flipped.getField(MatchType.DL_SRC).getMask());
+
+ Assert.assertTrue(match.getField(MatchType.NW_DST).getValue()
+ .equals(flipped.getField(MatchType.NW_SRC).getValue()));
+ Assert.assertTrue(match.getField(MatchType.NW_DST).getMask() == flipped.getField(MatchType.NW_SRC).getMask());
+
+ Assert.assertTrue(match.getField(MatchType.TP_DST).getValue()
+ .equals(flipped.getField(MatchType.TP_SRC).getValue()));
+ Assert.assertTrue(match.getField(MatchType.TP_DST).getMask() == flipped.getField(MatchType.TP_SRC).getMask());
Match flipflip = flipped.reverse().reverse();
Assert.assertTrue(flipflip.equals(flipped));
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.sal.packet;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.sal.utils.NetUtils;
+
+public class IEEE8021QTest {
+
+ @Test
+ public void testGetPcp() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte pcp[] = { 5 };
+ vlan.hdrFieldsMap.put("PriorityCodePoint", pcp);
+ byte spcp = vlan.getPcp();
+ Assert.assertTrue(spcp == 5);
+ }
+
+ @Test
+ public void testGetCfi() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte cfi[] = { 0 };
+ vlan.hdrFieldsMap.put("CanonicalFormatIndicator", cfi);
+ byte scfi = vlan.getCfi();
+ Assert.assertTrue(scfi == 0);
+ }
+
+ @Test
+ public void testGetVid() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte vid[] = { (byte) 0xF, (byte) 0xFE }; // 4094
+ vlan.hdrFieldsMap.put("VlanIdentifier", vid);
+ short svid = vlan.getVid();
+ Assert.assertTrue(svid == 4094);
+ }
+
+ @Test
+ public void testGetEthertype() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte ethType[] = { 8, 6 };
+ vlan.hdrFieldsMap.put("EtherType", ethType);
+ short etherType = vlan.getEtherType();
+ Assert.assertTrue(etherType == 2054);
+ }
+
+ @Test
+ public void testSetPcp() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte pcp = 5;
+ vlan.setPcp(pcp);
+ byte[] bpcp = vlan.hdrFieldsMap.get("PriorityCodePoint");
+ Assert.assertTrue(bpcp[0] == 5);
+ }
+
+ @Test
+ public void testSetCfi() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ byte cfi = 0;
+ vlan.setCfi(cfi);
+ byte[] bcfi = vlan.hdrFieldsMap.get("CanonicalFormatIndicator");
+ Assert.assertTrue(bcfi[0] == 0);
+ }
+
+ @Test
+ public void testSetVid() throws Exception {
+ IEEE8021Q vlan = new IEEE8021Q();
+ short vid = 4094; // 0xFFE
+ vlan.setVid(vid);
+ byte[] bvid = vlan.hdrFieldsMap.get("VlanIdentifier");
+ Assert.assertTrue(bvid[0] == (byte) 0xF);
+ Assert.assertTrue(bvid[1] == (byte) 0xFE);
+ }
+
+ @Test
+ public void testSetEthertype() throws Exception {
+ Ethernet eth = new Ethernet();
+ short ethType = 2054; // 0x806
+ eth.setEtherType(ethType);
+ byte[] etherType = eth.hdrFieldsMap.get("EtherType");
+ Assert.assertTrue(etherType[0] == 8);
+ Assert.assertTrue(etherType[1] == 6);
+ }
+
+ @Test
+ public void testDeserialize() throws Exception {
+ short startOffset, numBits;
+ Ethernet eth = new Ethernet();
+ byte[] data = {
+ (byte) 0xA, (byte) 0xC, (byte) 0xE, (byte) 0x14, (byte) 0x37, (byte) 0x45, // Destination MAC
+ (byte) 0xA6, (byte) 0xEC, (byte) 0x9C, (byte) 0xAE, (byte) 0xB2, (byte) 0x9F, // Source MAC
+ (byte) 0x81, (byte) 0x00, // EtherType
+ (byte) 0xAF, (byte) 0xFE, // PCP, CFI, VLAN ID
+ 8, 6, // EtherType
+ 0, 1, // Hardware Type
+ 8, 0, // Protocol Type
+ 6, // Hardware Address Length
+ 4, // Protocol Address Length
+ 0, 1, // opCode
+ (byte) 0xA6, (byte) 0xEC, (byte) 0x9C, (byte) 0xAE, (byte) 0xB2, (byte) 0x9F, // Sender Hardware Address
+ (byte) 0x9, (byte) 0x9, (byte) 0x9, (byte) 0x1, // Sender Protocol Address
+ (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, // Target Hardware Address
+ (byte) 0x9, (byte) 0x9, (byte) 0x9, (byte) 0xFE }; // Target Protocol Address
+
+ startOffset = 0;
+ numBits = (short) (data.length * 8);
+ eth.deserialize(data, startOffset, numBits);
+
+ short etherType = eth.getEtherType();
+ Assert.assertTrue(NetUtils.getUnsignedShort(etherType) == 0x8100);
+
+ IEEE8021Q vlanPacket = (IEEE8021Q) eth.getPayload();
+ Assert.assertTrue(vlanPacket.getCfi() == 0);
+ Assert.assertTrue(vlanPacket.getPcp() == 5);
+ Assert.assertTrue(vlanPacket.getVid() == 4094);
+ Assert.assertTrue(vlanPacket.getEtherType() == 2054); // 0x806
+
+ Packet arpPkt = (vlanPacket).getPayload();
+ Assert.assertTrue(arpPkt instanceof ARP);
+ }
+
+ @Test
+ public void testSerialize() throws Exception {
+ Ethernet eth = new Ethernet();
+
+ byte[] dMac = { (byte) 0xA, (byte) 0xC, (byte) 0xE, (byte) 0x14, (byte) 0x37, (byte) 0x45 };
+ byte[] sMac = { (byte) 0xA6, (byte) 0xEC, (byte) 0x9C, (byte) 0xAE, (byte) 0xB2, (byte) 0x9F };
+ eth.setDestinationMACAddress(dMac);
+ eth.setSourceMACAddress(sMac);
+ eth.setEtherType((short) 33024);
+
+ IEEE8021Q vlan = new IEEE8021Q();
+ vlan.setCfi((byte) 0x0);
+ vlan.setPcp((byte) 0x5);
+ vlan.setVid((short) 4094);
+ vlan.setEtherType((short) 2054);
+
+ vlan.setParent(eth);
+ eth.setPayload(vlan);
+
+ ARP arp = new ARP();
+ arp.setHardwareType((short) 1);
+ arp.setProtocolType((short) 2048);
+ arp.setHardwareAddressLength((byte) 0x6);
+ arp.setProtocolAddressLength((byte) 0x4);
+ arp.setOpCode((byte) 0x1);
+
+ byte[] senderHardwareAddress = { (byte) 0xA6, (byte) 0xEC, (byte) 0x9C, (byte) 0xAE, (byte) 0xB2, (byte) 0x9F };
+ byte[] senderProtocolAddress = { (byte) 0x9, (byte) 0x9, (byte) 0x9, (byte) 0x1 };
+ byte[] targetProtocolAddress = { (byte) 0x9, (byte) 0x9, (byte) 0x9, (byte) 0xFE };
+ byte[] targetHardwareAddress = { (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0 };
+ arp.setSenderHardwareAddress(senderHardwareAddress);
+ arp.setSenderProtocolAddress(senderProtocolAddress);
+ arp.setTargetHardwareAddress(targetHardwareAddress);
+ arp.setTargetProtocolAddress(targetProtocolAddress);
+
+ arp.setParent(vlan);
+ vlan.setPayload(arp);
+
+ byte[] data = eth.serialize();
+
+ Assert.assertTrue(data[0] == (byte) 0x0A); // Destination MAC
+ Assert.assertTrue(data[1] == (byte) 0x0C);
+ Assert.assertTrue(data[2] == (byte) 0x0E);
+ Assert.assertTrue(data[3] == (byte) 0x14);
+ Assert.assertTrue(data[4] == (byte) 0x37);
+ Assert.assertTrue(data[5] == (byte) 0x45);
+ Assert.assertTrue(data[6] == (byte) 0xA6); // Source MAC
+ Assert.assertTrue(data[7] == (byte) 0xEC);
+ Assert.assertTrue(data[8] == (byte) 0x9C);
+ Assert.assertTrue(data[9] == (byte) 0xAE);
+ Assert.assertTrue(data[10] == (byte) 0xB2);
+ Assert.assertTrue(data[11] == (byte) 0x9F);
+ Assert.assertTrue(data[12] == (byte) 0x81); // EtherType
+ Assert.assertTrue(data[13] == (byte) 0x00);
+ Assert.assertTrue(data[14] == (byte) 0xAF); // PCP, CFI, VLAN ID
+ Assert.assertTrue(data[15] == (byte) 0xFE);
+ Assert.assertTrue(data[16] == (byte) 0x08); // EtherType
+ Assert.assertTrue(data[17] == (byte) 0x06);
+ Assert.assertTrue(data[18] == (byte) 0x00); // Hardware Type
+ Assert.assertTrue(data[19] == (byte) 0x01);
+ Assert.assertTrue(data[20] == (byte) 0x08); // Protocol Type
+ Assert.assertTrue(data[21] == (byte) 0x0);
+ Assert.assertTrue(data[22] == (byte) 0x6); // Hardware Address Length
+ Assert.assertTrue(data[23] == (byte) 0x4); // Protocol Address Length
+ Assert.assertTrue(data[24] == (byte) 0x0); // opCode
+ Assert.assertTrue(data[25] == (byte) 0x1); // opCode
+ Assert.assertTrue(data[26] == (byte) 0xA6); // Source MAC
+ Assert.assertTrue(data[27] == (byte) 0xEC);
+ Assert.assertTrue(data[28] == (byte) 0x9C);
+ Assert.assertTrue(data[29] == (byte) 0xAE);
+ Assert.assertTrue(data[30] == (byte) 0xB2);
+ Assert.assertTrue(data[31] == (byte) 0x9F);
+ Assert.assertTrue(data[32] == (byte) 0x09); // Sender Protocol Address
+ Assert.assertTrue(data[33] == (byte) 0x09);
+ Assert.assertTrue(data[34] == (byte) 0x09);
+ Assert.assertTrue(data[35] == (byte) 0x01); // Target Hardware Address
+ Assert.assertTrue(data[36] == (byte) 0x00);
+ Assert.assertTrue(data[37] == (byte) 0x00);
+ Assert.assertTrue(data[38] == (byte) 0x00);
+ Assert.assertTrue(data[39] == (byte) 0x00);
+ Assert.assertTrue(data[40] == (byte) 0x00);
+ Assert.assertTrue(data[41] == (byte) 0x00);
+ Assert.assertTrue(data[42] == (byte) 0x09); // Target Protocol Address
+ Assert.assertTrue(data[43] == (byte) 0x09);
+ Assert.assertTrue(data[44] == (byte) 0x09);
+ Assert.assertTrue(data[45] == (byte) 0xFE);
+ }
+}
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-generator-api</artifactId>\r
<dependencies>\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-generator-impl</artifactId>\r
<dependencies>\r
<groupId>junit</groupId>\r
<artifactId>junit</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>commons-lang</groupId>\r
+ <artifactId>commons-lang</artifactId>\r
+ <version>2.1</version>\r
+ </dependency>\r
</dependencies>\r
</project>
\ No newline at end of file
*/
package org.opendaylight.controller.sal.binding.generator.impl;
+import static org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil.*;
+import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findDataSchemaNode;
+import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findParentModule;
+
+import java.util.*;
+import java.util.concurrent.Future;
+
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
-import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
import org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl;
import org.opendaylight.controller.yang.binding.Notification;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.SchemaContextUtil;
-import java.util.*;
-import java.util.concurrent.Future;
-
-import static org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil.*;
-import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findDataSchemaNode;
-import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findParentModule;
-
public final class BindingGeneratorImpl implements BindingGenerator {
private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
@Override
public List<Type> generateTypes(final SchemaContext context) {
if (context == null) {
- throw new IllegalArgumentException("Schema Context reference "
- + "cannot be NULL!");
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
}
if (context.getModules() == null) {
- throw new IllegalStateException("Schema Context does not contain "
- + "defined modules!");
+ throw new IllegalStateException("Schema Context does not contain defined modules!");
}
final List<Type> generatedTypes = new ArrayList<>();
generatedTypes.addAll(allTypeDefinitionsToGenTypes(module));
generatedTypes.addAll(allContainersToGenTypes(module));
generatedTypes.addAll(allListsToGenTypes(module));
+ generatedTypes.addAll(allChoicesToGenTypes(module));
generatedTypes.addAll(allAugmentsToGenTypes(module));
generatedTypes.addAll(allRPCMethodsToGenType(module));
generatedTypes.addAll(allNotificationsToGenType(module));
}
@Override
- public List<Type> generateTypes(final SchemaContext context,
- final Set<Module> modules) {
+ public List<Type> generateTypes(final SchemaContext context, final Set<Module> modules) {
if (context == null) {
- throw new IllegalArgumentException("Schema Context reference "
- + "cannot be NULL!");
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
}
if (context.getModules() == null) {
- throw new IllegalStateException("Schema Context does not contain "
- + "defined modules!");
+ throw new IllegalStateException("Schema Context does not contain defined modules!");
}
if (modules == null) {
- throw new IllegalArgumentException("Sef of Modules cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
}
final List<Type> filteredGenTypes = new ArrayList<>();
generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));
generatedTypes.addAll(allContainersToGenTypes(contextModule));
generatedTypes.addAll(allListsToGenTypes(contextModule));
+ generatedTypes.addAll(allChoicesToGenTypes(contextModule));
generatedTypes.addAll(allAugmentsToGenTypes(contextModule));
generatedTypes.addAll(allRPCMethodsToGenType(contextModule));
generatedTypes.addAll(allNotificationsToGenType(contextModule));
- generatedTypes.addAll(allIdentitiesToGenTypes(contextModule,
- context));
+ generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context));
generatedTypes.addAll(allGroupingsToGenTypes(contextModule));
if (modules.contains(contextModule)) {
private List<Type> allTypeDefinitionsToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
throw new IllegalArgumentException("Module name cannot be NULL!");
}
if (module.getTypeDefinitions() == null) {
- throw new IllegalArgumentException("Type Definitions for module "
- + module.getName() + " cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions for module " + module.getName() + " cannot be NULL!");
}
- final Set<TypeDefinition<?>> typeDefinitions = module
- .getTypeDefinitions();
+ final Set<TypeDefinition<?>> typeDefinitions = module.getTypeDefinitions();
final List<Type> generatedTypes = new ArrayList<>();
for (final TypeDefinition<?> typedef : typeDefinitions) {
if (typedef != null) {
- final Type type = ((TypeProviderImpl) typeProvider)
- .generatedTypeForExtendedDefinitionType(typedef);
+ final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef);
if ((type != null) && !generatedTypes.contains(type)) {
generatedTypes.add(type);
}
private List<Type> allContainersToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of Child "
- + "Nodes in module " + module.getName() + " cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
+ + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
private List<Type> allListsToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of Child "
- + "Nodes in module " + module.getName() + " cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
+ + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
return generatedTypes;
}
- private List<Type> allAugmentsToGenTypes(final Module module) {
+ private List<GeneratedType> allChoicesToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
-
if (module.getName() == null) {
throw new IllegalArgumentException("Module name cannot be NULL!");
}
+ final DataNodeIterator it = new DataNodeIterator(module);
+ final List<ChoiceNode> choiceNodes = it.allChoices();
+ final String basePackageName = moduleNamespaceToPackageName(module);
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ for (final ChoiceNode choice : choiceNodes) {
+ if (choice != null) {
+ generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice));
+ }
+ }
+ return generatedTypes;
+ }
+
+ private List<Type> allAugmentsToGenTypes(final Module module) {
+ if (module == null) {
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
+ }
+ if (module.getName() == null) {
+ throw new IllegalArgumentException("Module name cannot be NULL!");
+ }
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "Augmentation Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of Augmentation Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
final String basePackageName = moduleNamespaceToPackageName(module);
final List<AugmentationSchema> augmentations = resolveAugmentations(module);
for (final AugmentationSchema augment : augmentations) {
- generatedTypes.addAll(augmentationToGenTypes(basePackageName,
- augment));
+ generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment));
}
return generatedTypes;
}
private List<AugmentationSchema> resolveAugmentations(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getAugmentations() == null) {
throw new IllegalStateException("Augmentations Set cannot be NULL!");
}
final Set<AugmentationSchema> augmentations = module.getAugmentations();
- final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(
- augmentations);
- Collections.sort(sortedAugmentations,
- new Comparator<AugmentationSchema>() {
-
- @Override
- public int compare(AugmentationSchema augSchema1,
- AugmentationSchema augSchema2) {
-
- if (augSchema1.getTargetPath().getPath().size() > augSchema2
- .getTargetPath().getPath().size()) {
- return 1;
- } else if (augSchema1.getTargetPath().getPath().size() < augSchema2
- .getTargetPath().getPath().size()) {
- return -1;
- }
- return 0;
+ final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations);
+ Collections.sort(sortedAugmentations, new Comparator<AugmentationSchema>() {
- }
- });
+ @Override
+ public int compare(AugmentationSchema augSchema1, AugmentationSchema augSchema2) {
+
+ if (augSchema1.getTargetPath().getPath().size() > augSchema2.getTargetPath().getPath().size()) {
+ return 1;
+ } else if (augSchema1.getTargetPath().getPath().size() < augSchema2.getTargetPath().getPath().size()) {
+ return -1;
+ }
+ return 0;
+
+ }
+ });
return sortedAugmentations;
}
private GeneratedType moduleToDataType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
- final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(
- module, "Data");
+ final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
final String basePackageName = moduleNamespaceToPackageName(module);
if (moduleDataTypeBuilder != null) {
final Set<DataSchemaNode> dataNodes = module.getChildNodes();
- resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder,
- dataNodes);
+ resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes);
}
return moduleDataTypeBuilder.toInstance();
}
private List<Type> allRPCMethodsToGenType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "RPC Method Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of RPC Method Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final String basePackageName = moduleNamespaceToPackageName(module);
final Set<RpcDefinition> rpcDefinitions = module.getRpcs();
final List<Type> genRPCTypes = new ArrayList<>();
- final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module,
- "Service");
+ final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module, "Service");
final Type future = Types.typeForClass(Future.class);
for (final RpcDefinition rpc : rpcDefinitions) {
if (rpc != null) {
- String rpcName = parseToClassName(rpc.getQName()
- .getLocalName());
- MethodSignatureBuilder method = interfaceBuilder
- .addMethod(rpcName);
+ String rpcName = parseToClassName(rpc.getQName().getLocalName());
+ MethodSignatureBuilder method = interfaceBuilder.addMethod(rpcName);
final List<DataNodeIterator> rpcInOut = new ArrayList<>();
if (input != null) {
rpcInOut.add(new DataNodeIterator(input));
- GeneratedTypeBuilder inType = addRawInterfaceDefinition(
- basePackageName, input, rpcName);
+ GeneratedTypeBuilder inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
resolveDataSchemaNodes(basePackageName, inType, input.getChildNodes());
Type inTypeInstance = inType.toInstance();
genRPCTypes.add(inTypeInstance);
if (output != null) {
rpcInOut.add(new DataNodeIterator(output));
- GeneratedTypeBuilder outType = addRawInterfaceDefinition(
- basePackageName, output, rpcName);
+ GeneratedTypeBuilder outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
resolveDataSchemaNodes(basePackageName, outType, output.getChildNodes());
outTypeInstance = outType.toInstance();
genRPCTypes.add(outTypeInstance);
}
- final Type rpcRes = Types.parameterizedTypeFor(
- Types.typeForClass(RpcResult.class), outTypeInstance);
- method.addReturnType(Types.parameterizedTypeFor(future, rpcRes));
+ final Type rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult.class), outTypeInstance);
+ method.setReturnType(Types.parameterizedTypeFor(future, rpcRes));
for (DataNodeIterator it : rpcInOut) {
List<ContainerSchemaNode> nContainers = it.allContainers();
if ((nContainers != null) && !nContainers.isEmpty()) {
for (final ContainerSchemaNode container : nContainers) {
- genRPCTypes.add(containerToGenType(basePackageName,
- container));
+ genRPCTypes.add(containerToGenType(basePackageName, container));
}
}
List<ListSchemaNode> nLists = it.allLists();
if ((nLists != null) && !nLists.isEmpty()) {
for (final ListSchemaNode list : nLists) {
- genRPCTypes.addAll(listToGenType(basePackageName,
- list));
+ genRPCTypes.addAll(listToGenType(basePackageName, list));
}
}
}
private List<Type> allNotificationsToGenType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "Notification Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of Notification Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final String basePackageName = moduleNamespaceToPackageName(module);
final List<Type> genNotifyTypes = new ArrayList<>();
- final Set<NotificationDefinition> notifications = module
- .getNotifications();
+ final Set<NotificationDefinition> notifications = module.getNotifications();
for (final NotificationDefinition notification : notifications) {
if (notification != null) {
// Containers
for (ContainerSchemaNode node : it.allContainers()) {
- genNotifyTypes
- .add(containerToGenType(basePackageName, node));
+ genNotifyTypes.add(containerToGenType(basePackageName, node));
}
// Lists
for (ListSchemaNode node : it.allLists()) {
genNotifyTypes.addAll(listToGenType(basePackageName, node));
}
- final GeneratedTypeBuilder notificationTypeBuilder = addRawInterfaceDefinition(
- basePackageName, notification);
- notificationTypeBuilder.addImplementsType(Types
- .typeForClass(Notification.class));
+ final GeneratedTypeBuilder notificationTypeBuilder = addDefaultInterfaceDefinition(basePackageName,
+ notification);
+ notificationTypeBuilder.addImplementsType(Types.typeForClass(Notification.class));
// Notification object
- resolveDataSchemaNodes(basePackageName,
- notificationTypeBuilder, notification.getChildNodes());
+ resolveDataSchemaNodes(basePackageName, notificationTypeBuilder, notification.getChildNodes());
genNotifyTypes.add(notificationTypeBuilder.toInstance());
}
}
return genNotifyTypes;
}
- private List<Type> allIdentitiesToGenTypes(final Module module,
- final SchemaContext context) {
- List<Type> genTypes = new ArrayList<Type>();
+ private List<Type> allIdentitiesToGenTypes(final Module module, final SchemaContext context) {
+ List<Type> genTypes = new ArrayList<>();
final Set<IdentitySchemaNode> schemaIdentities = module.getIdentities();
if (schemaIdentities != null && !schemaIdentities.isEmpty()) {
for (final IdentitySchemaNode identity : schemaIdentities) {
- genTypes.add(identityToGenType(basePackageName, identity,
- context));
+ genTypes.add(identityToGenType(basePackageName, identity, context));
}
}
return genTypes;
}
- private GeneratedType identityToGenType(final String basePackageName,
- IdentitySchemaNode identity, SchemaContext context) {
+ private GeneratedType identityToGenType(final String basePackageName, final IdentitySchemaNode identity,
+ final SchemaContext context) {
if (identity == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- identity.getPath());
-
- final String genTypeName = parseToClassName(identity.getQName()
- .getLocalName());
- final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(
- packageName, genTypeName);
+ final String packageName = packageNameForGeneratedType(basePackageName, identity.getPath());
+ final String genTypeName = parseToClassName(identity.getQName().getLocalName());
+ final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
IdentitySchemaNode baseIdentity = identity.getBaseIdentity();
if (baseIdentity != null) {
- Module baseIdentityParentModule = SchemaContextUtil.findParentModule(
- context, baseIdentity);
+ Module baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
final String returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
- final String returnTypeName = parseToClassName(baseIdentity
- .getQName().getLocalName());
+ final String returnTypeName = parseToClassName(baseIdentity.getQName().getLocalName());
- GeneratedTransferObject gto = new GeneratedTOBuilderImpl(
- returnTypePkgName, returnTypeName).toInstance();
- newType.addExtendsType(gto);
+ GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
+ newType.setExtendsType(gto);
} else {
- newType.addExtendsType(Types.getBaseIdentityTO());
+ newType.setExtendsType(Types.getBaseIdentityTO());
}
-
- return newType.toIdentityInstance();
+ newType.setAbstract(true);
+ return newType.toInstance();
}
- private List<Type> allGroupingsToGenTypes(Module module) {
- final List<Type> genTypes = new ArrayList<Type>();
+ private List<Type> allGroupingsToGenTypes(final Module module) {
+ final List<Type> genTypes = new ArrayList<>();
final String basePackageName = moduleNamespaceToPackageName(module);
- Set<GroupingDefinition> groupings = module.getGroupings();
+ final Set<GroupingDefinition> groupings = module.getGroupings();
if (groupings != null && !groupings.isEmpty()) {
for (final GroupingDefinition grouping : groupings) {
genTypes.add(groupingToGenType(basePackageName, grouping));
return genTypes;
}
- private GeneratedType groupingToGenType(final String basePackageName,
- GroupingDefinition grouping) {
+ private GeneratedType groupingToGenType(final String basePackageName, GroupingDefinition grouping) {
if (grouping == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- grouping.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, grouping.getPath());
final Set<DataSchemaNode> schemaNodes = grouping.getChildNodes();
- final GeneratedTypeBuilder typeBuilder = addRawInterfaceDefinition(
- packageName, grouping);
+ final GeneratedTypeBuilder typeBuilder = addDefaultInterfaceDefinition(packageName, grouping);
resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
return typeBuilder.toInstance();
}
- private EnumTypeDefinition enumTypeDefFromExtendedType(
- final TypeDefinition<?> typeDefinition) {
+ private EnumTypeDefinition enumTypeDefFromExtendedType(final TypeDefinition<?> typeDefinition) {
if (typeDefinition != null) {
if (typeDefinition.getBaseType() instanceof EnumTypeDefinition) {
return (EnumTypeDefinition) typeDefinition.getBaseType();
return null;
}
- private EnumBuilder resolveInnerEnumFromTypeDefinition(
- final EnumTypeDefinition enumTypeDef, final String enumName,
+ private EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final String enumName,
final GeneratedTypeBuilder typeBuilder) {
- if ((enumTypeDef != null) && (typeBuilder != null)
- && (enumTypeDef.getQName() != null)
+ if ((enumTypeDef != null) && (typeBuilder != null) && (enumTypeDef.getQName() != null)
&& (enumTypeDef.getQName().getLocalName() != null)) {
final String enumerationName = parseToClassName(enumName);
- final EnumBuilder enumBuilder = typeBuilder
- .addEnumeration(enumerationName);
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);
if (enumBuilder != null) {
final List<EnumPair> enums = enumTypeDef.getValues();
int listIndex = 0;
for (final EnumPair enumPair : enums) {
if (enumPair != null) {
- final String enumPairName = parseToClassName(enumPair
- .getName());
+ final String enumPairName = parseToClassName(enumPair.getName());
Integer enumPairValue = enumPair.getValue();
if (enumPairValue == null) {
return null;
}
- private GeneratedTypeBuilder moduleTypeBuilder(final Module module,
- final String postfix) {
+ private GeneratedTypeBuilder moduleTypeBuilder(final Module module, final String postfix) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
String packageName = moduleNamespaceToPackageName(module);
final String moduleName = parseToClassName(module.getName()) + postfix;
}
- private List<Type> augmentationToGenTypes(final String augmentPackageName,
- final AugmentationSchema augSchema) {
+ private List<Type> augmentationToGenTypes(final String augmentPackageName, final AugmentationSchema augSchema) {
if (augmentPackageName == null) {
throw new IllegalArgumentException("Package Name cannot be NULL!");
}
if (augSchema == null) {
- throw new IllegalArgumentException(
- "Augmentation Schema cannot be NULL!");
+ throw new IllegalArgumentException("Augmentation Schema cannot be NULL!");
}
if (augSchema.getTargetPath() == null) {
- throw new IllegalStateException(
- "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+ throw new IllegalStateException("Augmentation Schema does not contain Target Path (Target Path is NULL).");
}
final List<Type> genTypes = new ArrayList<>();
// EVERY augmented interface will extends Augmentation<T> interface
// and DataObject interface!!!
final SchemaPath targetPath = augSchema.getTargetPath();
- final DataSchemaNode targetSchemaNode = findDataSchemaNode(
- schemaContext, targetPath);
+ final DataSchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
if ((targetSchemaNode != null) && (targetSchemaNode.getQName() != null)
&& (targetSchemaNode.getQName().getLocalName() != null)) {
- final Module targetModule = findParentModule(schemaContext,
- targetSchemaNode);
-
+ final Module targetModule = findParentModule(schemaContext, targetSchemaNode);
final String targetBasePackage = moduleNamespaceToPackageName(targetModule);
- final String targetPackageName = packageNameForGeneratedType(
- targetBasePackage, targetSchemaNode.getPath());
-
- final String targetSchemaNodeName = targetSchemaNode.getQName()
- .getLocalName();
+ final String targetPackageName = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());
+ final String targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();
final Set<DataSchemaNode> augChildNodes = augSchema.getChildNodes();
- final GeneratedTypeBuilder augTypeBuilder = addRawAugmentGenTypeDefinition(
- augmentPackageName, targetPackageName,
- targetSchemaNodeName, augSchema);
- if (augTypeBuilder != null) {
- genTypes.add(augTypeBuilder.toInstance());
+
+ if (!(targetSchemaNode instanceof ChoiceNode)) {
+ final GeneratedTypeBuilder augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName,
+ targetPackageName, targetSchemaNodeName, augSchema);
+ final GeneratedType augType = augTypeBuilder.toInstance();
+ genTypes.add(augType);
+ } else {
+ final Type refChoiceType = new ReferencedTypeImpl(targetPackageName,
+ parseToClassName(targetSchemaNodeName));
+ final ChoiceNode choiceTarget = (ChoiceNode) targetSchemaNode;
+ final Set<ChoiceCaseNode> choiceCaseNodes = choiceTarget.getCases();
+ genTypes.addAll(augmentCasesToGenTypes(augmentPackageName, refChoiceType, choiceCaseNodes));
}
- genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName,
- augChildNodes));
+ genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes));
+ }
+ return genTypes;
+ }
+ private List<GeneratedType> augmentCasesToGenTypes(final String augmentPackageName, final Type refChoiceType,
+ final Set<ChoiceCaseNode> choiceCaseNodes) {
+ if (augmentPackageName == null) {
+ throw new IllegalArgumentException("Augment Package Name string cannot be NULL!");
+ }
+ if (choiceCaseNodes == null) {
+ throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
}
+ final List<GeneratedType> genTypes = generateTypesFromAugmentedChoiceCases(augmentPackageName, refChoiceType,
+ choiceCaseNodes);
return genTypes;
}
- private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(
- final String augmentPackageName, final String targetPackageName,
- final String targetSchemaNodeName,
- final AugmentationSchema augSchema) {
+ private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(final String augmentPackageName,
+ final String targetPackageName, final String targetSchemaNodeName, final AugmentationSchema augSchema) {
final String targetTypeName = parseToClassName(targetSchemaNodeName);
- Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders
- .get(augmentPackageName);
+ Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
if (augmentBuilders == null) {
augmentBuilders = new HashMap<>();
genTypeBuilders.put(augmentPackageName, augmentBuilders);
}
- final String augTypeName = augGenTypeName(augmentBuilders,
- targetTypeName);
- final Type targetTypeRef = new ReferencedTypeImpl(targetPackageName,
- targetTypeName);
+ final String augTypeName = augGenTypeName(augmentBuilders, targetTypeName);
+ final Type targetTypeRef = new ReferencedTypeImpl(targetPackageName, targetTypeName);
final Set<DataSchemaNode> augChildNodes = augSchema.getChildNodes();
- final GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(
- augmentPackageName, augTypeName);
+ final GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
augTypeBuilder.addImplementsType(Types.DATA_OBJECT);
- augTypeBuilder.addImplementsType(Types
- .augmentationTypeFor(targetTypeRef));
+ augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
- augSchemaNodeToMethods(augmentPackageName, augTypeBuilder,
- augChildNodes);
+ augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes);
augmentBuilders.put(augTypeName, augTypeBuilder);
return augTypeBuilder;
}
- private List<Type> augmentationBodyToGenTypes(
- final String augBasePackageName,
+ private List<Type> augmentationBodyToGenTypes(final String augBasePackageName,
final Set<DataSchemaNode> augChildNodes) {
final List<Type> genTypes = new ArrayList<>();
final List<DataNodeIterator> augSchemaIts = new ArrayList<>();
for (final DataSchemaNode childNode : augChildNodes) {
if (childNode instanceof DataNodeContainer) {
- augSchemaIts.add(new DataNodeIterator(
- (DataNodeContainer) childNode));
+ augSchemaIts.add(new DataNodeIterator((DataNodeContainer) childNode));
if (childNode instanceof ContainerSchemaNode) {
- genTypes.add(containerToGenType(augBasePackageName,
- (ContainerSchemaNode) childNode));
+ genTypes.add(containerToGenType(augBasePackageName, (ContainerSchemaNode) childNode));
} else if (childNode instanceof ListSchemaNode) {
- genTypes.addAll(listToGenType(augBasePackageName,
- (ListSchemaNode) childNode));
+ genTypes.addAll(listToGenType(augBasePackageName, (ListSchemaNode) childNode));
}
+ } else if (childNode instanceof ChoiceNode) {
+ final ChoiceNode choice = (ChoiceNode) childNode;
+ for (final ChoiceCaseNode caseNode : choice.getCases()) {
+ augSchemaIts.add(new DataNodeIterator(caseNode));
+ }
+ genTypes.addAll(choiceToGeneratedType(augBasePackageName, (ChoiceNode) childNode));
}
}
for (final DataNodeIterator it : augSchemaIts) {
final List<ContainerSchemaNode> augContainers = it.allContainers();
final List<ListSchemaNode> augLists = it.allLists();
+ final List<ChoiceNode> augChoices = it.allChoices();
- if ((augContainers != null) && !augContainers.isEmpty()) {
+ if (augContainers != null) {
for (final ContainerSchemaNode container : augContainers) {
- genTypes.add(containerToGenType(augBasePackageName,
- container));
+ genTypes.add(containerToGenType(augBasePackageName, container));
}
}
- if ((augLists != null) && !augLists.isEmpty()) {
+ if (augLists != null) {
for (final ListSchemaNode list : augLists) {
genTypes.addAll(listToGenType(augBasePackageName, list));
}
}
+ if (augChoices != null) {
+ for (final ChoiceNode choice : augChoices) {
+ genTypes.addAll(choiceToGeneratedType(augBasePackageName, choice));
+ }
+ }
}
return genTypes;
}
- private String augGenTypeName(
- final Map<String, GeneratedTypeBuilder> builders,
- final String genTypeName) {
+ private String augGenTypeName(final Map<String, GeneratedTypeBuilder> builders, final String genTypeName) {
String augTypeName = genTypeName;
int index = 1;
return augTypeName;
}
- private GeneratedType containerToGenType(final String basePackageName,
- ContainerSchemaNode containerNode) {
+ private GeneratedType containerToGenType(final String basePackageName, ContainerSchemaNode containerNode) {
if (containerNode == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- containerNode.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, containerNode.getPath());
final Set<DataSchemaNode> schemaNodes = containerNode.getChildNodes();
- final GeneratedTypeBuilder typeBuilder = addRawInterfaceDefinition(
- packageName, containerNode);
+ final GeneratedTypeBuilder typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode);
resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
return typeBuilder.toInstance();
}
- private GeneratedTypeBuilder resolveDataSchemaNodes(
- final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
- final Set<DataSchemaNode> schemaNodes) {
-
+ private GeneratedTypeBuilder resolveDataSchemaNodes(final String basePackageName,
+ final GeneratedTypeBuilder typeBuilder, final Set<DataSchemaNode> schemaNodes) {
if ((schemaNodes != null) && (typeBuilder != null)) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (schemaNode.isAugmenting()) {
continue;
}
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode,
- typeBuilder);
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
}
}
return typeBuilder;
}
- private GeneratedTypeBuilder augSchemaNodeToMethods(
- final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
- final Set<DataSchemaNode> schemaNodes) {
-
+ private GeneratedTypeBuilder augSchemaNodeToMethods(final String basePackageName,
+ final GeneratedTypeBuilder typeBuilder, final Set<DataSchemaNode> schemaNodes) {
if ((schemaNodes != null) && (typeBuilder != null)) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (schemaNode.isAugmenting()) {
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode,
- typeBuilder);
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
}
}
}
return typeBuilder;
}
- private void addSchemaNodeToBuilderAsMethod(final String basePackageName,
- final DataSchemaNode schemaNode,
+ private void addSchemaNodeToBuilderAsMethod(final String basePackageName, final DataSchemaNode schemaNode,
final GeneratedTypeBuilder typeBuilder) {
if (schemaNode != null && typeBuilder != null) {
if (schemaNode instanceof LeafSchemaNode) {
- resolveLeafSchemaNodeAsMethod(typeBuilder,
- (LeafSchemaNode) schemaNode);
+ resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) schemaNode);
} else if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder,
- (LeafListSchemaNode) schemaNode);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
} else if (schemaNode instanceof ContainerSchemaNode) {
- resolveContainerSchemaNode(basePackageName, typeBuilder,
- (ContainerSchemaNode) schemaNode);
+ resolveContainerSchemaNode(basePackageName, typeBuilder, (ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
- resolveListSchemaNode(basePackageName, typeBuilder,
- (ListSchemaNode) schemaNode);
+ resolveListSchemaNode(basePackageName, typeBuilder, (ListSchemaNode) schemaNode);
+ } else if (schemaNode instanceof ChoiceNode) {
+ resolveChoiceSchemaNode(basePackageName, typeBuilder, (ChoiceNode) schemaNode);
}
}
}
- private boolean resolveLeafSchemaNodeAsMethod(
- final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) {
+ private void resolveChoiceSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
+ final ChoiceNode choiceNode) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (typeBuilder == null) {
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
+ }
+ if (choiceNode == null) {
+ throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
+ }
+
+ final String choiceName = choiceNode.getQName().getLocalName();
+ if (choiceName != null) {
+ final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
+ final GeneratedTypeBuilder choiceType = addDefaultInterfaceDefinition(packageName, choiceNode);
+ constructGetter(typeBuilder, choiceName, choiceNode.getDescription(), choiceType);
+ }
+ }
+
+ private List<GeneratedType> choiceToGeneratedType(final String basePackageName, final ChoiceNode choiceNode) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (choiceNode == null) {
+ throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
+ }
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
+ final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
+ choiceTypeBuilder.addImplementsType(Types.DATA_OBJECT);
+ final GeneratedType choiceType = choiceTypeBuilder.toInstance();
+
+ generatedTypes.add(choiceType);
+ final Set<ChoiceCaseNode> caseNodes = choiceNode.getCases();
+ if ((caseNodes != null) && !caseNodes.isEmpty()) {
+ generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes));
+ }
+ return generatedTypes;
+ }
+
+ private List<GeneratedType> generateTypesFromChoiceCases(final String basePackageName, final Type refChoiceType,
+ final Set<ChoiceCaseNode> caseNodes) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (refChoiceType == null) {
+ throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!");
+ }
+ if (caseNodes == null) {
+ throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
+ }
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ for (final ChoiceCaseNode caseNode : caseNodes) {
+ if (caseNode != null && !caseNode.isAddedByUses()) {
+ final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath());
+ final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
+ caseTypeBuilder.addImplementsType(refChoiceType);
+
+ final Set<DataSchemaNode> childNodes = caseNode.getChildNodes();
+ if (childNodes != null) {
+ resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
+ }
+ generatedTypes.add(caseTypeBuilder.toInstance());
+ }
+ }
+
+ return generatedTypes;
+ }
+
+ private List<GeneratedType> generateTypesFromAugmentedChoiceCases(final String basePackageName,
+ final Type refChoiceType, final Set<ChoiceCaseNode> caseNodes) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (refChoiceType == null) {
+ throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!");
+ }
+ if (caseNodes == null) {
+ throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
+ }
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ for (final ChoiceCaseNode caseNode : caseNodes) {
+ if (caseNode != null && caseNode.isAugmenting()) {
+ final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath());
+ final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
+ caseTypeBuilder.addImplementsType(refChoiceType);
+
+ final Set<DataSchemaNode> childNodes = caseNode.getChildNodes();
+ if (childNodes != null) {
+ resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
+ }
+ generatedTypes.add(caseTypeBuilder.toInstance());
+ }
+ }
+
+ return generatedTypes;
+ }
+
+ private boolean resolveLeafSchemaNodeAsMethod(final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) {
if ((leaf != null) && (typeBuilder != null)) {
final String leafName = leaf.getQName().getLocalName();
String leafDesc = leaf.getDescription();
Type returnType = null;
if (!(typeDef instanceof EnumTypeDefinition)) {
- returnType = typeProvider
- .javaTypeForSchemaDefinitionType(typeDef);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);
} else {
final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef);
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(
- enumTypeDef, leafName, typeBuilder);
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName,
+ typeBuilder);
if (enumBuilder != null) {
- returnType = new ReferencedTypeImpl(
- enumBuilder.getPackageName(),
- enumBuilder.getName());
+ returnType = new ReferencedTypeImpl(enumBuilder.getPackageName(), enumBuilder.getName());
}
- ((TypeProviderImpl) typeProvider).putReferencedType(
- leaf.getPath(), returnType);
+ ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
}
if (returnType != null) {
constructGetter(typeBuilder, leafName, leafDesc, returnType);
if (!leaf.isConfiguration()) {
- constructSetter(typeBuilder, leafName, leafDesc,
- returnType);
+ constructSetter(typeBuilder, leafName, leafDesc, returnType);
}
return true;
}
return false;
}
- private boolean resolveLeafSchemaNodeAsProperty(
- final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
+ private boolean resolveLeafSchemaNodeAsProperty(final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
boolean isReadOnly) {
if ((leaf != null) && (toBuilder != null)) {
final String leafName = leaf.getQName().getLocalName();
final TypeDefinition<?> typeDef = leaf.getType();
// TODO: properly resolve enum types
- final Type returnType = typeProvider
- .javaTypeForSchemaDefinitionType(typeDef);
+ final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);
if (returnType != null) {
- final GeneratedPropertyBuilder propBuilder = toBuilder
- .addProperty(parseToClassName(leafName));
+ final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(parseToClassName(leafName));
propBuilder.setReadOnly(isReadOnly);
- propBuilder.addReturnType(returnType);
- propBuilder.addComment(leafDesc);
+ propBuilder.setReturnType(returnType);
+ propBuilder.setComment(leafDesc);
toBuilder.addEqualsIdentity(propBuilder);
toBuilder.addHashIdentity(propBuilder);
return false;
}
- private boolean resolveLeafListSchemaNode(
- final GeneratedTypeBuilder typeBuilder,
- final LeafListSchemaNode node) {
+ private boolean resolveLeafListSchemaNode(final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node) {
if ((node != null) && (typeBuilder != null)) {
final String nodeName = node.getQName().getLocalName();
String nodeDesc = node.getDescription();
if (nodeName != null) {
final TypeDefinition<?> type = node.getType();
- final Type listType = Types.listTypeFor(typeProvider
- .javaTypeForSchemaDefinitionType(type));
+ final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type));
constructGetter(typeBuilder, nodeName, nodeDesc, listType);
if (!node.isConfiguration()) {
return false;
}
- private boolean resolveContainerSchemaNode(final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
+ private boolean resolveContainerSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
final ContainerSchemaNode containerNode) {
if ((containerNode != null) && (typeBuilder != null)) {
final String nodeName = containerNode.getQName().getLocalName();
if (nodeName != null) {
- final String packageName = packageNameForGeneratedType(
- basePackageName, containerNode.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, containerNode.getPath());
- final GeneratedTypeBuilder rawGenType = addRawInterfaceDefinition(
- packageName, containerNode);
- constructGetter(typeBuilder, nodeName, "", rawGenType);
+ final GeneratedTypeBuilder rawGenType = addDefaultInterfaceDefinition(packageName, containerNode);
+ constructGetter(typeBuilder, nodeName, containerNode.getDescription(), rawGenType);
return true;
}
return false;
}
- private boolean resolveListSchemaNode(final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
+ private boolean resolveListSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
final ListSchemaNode schemaNode) {
if ((schemaNode != null) && (typeBuilder != null)) {
final String listName = schemaNode.getQName().getLocalName();
if (listName != null) {
- final String packageName = packageNameForGeneratedType(
- basePackageName, schemaNode.getPath());
- final GeneratedTypeBuilder rawGenType = addRawInterfaceDefinition(
- packageName, schemaNode);
- constructGetter(typeBuilder, listName, "",
- Types.listTypeFor(rawGenType));
+ final String packageName = packageNameForGeneratedType(basePackageName, schemaNode.getPath());
+ final GeneratedTypeBuilder rawGenType = addDefaultInterfaceDefinition(packageName, schemaNode);
+ constructGetter(typeBuilder, listName, schemaNode.getDescription(), Types.listTypeFor(rawGenType));
if (!schemaNode.isConfiguration()) {
- constructSetter(typeBuilder, listName, "",
- Types.listTypeFor(rawGenType));
+ constructSetter(typeBuilder, listName, schemaNode.getDescription(), Types.listTypeFor(rawGenType));
}
return true;
}
return false;
}
- private GeneratedTypeBuilder addRawInterfaceDefinition(
- final String packageName, final SchemaNode schemaNode) {
+ /**
+ * Method instantiates new Generated Type Builder and sets the implements
+ * definitions of Data Object and Augmentable.
+ *
+ * @param packageName
+ * Generated Type Package Name
+ * @param schemaNode
+ * Schema Node definition
+ * @return Generated Type Builder instance for Schema Node definition
+ */
+ private GeneratedTypeBuilder addDefaultInterfaceDefinition(final String packageName, final SchemaNode schemaNode) {
+ final GeneratedTypeBuilder builder = addRawInterfaceDefinition(packageName, schemaNode, "");
+ builder.addImplementsType(Types.DATA_OBJECT);
+ builder.addImplementsType(Types.augmentableTypeFor(builder));
+ return builder;
+ }
+
+ /**
+ *
+ * @param packageName
+ * @param schemaNode
+ * @return
+ */
+ private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode) {
return addRawInterfaceDefinition(packageName, schemaNode, "");
}
- private GeneratedTypeBuilder addRawInterfaceDefinition(
- final String packageName, final SchemaNode schemaNode,
+ private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode,
final String prefix) {
if (schemaNode == null) {
- return null;
+ throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
+ }
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
+ }
+ if (schemaNode.getQName() == null) {
+ throw new IllegalArgumentException("QName for Data Schema Node cannot be NULL!");
}
-
final String schemaNodeName = schemaNode.getQName().getLocalName();
+ if (schemaNodeName == null) {
+ throw new IllegalArgumentException("Local Name of QName for Data Schema Node cannot be NULL!");
+ }
- if ((packageName != null) && (schemaNodeName != null)) {
- final String genTypeName = prefix + parseToClassName(schemaNodeName)
- ;
- final GeneratedTypeBuilder newType = new GeneratedTypeBuilderImpl(
- packageName, genTypeName);
-
- newType.addImplementsType(Types.DATA_OBJECT);
- newType.addImplementsType(Types.augmentableTypeFor(newType));
+ final String genTypeName;
+ if (prefix == null) {
+ genTypeName = parseToClassName(schemaNodeName);
+ } else {
+ genTypeName = prefix + parseToClassName(schemaNodeName);
+ }
- if (!genTypeBuilders.containsKey(packageName)) {
- final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
+ final GeneratedTypeBuilder newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
+ if (!genTypeBuilders.containsKey(packageName)) {
+ final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
+ builders.put(genTypeName, newType);
+ genTypeBuilders.put(packageName, builders);
+ } else {
+ final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
+ if (!builders.containsKey(genTypeName)) {
builders.put(genTypeName, newType);
- genTypeBuilders.put(packageName, builders);
- } else {
- final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders
- .get(packageName);
- if (!builders.containsKey(genTypeName)) {
- builders.put(genTypeName, newType);
- }
}
- return newType;
}
- return null;
+ return newType;
}
private String getterMethodName(final String methodName) {
return method.toString();
}
- private MethodSignatureBuilder constructGetter(
- final GeneratedTypeBuilder interfaceBuilder,
- final String schemaNodeName, final String comment,
- final Type returnType) {
- final MethodSignatureBuilder getMethod = interfaceBuilder
- .addMethod(getterMethodName(schemaNodeName));
+ private MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder,
+ final String schemaNodeName, final String comment, final Type returnType) {
+ final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName));
- getMethod.addComment(comment);
- getMethod.addReturnType(returnType);
+ getMethod.setComment(comment);
+ getMethod.setReturnType(returnType);
return getMethod;
}
- private MethodSignatureBuilder constructSetter(
- final GeneratedTypeBuilder interfaceBuilder,
- final String schemaNodeName, final String comment,
- final Type parameterType) {
- final MethodSignatureBuilder setMethod = interfaceBuilder
- .addMethod(setterMethodName(schemaNodeName));
+ private MethodSignatureBuilder constructSetter(final GeneratedTypeBuilder interfaceBuilder,
+ final String schemaNodeName, final String comment, final Type parameterType) {
+ final MethodSignatureBuilder setMethod = interfaceBuilder.addMethod(setterMethodName(schemaNodeName));
- setMethod.addComment(comment);
- setMethod.addParameter(parameterType,
- parseToValidParamName(schemaNodeName));
- setMethod.addReturnType(Types.voidType());
+ setMethod.setComment(comment);
+ setMethod.addParameter(parameterType, parseToValidParamName(schemaNodeName));
+ setMethod.setReturnType(Types.voidType());
return setMethod;
}
- private List<Type> listToGenType(final String basePackageName,
- final ListSchemaNode list) {
+ private List<Type> listToGenType(final String basePackageName, final ListSchemaNode list) {
if (basePackageName == null) {
- throw new IllegalArgumentException(
- "Package Name for Generated Type cannot be NULL!");
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
}
if (list == null) {
- throw new IllegalArgumentException(
- "List Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("List Schema Node cannot be NULL!");
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- list.getPath());
- final GeneratedTypeBuilder typeBuilder = resolveListTypeBuilder(
- packageName, list);
+ final String packageName = packageNameForGeneratedType(basePackageName, list.getPath());
+ final GeneratedTypeBuilder typeBuilder = resolveListTypeBuilder(packageName, list);
final List<String> listKeys = listKeys(list);
- GeneratedTOBuilder genTOBuilder = resolveListKeyTOBuilder(packageName,
- list, listKeys);
+ GeneratedTOBuilder genTOBuilder = resolveListKeyTOBuilder(packageName, list, listKeys);
final Set<DataSchemaNode> schemaNodes = list.getChildNodes();
if (schemaNode.isAugmenting()) {
continue;
}
- addSchemaNodeToListBuilders(basePackageName, schemaNode,
- typeBuilder, genTOBuilder, listKeys);
+ addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys);
}
return typeBuildersToGenTypes(typeBuilder, genTOBuilder);
}
- private void addSchemaNodeToListBuilders(final String basePackageName,
- final DataSchemaNode schemaNode,
- final GeneratedTypeBuilder typeBuilder,
- final GeneratedTOBuilder genTOBuilder, final List<String> listKeys) {
+ private void addSchemaNodeToListBuilders(final String basePackageName, final DataSchemaNode schemaNode,
+ final GeneratedTypeBuilder typeBuilder, final GeneratedTOBuilder genTOBuilder, final List<String> listKeys) {
if (schemaNode == null) {
- throw new IllegalArgumentException(
- "Data Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
}
if (typeBuilder == null) {
- throw new IllegalArgumentException(
- "Generated Type Builder cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
}
if (schemaNode instanceof LeafSchemaNode) {
resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
}
} else if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder,
- (LeafListSchemaNode) schemaNode);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
} else if (schemaNode instanceof ContainerSchemaNode) {
- resolveContainerSchemaNode(basePackageName, typeBuilder,
- (ContainerSchemaNode) schemaNode);
+ resolveContainerSchemaNode(basePackageName, typeBuilder, (ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
- resolveListSchemaNode(basePackageName, typeBuilder,
- (ListSchemaNode) schemaNode);
+ resolveListSchemaNode(basePackageName, typeBuilder, (ListSchemaNode) schemaNode);
}
}
- private List<Type> typeBuildersToGenTypes(
- final GeneratedTypeBuilder typeBuilder,
- GeneratedTOBuilder genTOBuilder) {
+ private List<Type> typeBuildersToGenTypes(final GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
final List<Type> genTypes = new ArrayList<>();
if (typeBuilder == null) {
- throw new IllegalArgumentException(
- "Generated Type Builder cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
}
if (genTOBuilder != null) {
final GeneratedTransferObject genTO = genTOBuilder.toInstance();
- constructGetter(typeBuilder, genTO.getName(),
- "Returns Primary Key of Yang List Type", genTO);
+ constructGetter(typeBuilder, genTO.getName(), "Returns Primary Key of Yang List Type", genTO);
genTypes.add(genTO);
}
genTypes.add(typeBuilder.toInstance());
* @param list
* @return
*/
- private GeneratedTOBuilder resolveListKey(final String packageName,
- final ListSchemaNode list) {
+ private GeneratedTOBuilder resolveListKey(final String packageName, final ListSchemaNode list) {
final String listName = list.getQName().getLocalName() + "Key";
return schemaNodeToTransferObjectBuilder(packageName, list, listName);
}
- private boolean isPartOfListKey(final LeafSchemaNode leaf,
- final List<String> keys) {
+ private boolean isPartOfListKey(final LeafSchemaNode leaf, final List<String> keys) {
if ((leaf != null) && (keys != null) && (leaf.getQName() != null)) {
final String leafName = leaf.getQName().getLocalName();
if (keys.contains(leafName)) {
return listKeys;
}
- private GeneratedTypeBuilder resolveListTypeBuilder(
- final String packageName, final ListSchemaNode list) {
+ private GeneratedTypeBuilder resolveListTypeBuilder(final String packageName, final ListSchemaNode list) {
if (packageName == null) {
- throw new IllegalArgumentException(
- "Package Name for Generated Type cannot be NULL!");
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
}
if (list == null) {
- throw new IllegalArgumentException(
- "List Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("List Schema Node cannot be NULL!");
}
final String schemaNodeName = list.getQName().getLocalName();
final String genTypeName = parseToClassName(schemaNodeName);
GeneratedTypeBuilder typeBuilder = null;
- final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders
- .get(packageName);
+ final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
if (builders != null) {
typeBuilder = builders.get(genTypeName);
}
if (typeBuilder == null) {
- typeBuilder = addRawInterfaceDefinition(packageName, list);
+ typeBuilder = addDefaultInterfaceDefinition(packageName, list);
}
return typeBuilder;
}
- private GeneratedTOBuilder resolveListKeyTOBuilder(
- final String packageName, final ListSchemaNode list,
+ private GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list,
final List<String> listKeys) {
GeneratedTOBuilder genTOBuilder = null;
if (listKeys.size() > 0) {
*/
package org.opendaylight.controller.sal.binding.yang.types;
+import org.apache.commons.lang.StringEscapeUtils;
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.*;
-import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.controller.yang.model.api.type.*;
+import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.controller.yang.model.util.ExtendedType;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public void putReferencedType(final SchemaPath refTypePath,
final Type refType) {
if (refTypePath == null) {
- throw new IllegalArgumentException("Path reference of " +
- "Enumeration Type Definition cannot be NULL!");
+ throw new IllegalArgumentException("Path reference of "
+ + "Enumeration Type Definition cannot be NULL!");
}
if (refType == null) {
- throw new IllegalArgumentException("Reference to Enumeration " +
- "Type cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Enumeration "
+ + "Type cannot be NULL!");
}
referencedTypes.put(refTypePath, refType);
}
final TypeDefinition<?> typeDefinition) {
Type returnType = null;
if (typeDefinition == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
if (typeDefinition.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Type Definitions Local Name " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
}
final String typedefName = typeDefinition.getQName().getLocalName();
if (typeDefinition instanceof ExtendedType) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef;
returnType = provideTypeForLeafref(leafref);
} else if (baseTypeDef instanceof IdentityrefTypeDefinition) {
- final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition;
+ final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) baseTypeDef;
returnType = returnTypeForIdentityref(idref);
} else if (baseTypeDef instanceof EnumTypeDefinition) {
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
returnType = resolveEnumFromTypeDefinition(enumTypeDef,
typedefName);
} else {
- final Module module = findParentModuleForTypeDefinition(schemaContext,
- typeDefinition);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, typeDefinition);
if (module != null) {
final Map<String, Type> genTOs = genTypeDefsContextMap
.get(module.getName());
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
returnType = provideTypeForLeafref(leafref);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
- final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition;
+ final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
returnType = returnTypeForIdentityref(idref);
} else {
returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
.javaTypeForSchemaDefinitionType(typeDefinition);
}
}
- //TODO: add throw exception when we will be able to resolve ALL yang
+ // TODO: add throw exception when we will be able to resolve ALL yang
// types!
-// if (returnType == null) {
-// throw new IllegalArgumentException("Type Provider can't resolve " +
-// "type for specified Type Definition " + typedefName);
-// }
+ // if (returnType == null) {
+ // throw new IllegalArgumentException("Type Provider can't resolve " +
+ // "type for specified Type Definition " + typedefName);
+ // }
return returnType;
}
-
+
private Type returnTypeForIdentityref(IdentityrefTypeDefinition idref) {
QName baseIdQName = idref.getIdentity();
Module module = schemaContext.findModuleByNamespace(baseIdQName.getNamespace());
IdentitySchemaNode identity = null;
- for(IdentitySchemaNode id : module.getIdentities()) {
- if(id.getQName().equals(baseIdQName)) {
+ for (IdentitySchemaNode id : module.getIdentities()) {
+ if (id.getQName().equals(baseIdQName)) {
identity = id;
}
}
- if(identity == null) {
+ if (identity == null) {
throw new IllegalArgumentException("Target identity '" + baseIdQName + "' do not exists");
}
final TypeDefinition<?> typeDefinition) {
Type returnType = null;
if (typeDefinition == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definitions Local Name " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
}
final String typedefName = typeDefinition.getQName().getLocalName();
if (!(baseTypeDef instanceof LeafrefTypeDefinition)
&& !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
- final Module module = findParentModuleForTypeDefinition(schemaContext,
- typeDefinition);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, typeDefinition);
if (module != null) {
final Map<String, Type> genTOs = genTypeDefsContextMap
private TypeDefinition<?> baseTypeDefForExtendedType(
final TypeDefinition<?> extendTypeDef) {
if (extendTypeDef == null) {
- throw new IllegalArgumentException("Type Definiition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definiition reference cannot be NULL!");
}
final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
if (baseTypeDef instanceof ExtendedType) {
public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
Type returnType = null;
if (leafrefType == null) {
- throw new IllegalArgumentException("Leafref Type Definition " +
- "reference cannot be NULL!");
+ throw new IllegalArgumentException("Leafref Type Definition reference cannot be NULL!");
}
if (leafrefType.getPathStatement() == null) {
- throw new IllegalArgumentException("The Path Statement for " +
- "Leafref Type Definition cannot be NULL!");
+ throw new IllegalArgumentException("The Path Statement for Leafref Type Definition cannot be NULL!");
}
final RevisionAwareXPath xpath = leafrefType.getPathStatement();
if (strXPath.matches(".*//[.* | .*//].*")) {
returnType = Types.typeForClass(Object.class);
} else {
- final Module module = findParentModuleForTypeDefinition(schemaContext, leafrefType);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, leafrefType);
if (module != null) {
final DataSchemaNode dataNode;
if (xpath.isAbsolute()) {
dataNode = findDataSchemaNode(schemaContext, module,
xpath);
} else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext,
- module, leafrefType, xpath);
+ dataNode = findDataSchemaNodeForRelativeXPath(
+ schemaContext, module, leafrefType, xpath);
}
if (leafContainsEnumDefinition(dataNode)) {
returnType = referencedTypes.get(dataNode.getPath());
} else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(
- dataNode.getPath()));
+ returnType = Types.listTypeFor(referencedTypes
+ .get(dataNode.getPath()));
} else {
returnType = resolveTypeFromDataSchemaNode(dataNode);
}
return false;
}
- private boolean leafListContainsEnumDefinition(
- final DataSchemaNode dataNode) {
+ private boolean leafListContainsEnumDefinition(final DataSchemaNode dataNode) {
if (dataNode instanceof LeafListSchemaNode) {
final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
if (leafList.getType() instanceof EnumTypeDefinition) {
private Enumeration resolveEnumFromTypeDefinition(
final EnumTypeDefinition enumTypeDef, final String enumName) {
if (enumTypeDef == null) {
- throw new IllegalArgumentException("EnumTypeDefinition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
}
if (enumTypeDef.getValues() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain at least ONE value definition!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
}
if (enumTypeDef.getQName() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain NON-NULL QName!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
}
if (enumTypeDef.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Local Name in " +
- "EnumTypeDefinition QName cannot be NULL!");
+ throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
}
final String enumerationName = parseToClassName(enumName);
- Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef);
+ Module module = findParentModuleForTypeDefinition(schemaContext,
+ enumTypeDef);
final String basePackageName = moduleNamespaceToPackageName(module);
final EnumBuilder enumBuilder = new EnumerationBuilderImpl(
final EnumTypeDefinition enumTypeDef, final String enumName,
final GeneratedTypeBuilder typeBuilder) {
if (enumTypeDef == null) {
- throw new IllegalArgumentException("EnumTypeDefinition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
}
if (enumTypeDef.getValues() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain at least ONE value definition!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
}
if (enumTypeDef.getQName() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain NON-NULL QName!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
}
if (enumTypeDef.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Local Name in " +
- "EnumTypeDefinition QName cannot be NULL!");
+ throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
}
if (typeBuilder == null) {
- throw new IllegalArgumentException("Generated Type Builder " +
- "reference cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!");
}
final String enumerationName = parseToClassName(enumName);
}
private void updateEnumPairsFromEnumTypeDef(
- final EnumTypeDefinition enumTypeDef,
- final EnumBuilder enumBuilder) {
+ final EnumTypeDefinition enumTypeDef, final EnumBuilder enumBuilder) {
if (enumBuilder != null) {
final List<EnumPair> enums = enumTypeDef.getValues();
if (enums != null) {
private void resolveTypeDefsFromContext() {
final Set<Module> modules = schemaContext.getModules();
if (modules == null) {
- throw new IllegalArgumentException("Sef of Modules cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
}
for (final Module module : modules) {
if (module == null) {
final List<ExtendedType> extUnions = UnionDependencySort
.sort(typeDefinitions);
for (final ExtendedType extUnionType : extUnions) {
- addUnionGeneratedTypeDefinition(basePackageName, extUnionType);
+ addUnionGeneratedTypeDefinition(basePackageName,
+ extUnionType);
}
}
}
if ((basePackageName != null) && (moduleName != null)
&& (typedef != null) && (typedef.getQName() != null)) {
-
final String typedefName = typedef.getQName().getLocalName();
final TypeDefinition<?> baseTypeDefinition = baseTypeDefForExtendedType(typedef);
if (!(baseTypeDefinition instanceof LeafrefTypeDefinition)
returnType = resolveEnumFromTypeDefinition(enumTypeDef,
typedefName);
+ } else if (baseTypeDefinition instanceof BitsTypeDefinition) {
+ final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) baseTypeDefinition;
+ returnType = bitsTypedefToTransferObject(bitsTypeDefinition,
+ basePackageName, typedefName);
+
} else {
final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
.javaTypeForSchemaDefinitionType(baseTypeDefinition);
javaType);
}
if (returnType != null) {
- final Map<String, Type> typeMap = genTypeDefsContextMap.get
- (moduleName);
+ final Map<String, Type> typeMap = genTypeDefsContextMap
+ .get(moduleName);
if (typeMap != null) {
typeMap.put(typedefName, returnType);
}
final GeneratedPropertyBuilder genPropBuilder = genTOBuilder
.addProperty(propertyName);
- genPropBuilder.addReturnType(javaType);
+ genPropBuilder.setReturnType(javaType);
genTOBuilder.addEqualsIdentity(genPropBuilder);
genTOBuilder.addHashIdentity(genPropBuilder);
genTOBuilder.addToStringProperty(genPropBuilder);
+ if (javaType == BaseYangTypes.STRING_TYPE) {
+ if (typedef instanceof ExtendedType) {
+ List<PatternConstraint> patternConstraints = ((ExtendedType) typedef).getPatterns();
+ List<String> regularExpressions = new ArrayList<String>();
+ String regEx;
+ String modifiedRegEx;
+ for (PatternConstraint ptrnCons : patternConstraints) {
+ regEx = ptrnCons.getRegularExpression();
+ modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
+ regularExpressions.add(modifiedRegEx);
+ }
+
+ genTOBuilder.addConstant(Types.listTypeFor(BaseYangTypes.STRING_TYPE),
+ TypeConstants.PATTERN_CONSTANT_NAME, regularExpressions);
+ }
+ }
+
return genTOBuilder.toInstance();
}
return null;
private void addUnionGeneratedTypeDefinition(final String basePackageName,
final TypeDefinition<?> typedef) {
if (basePackageName == null) {
- throw new IllegalArgumentException("Base Package Name cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
}
if (typedef == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typedef.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
final TypeDefinition<?> baseTypeDefinition = typedef.getBaseType();
if ((baseTypeDefinition != null)
&& (baseTypeDefinition instanceof UnionTypeDefinition)) {
final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition;
- final List<TypeDefinition<?>> unionTypes = unionTypeDef
- .getTypes();
- final Module parentModule = findParentModuleForTypeDefinition(schemaContext,
- typedef);
+ final List<TypeDefinition<?>> unionTypes = unionTypeDef.getTypes();
+ final Module parentModule = findParentModuleForTypeDefinition(
+ schemaContext, typedef);
Map<String, Type> genTOsMap = null;
if (parentModule != null && parentModule.getName() != null) {
basePackageName, typedef);
if ((unionTypes != null) && (unionGenTransObject != null)) {
for (final TypeDefinition<?> unionType : unionTypes) {
- final String typeName = unionType.getQName()
- .getLocalName();
+ final String typeName = unionType.getQName().getLocalName();
if (unionType instanceof ExtendedType) {
- final Module unionTypeModule = findParentModuleForTypeDefinition(schemaContext,
- unionType);
- if (unionTypeModule != null && unionTypeModule.getName() != null) {
+ final Module unionTypeModule = findParentModuleForTypeDefinition(
+ schemaContext, unionType);
+ if (unionTypeModule != null
+ && unionTypeModule.getName() != null) {
final Map<String, Type> innerGenTOs = genTypeDefsContextMap
.get(unionTypeModule.getName());
- final GeneratedTransferObject genTransferObject =
- (GeneratedTransferObject) innerGenTOs.get(typeName);
+ final GeneratedTransferObject genTransferObject = (GeneratedTransferObject) innerGenTOs
+ .get(typeName);
if (genTransferObject != null) {
updateUnionTypeAsProperty(unionGenTransObject,
genTransferObject,
}
}
} else if (unionType instanceof EnumTypeDefinition) {
- final EnumBuilder
- enumBuilder = resolveInnerEnumFromTypeDefinition(
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(
(EnumTypeDefinition) unionType, typeName,
unionGenTransObject);
final Type enumRefType = new ReferencedTypeImpl(
final GeneratedTOBuilder unionGenTransObject, final Type type,
final String propertyName) {
if (unionGenTransObject != null && type != null) {
- final GeneratedPropertyBuilder propBuilder =
- unionGenTransObject.addProperty(parseToValidParamName(
- propertyName));
- propBuilder.addReturnType(type);
+ final GeneratedPropertyBuilder propBuilder = unionGenTransObject
+ .addProperty(parseToValidParamName(propertyName));
+ propBuilder.setReturnType(type);
propBuilder.setReadOnly(false);
if (!(type instanceof Enumeration)) {
}
return null;
}
+
+ private GeneratedTransferObject bitsTypedefToTransferObject(
+ final BitsTypeDefinition bitsTypeDefinition, final String basePackageName, final String typedefName) {
+
+ if (bitsTypeDefinition == null) {
+ throw new IllegalArgumentException("Bits TypeDefinition cannot be NULL!");
+ }
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (typedefName == null) {
+ throw new IllegalArgumentException("Type Definition Local Name cannot be NULL!");
+ }
+
+ final String typeDefName = parseToClassName(typedefName);
+ final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName);
+
+ final List<Bit> bitList = bitsTypeDefinition.getBits();
+ GeneratedPropertyBuilder genPropertyBuilder;
+ for (final Bit bit : bitList) {
+ String name = bit.getName();
+ genPropertyBuilder = genTOBuilder.addProperty(parseToValidParamName(name));
+ genPropertyBuilder.setReadOnly(false);
+ genPropertyBuilder.setReturnType(BaseYangTypes.BOOLEAN_TYPE);
+
+ genTOBuilder.addEqualsIdentity(genPropertyBuilder);
+ genTOBuilder.addHashIdentity(genPropertyBuilder);
+ genTOBuilder.addToStringProperty(genPropertyBuilder);
+ }
+ return genTOBuilder.toInstance();
+ }
+
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class ChoiceCaseGenTypesTest {
+
+ private final static List<File> yangModels = new ArrayList<>();
+ private final static String yangModelsFolder = AugmentedTypeTest.class.getResource("/choice-case-type-test-models")
+ .getPath();
+
+ @BeforeClass
+ public static void loadTestResources() {
+ final File augFolder = new File(yangModelsFolder);
+ for (final File fileEntry : augFolder.listFiles()) {
+ if (fileEntry.isFile()) {
+ yangModels.add(fileEntry);
+ }
+ }
+ }
+
+ @Test
+ public void choiceCaseResolvingTypeTest() {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(yangModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull("context is null", context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ assertNotNull("genTypes is null", genTypes);
+ assertFalse("genTypes is empty", genTypes.isEmpty());
+ }
+}
*/
package org.opendaylight.controller.sal.binding.generator.impl;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Test;
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
public class GenEnumResolvingTest {
private SchemaContext resolveSchemaContextFromFiles(
Enumeration linkUpDownTrapEnable = null;
Enumeration operStatus = null;
- final List<Enumeration> enums = genInterface.getEnumDefintions();
+ final List<Enumeration> enums = genInterface.getEnumerations();
assertNotNull("Generated Type Interface cannot contain NULL reference" +
" to Enumeration types!", enums);
assertEquals("Generated Type Interface MUST contain 2 Enumeration " +
assertNotNull("Generated Interface cannot contain NULL reference for " +
"Method Signature Definitions!", methods);
- assertEquals("Expected count of method signature definitions is 26",
- 26, methods.size());
+ assertEquals("Expected count of method signature definitions is 21",
+ 21, methods.size());
Enumeration ianaIfType = null;
for (final MethodSignature method : methods) {
if (method.getName().equals("getType")) {
final List<MethodSignature> methods = genInterface.getMethodDefinitions();
assertNotNull("Generated Type Interface cannot contain NULL reference" +
" to Enumeration types!", methods);
- assertEquals("Generated Type Interface MUST contain 7 Methods ",
- 7, methods.size());
+ assertEquals("Generated Type Interface MUST contain 4 Methods ",
+ 4, methods.size());
for (final MethodSignature method : methods) {
if (method.getName().equals("getLinkUpDownTrapEnable")) {
linkUpDownTrapEnable = method.getReturnType();
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+public class GeneratedTypesBitsTest {
+
+ private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
+ final YangModelParser parser = new YangParserImpl();
+
+ final List<File> inputFiles = new ArrayList<File>();
+ for (int i = 0; i < yangFiles.length; ++i) {
+ inputFiles.add(new File(yangFiles[i]));
+ }
+
+ final Set<Module> modules = parser.parseYangModels(inputFiles);
+ return parser.resolveSchemaContext(modules);
+ }
+
+ @Test
+ public void testGeneretedTypesBitsTest() {
+ final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
+
+ final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
+ assertTrue(context != null);
+
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+ assertTrue(genTypes != null);
+
+ List<MethodSignature> methodSignaturesList = null;
+
+ boolean leafParentFound = false;
+
+ boolean byteTypeFound = false;
+ int classPropertiesNumb = 0;
+ int toStringPropertiesNum = 0;
+ int equalPropertiesNum = 0;
+ int hashPropertiesNum = 0;
+
+ String nameReturnParamType = "";
+ String nameMethodeParamType = "";
+ boolean getByteLeafMethodFound = false;
+ boolean setByteLeafMethodFound = false;
+ int setByteLeafMethodParamNum = 0;
+
+ for (final Type type : genTypes) {
+ if (type instanceof GeneratedTransferObject) { // searching for
+ // ByteType
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+ if (genTO.getName().equals("ByteType")) {
+ byteTypeFound = true;
+ List<GeneratedProperty> genProperties = genTO.getProperties();
+ classPropertiesNumb = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getToStringIdentifiers();
+ toStringPropertiesNum = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getEqualsIdentifiers();
+ equalPropertiesNum = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getHashCodeIdentifiers();
+ hashPropertiesNum = genProperties.size();
+
+ }
+ } else if (type instanceof GeneratedType) { // searching for
+ // interface
+ // LeafParameterContainer
+ final GeneratedType genType = (GeneratedType) type;
+ if (genType.getName().equals("LeafParentContainer")) {
+ leafParentFound = true;
+ // check of methods
+ methodSignaturesList = genType.getMethodDefinitions();
+ if (methodSignaturesList != null) {
+ for (MethodSignature methodSignature : methodSignaturesList) { // loop
+ // through
+ // all
+ // methods
+ if (methodSignature.getName().equals("getByteLeaf")) {
+ getByteLeafMethodFound = true;
+
+ nameReturnParamType = methodSignature.getReturnType().getName();
+ } else if (methodSignature.getName().equals("setByteLeaf")) {
+ setByteLeafMethodFound = true;
+
+ List<Parameter> parameters = methodSignature.getParameters();
+ setByteLeafMethodParamNum = parameters.size();
+ for (Parameter parameter : parameters) {
+ nameMethodeParamType = parameter.getType().getName();
+ }
+
+ }
+
+ }
+ }
+ }
+ }
+
+ }
+
+ assertTrue(byteTypeFound);
+
+ assertEquals(classPropertiesNumb,8);
+
+ assertEquals(toStringPropertiesNum,8);
+ assertEquals(equalPropertiesNum,8);
+ assertEquals(hashPropertiesNum,8);
+ assertTrue(leafParentFound);
+
+ assertNotNull(methodSignaturesList);
+
+ assertTrue(getByteLeafMethodFound);
+ assertEquals(nameReturnParamType,"ByteType");
+
+ assertFalse(setByteLeafMethodFound);
+ assertEquals(0, setByteLeafMethodParamNum);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+public class GeneratedTypesStringTest {
+
+ private final static List<File> testModels = new ArrayList<File>();
+
+ @BeforeClass
+ public static void loadTestResources() {
+ final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang")
+ .getPath());
+ testModels.add(listModelFile);
+ }
+
+ @Test
+ public void constantGenerationTest() {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(testModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull(context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ boolean typedefStringFound = false;
+ boolean constantRegExListFound = false;
+ boolean constantRegExListTypeGeneric = false;
+ boolean constantRegExListTypeContainer = false;
+ boolean noStringInReqExListFound = false;
+ boolean constantRegExListValueOK = false;
+ boolean constantRegExListTypeOneGeneric = false;
+ for (final Type type : genTypes) {
+ if (type instanceof GeneratedTransferObject) {
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+
+ if (genTO.getName().equals("TypedefString")) {
+ typedefStringFound = true;
+
+ List<Constant> constants = genTO.getConstantDefinitions();
+ for (Constant con : constants) {
+ if (con.getName().equals("PATTERN_CONSTANTS")) {
+ constantRegExListFound = true;
+ } else
+ break;
+ ParameterizedType pType;
+ if (con.getType() instanceof ParameterizedType) {
+ pType = (ParameterizedType) con.getType();
+ } else
+ break;
+
+ Type[] types;
+ if (pType.getName().equals("List")) {
+ constantRegExListTypeContainer = true;
+ types = pType.getActualTypeArguments();
+ } else
+ break;
+
+ if (types.length == 1) {
+ constantRegExListTypeOneGeneric = true;
+ } else
+ break;
+
+ if (types[0].getName().equals("String")) {
+ constantRegExListTypeGeneric = true;
+ } else
+ break;
+
+ if (con.getValue() instanceof List) {
+ constantRegExListValueOK = true;
+ } else
+ break;
+
+ for (Object obj : (List<?>) con.getValue()) {
+ if (!(obj instanceof String)) {
+ noStringInReqExListFound = true;
+ break;
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+
+ assertTrue("Typedef >>TypedefString<< wasn't found", typedefStringFound);
+ assertTrue("Constant PATTERN_CONSTANTS is missing in TO", constantRegExListFound);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't have correct container type", constantRegExListTypeContainer);
+ assertTrue("Constant PATTERN_CONSTANTS has more than one generic type", constantRegExListTypeOneGeneric);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't have correct generic type", constantRegExListTypeGeneric);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't contain List object", constantRegExListValueOK);
+ assertTrue("In list found other type than String", !noStringInReqExListFound);
+
+ }
+
+}
import org.junit.Test;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
public class GeneratedTypesTest {
- private SchemaContext resolveSchemaContextFromFiles(
- final String... yangFiles) {
+ private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
final YangModelParser parser = new YangParserImpl();
final List<File> inputFiles = new ArrayList<File>();
@Test
public void testMultipleModulesResolving() {
- final String topologyPath = getClass().getResource(
- "/abstract-topology.yang").getPath();
- final String typesPath = getClass().getResource(
- "/ietf-inet-types@2010-09-24.yang").getPath();
- final SchemaContext context = resolveSchemaContextFromFiles(
- topologyPath, typesPath);
- assertTrue(context != null);
+ final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath();
+ final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath();
+ final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(29, genTypes.size());
}
@Test
public void testLeafrefResolving() {
- final String topologyPath = getClass().getResource(
- "/leafref-test-models/abstract-topology@2013-02-08.yang")
+ final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
.getPath();
- final String interfacesPath = getClass().getResource(
- "/leafref-test-models/ietf-interfaces@2012-11-15.yang")
+ final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
.getPath();
// final String ifTypePath = getClass().getResource(
// "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
- final String inetTypesPath = getClass().getResource(
- "/leafref-test-models/ietf-inet-types@2010-09-24.yang")
+ final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang")
.getPath();
- final String yangTypesPath = getClass().getResource(
- "/leafref-test-models/ietf-yang-types@2010-09-24.yang")
+ final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
.getPath();
- assertTrue(topologyPath != null);
- assertTrue(interfacesPath != null);
+ assertNotNull(topologyPath);
+ assertNotNull(interfacesPath);
// assertTrue(ifTypePath != null);
- assertTrue(inetTypesPath != null);
- assertTrue(yangTypesPath != null);
+ assertNotNull(inetTypesPath);
+ assertNotNull(yangTypesPath);
// final SchemaContext context = resolveSchemaContextFromFiles(
// topologyPath, interfacesPath, ifTypePath, inetTypesPath,
// yangTypesPath);
- final SchemaContext context = resolveSchemaContextFromFiles(
- topologyPath, interfacesPath, inetTypesPath, yangTypesPath);
- assertTrue(context != null);
+ final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
+ yangTypesPath);
+ assertNotNull(context);
assertEquals(4, context.getModules().size());
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertEquals(57, genTypes.size());
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
GeneratedTransferObject gtIfcKey = null;
GeneratedType gtIfc = null;
Type ifcIdPropType = ifcIdProp.getReturnType();
assertNotNull(ifcIdPropType);
assertFalse(ifcIdPropType.equals("java.lang.Void"));
- assertTrue(ifcIdPropType.getName().equals("String"));
+ assertEquals(ifcIdPropType.getName(), "String");
// Interface
final List<MethodSignature> gtIfcMethods = gtIfc.getMethodDefinitions();
Type getIfcKeyType = getIfcKey.getReturnType();
assertNotNull(getIfcKeyType);
assertFalse(getIfcKeyType.equals("java.lang.Void"));
- assertTrue(getIfcKeyType.getName().equals("InterfaceKey"));
+ assertEquals(getIfcKeyType.getName(), "InterfaceKey");
assertNotNull(getHigherLayerIf);
Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
assertNotNull(getHigherLayerIfType);
assertFalse(getHigherLayerIfType.equals("java.lang.Void"));
- assertTrue(getHigherLayerIfType.getName().equals("List"));
+ assertEquals(getHigherLayerIfType.getName(), "List");
// NetworkLink
- final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink
- .getMethodDefinitions();
+ final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions();
assertNotNull(gtNetworkLinkMethods);
MethodSignature getIfc = null;
for (MethodSignature method : gtNetworkLinkMethods) {
Type getIfcType = getIfc.getReturnType();
assertNotNull(getIfcType);
assertFalse(getIfcType.equals("java.lang.Void"));
- assertTrue(getIfcType.getName().equals("String"));
+ assertEquals(getIfcType.getName(), "String");
// SourceNode
- final List<MethodSignature> gtSourceMethods = gtSource
- .getMethodDefinitions();
+ final List<MethodSignature> gtSourceMethods = gtSource.getMethodDefinitions();
assertNotNull(gtSourceMethods);
MethodSignature getIdSource = null;
for (MethodSignature method : gtSourceMethods) {
Type getIdType = getIdSource.getReturnType();
assertNotNull(getIdType);
assertFalse(getIdType.equals("java.lang.Void"));
- assertTrue(getIdType.getName().equals("Uri"));
+ assertEquals(getIdType.getName(), "Uri");
// DestinationNode
- final List<MethodSignature> gtDestMethods = gtDest
- .getMethodDefinitions();
+ final List<MethodSignature> gtDestMethods = gtDest.getMethodDefinitions();
assertNotNull(gtDestMethods);
MethodSignature getIdDest = null;
for (MethodSignature method : gtDestMethods) {
Type getIdDestType = getIdDest.getReturnType();
assertNotNull(getIdDestType);
assertFalse(getIdDestType.equals("java.lang.Void"));
- assertTrue(getIdDestType.getName().equals("Uri"));
+ assertEquals(getIdDestType.getName(), "Uri");
// Tunnel
- final List<MethodSignature> gtTunnelMethods = gtTunnel
- .getMethodDefinitions();
+ final List<MethodSignature> gtTunnelMethods = gtTunnel.getMethodDefinitions();
assertNotNull(gtTunnelMethods);
MethodSignature getTunnelKey = null;
for (MethodSignature method : gtTunnelMethods) {
Type getTunnelKeyType = getTunnelKey.getReturnType();
assertNotNull(getTunnelKeyType);
assertFalse(getTunnelKeyType.equals("java.lang.Void"));
- assertTrue(getTunnelKeyType.getName().equals("TunnelKey"));
+ assertEquals(getTunnelKeyType.getName(), "TunnelKey");
// TunnelKey
- final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey
- .getProperties();
+ final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey.getProperties();
assertNotNull(gtTunnelKeyProps);
GeneratedProperty tunnelId = null;
for (final GeneratedProperty property : gtTunnelKeyProps) {
Type tunnelIdType = tunnelId.getReturnType();
assertNotNull(tunnelIdType);
assertFalse(tunnelIdType.equals("java.lang.Void"));
- assertTrue(tunnelIdType.getName().equals("Uri"));
+ assertEquals(tunnelIdType.getName(), "Uri");
}
@Test
public void testContainerResolving() {
- final String filePath = getClass().getResource(
- "/simple-container-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-container-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assert (context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(4, genTypes.size());
final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
assertEquals("SimpleContainer", simpleContainer.getName());
assertEquals("NestedContainer", nestedContainer.getName());
- assertEquals(5, simpleContainer.getMethodDefinitions().size());
- assertEquals(4, nestedContainer.getMethodDefinitions().size());
-
- int methodsCount = 0;
- for (final MethodSignature method : simpleContainer
- .getMethodDefinitions()) {
+ assertEquals(3, simpleContainer.getMethodDefinitions().size());
+ assertEquals(2, nestedContainer.getMethodDefinitions().size());
+
+ int setFooMethodCounter = 0;
+ int getFooMethodCounter = 0;
+ int getBarMethodCounter = 0;
+ int getNestedContainerCounter = 0;
+
+ String getFooMethodReturnTypeName = "";
+ String setFooMethodInputParamName = "";
+ String setFooMethodInputParamTypeName = "";
+ String getBarMethodReturnTypeName = "";
+ String getNestedContainerReturnTypeName = "";
+ for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Integer");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Integer", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("getNestedContainer")) {
- method.getReturnType().getName().equals("NestedContainer");
- methodsCount++;
+ getNestedContainerCounter++;
+ getNestedContainerReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(4, methodsCount);
- methodsCount = 0;
- for (final MethodSignature method : nestedContainer
- .getMethodDefinitions()) {
+ assertEquals(getFooMethodCounter, 1);
+ assertEquals(getFooMethodReturnTypeName, "Integer");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(setFooMethodCounter, 1);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Integer");
+
+ assertEquals(getBarMethodCounter, 1);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ assertEquals(getNestedContainerCounter, 1);
+ assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+ setFooMethodCounter = 0;
+ getFooMethodCounter = 0;
+ getBarMethodCounter = 0;
+ int setBarMethodCounter = 0;
+
+ getFooMethodReturnTypeName = "";
+ setFooMethodInputParamName = "";
+ setFooMethodInputParamTypeName = "";
+ getBarMethodReturnTypeName = "";
+ String setBarMethodInputParamName = "";
+ String setBarMethodInputParamTypeName = "";
+
+ for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
+
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Short");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Short", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ setBarMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setBarMethodInputParamName = param.getName();
+ setBarMethodInputParamTypeName = param.getType().getName();
}
}
- assertEquals(4, methodsCount);
+
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "Short");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Short");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setBarMethodCounter);
+ // assertEquals(setBarMethodInputParamName, "bar");
+ // assertEquals(setBarMethodInputParamTypeName, "String");
}
@Test
public void testLeafListResolving() {
- final String filePath = getClass().getResource(
- "/simple-leaf-list-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(4, genTypes.size());
final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
assertEquals("SimpleContainer", simpleContainer.getName());
assertEquals("NestedContainer", nestedContainer.getName());
- assertEquals(5, simpleContainer.getMethodDefinitions().size());
- assertEquals(3, nestedContainer.getMethodDefinitions().size());
-
- int methodsCount = 0;
- for (final MethodSignature method : simpleContainer
- .getMethodDefinitions()) {
+ assertEquals(3, simpleContainer.getMethodDefinitions().size());
+ assertEquals(2, nestedContainer.getMethodDefinitions().size());
+
+ int setFooMethodCounter = 0;
+ int getFooMethodCounter = 0;
+ int getBarMethodCounter = 0;
+ int getNestedContainerCounter = 0;
+
+ String getFooMethodReturnTypeName = "";
+ String setFooMethodInputParamName = "";
+ String setFooMethodInputParamTypeName = "";
+ String getBarMethodReturnTypeName = "";
+ String getNestedContainerReturnTypeName = "";
+ for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("List");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("List", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("getNestedContainer")) {
- method.getReturnType().getName().equals("NestedContainer");
- methodsCount++;
+ getNestedContainerCounter++;
+ getNestedContainerReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(4, methodsCount);
- methodsCount = 0;
- for (final MethodSignature method : nestedContainer
- .getMethodDefinitions()) {
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "List");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "List");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ assertEquals(1, getNestedContainerCounter);
+ assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+ setFooMethodCounter = 0;
+ getFooMethodCounter = 0;
+ getBarMethodCounter = 0;
+
+ getFooMethodReturnTypeName = "";
+ setFooMethodInputParamName = "";
+ setFooMethodInputParamTypeName = "";
+ getBarMethodReturnTypeName = "";
+
+ for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Short");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Short", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("List");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(3, methodsCount);
+
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "Short");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Short");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "List");
}
@Test
public void testListResolving() {
- final String filePath = getClass()
- .getResource("/simple-list-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(6, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
+
+ int listParentContainerMethodsCount = 0;
+ int simpleListMethodsCount = 0;
+ int listChildContainerMethodsCount = 0;
+ int listKeyClassCount = 0;
+
+ int getSimpleListKeyMethodCount = 0;
+ int getListChildContainerMethodCount = 0;
+ int getFooMethodCount = 0;
+ int setFooMethodCount = 0;
+ int getSimpleLeafListMethodCount = 0;
+ int setSimpleLeafListMethodCount = 0;
+ int getBarMethodCount = 0;
+
+ String getSimpleListKeyMethodReturnTypeName = "";
+ String getListChildContainerMethodReturnTypeName = "";
+
+ int listKeyClassPropertyCount = 0;
+ String listKeyClassPropertyName = "";
+ String listKeyClassPropertyTypeName = "";
+ boolean listKeyClassPropertyReadOnly = false;
+
+ int hashMethodParameterCount = 0;
+ String hashMethodParameterName = "";
+ String hashMethodParameterReturnTypeName = "";
+
+ int equalMethodParameterCount = 0;
+ String equalMethodParameterName = "";
+ String equalMethodParameterReturnTypeName = "";
+
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
final GeneratedType genType = (GeneratedType) type;
if (genType.getName().equals("ListParentContainer")) {
- assertEquals(2, genType.getMethodDefinitions().size());
+ listParentContainerMethodsCount = genType.getMethodDefinitions().size();
genTypesCount++;
} else if (genType.getName().equals("SimpleList")) {
- assertEquals(8, genType.getMethodDefinitions().size());
- final List<MethodSignature> methods = genType
- .getMethodDefinitions();
- int methodsCount = 0;
+ simpleListMethodsCount = genType.getMethodDefinitions().size();
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
for (final MethodSignature method : methods) {
if (method.getName().equals("getSimpleListKey")) {
- assertEquals("SimpleListKey", method
- .getReturnType().getName());
- methodsCount++;
- } else if (method.getName().equals(
- "getListChildContainer")) {
- assertEquals("ListChildContainer", method
- .getReturnType().getName());
- methodsCount++;
+ getSimpleListKeyMethodCount++;
+ getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
+ } else if (method.getName().equals("getListChildContainer")) {
+ getListChildContainerMethodCount++;
+ getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
} else if (method.getName().equals("getFoo")) {
- methodsCount++;
+ getFooMethodCount++;
} else if (method.getName().equals("setFoo")) {
- methodsCount++;
+ setFooMethodCount++;
} else if (method.getName().equals("getSimpleLeafList")) {
- methodsCount++;
+ getSimpleLeafListMethodCount++;
} else if (method.getName().equals("setSimpleLeafList")) {
- methodsCount++;
+ setSimpleLeafListMethodCount++;
} else if (method.getName().equals("getBar")) {
- methodsCount++;
+ getBarMethodCount++;
}
}
- assertEquals(7, methodsCount);
genTypesCount++;
} else if (genType.getName().equals("ListChildContainer")) {
- assertEquals(2, genType.getMethodDefinitions().size());
+ listChildContainerMethodsCount = genType.getMethodDefinitions().size();
genTypesCount++;
}
} else if (type instanceof GeneratedTransferObject) {
genTOsCount++;
final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- final List<GeneratedProperty> hashProps = genTO
- .getHashCodeIdentifiers();
- final List<GeneratedProperty> equalProps = genTO
- .getEqualsIdentifiers();
-
- assertEquals(1, properties.size());
- assertEquals("ListKey", properties.get(0).getName());
- assertEquals("Byte", properties.get(0).getReturnType()
- .getName());
- assertEquals(true, properties.get(0).isReadOnly());
- assertEquals(1, hashProps.size());
- assertEquals("ListKey", hashProps.get(0).getName());
- assertEquals("Byte", hashProps.get(0).getReturnType().getName());
- assertEquals(1, equalProps.size());
- assertEquals("ListKey", equalProps.get(0).getName());
- assertEquals("Byte", equalProps.get(0).getReturnType()
- .getName());
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
+ final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
+
+ listKeyClassCount++;
+ listKeyClassPropertyCount = properties.size();
+ listKeyClassPropertyName = properties.get(0).getName();
+ listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
+ listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
+
+ hashMethodParameterCount = hashProps.size();
+ hashMethodParameterName = hashProps.get(0).getName();
+ hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
+
+ equalMethodParameterCount = equalProps.size();
+ equalMethodParameterName = equalProps.get(0).getName();
+ equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
+
}
}
- assertEquals(3, genTypesCount);
- assertEquals(1, genTOsCount);
+
+ assertEquals(1, listParentContainerMethodsCount);
+ assertEquals(1, listChildContainerMethodsCount);
+ assertEquals(1, getSimpleListKeyMethodCount);
+ assertEquals(1, listKeyClassCount);
+
+ assertEquals(1, listKeyClassPropertyCount);
+ assertEquals("ListKey", listKeyClassPropertyName);
+ assertEquals("Byte", listKeyClassPropertyTypeName);
+ assertEquals(true, listKeyClassPropertyReadOnly);
+ assertEquals(1, hashMethodParameterCount);
+ assertEquals("ListKey", hashMethodParameterName);
+ assertEquals("Byte", hashMethodParameterReturnTypeName);
+ assertEquals(1, equalMethodParameterCount);
+ assertEquals("ListKey", equalMethodParameterName);
+ assertEquals("Byte", equalMethodParameterReturnTypeName);
+
+ assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
+
+ assertEquals(1, getListChildContainerMethodCount);
+ assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
+ assertEquals(1, getFooMethodCount);
+ assertEquals(0, setFooMethodCount);
+ assertEquals(1, getSimpleLeafListMethodCount);
+ assertEquals(0, setSimpleLeafListMethodCount);
+ assertEquals(1, getBarMethodCount);
+
+ assertEquals(5, simpleListMethodsCount);
}
@Test
public void testListCompositeKeyResolving() {
- final String filePath = getClass().getResource(
- "/list-composite-key.yang").getPath();
+ final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(8, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
+
+ int compositeKeyListKeyPropertyCount = 0;
+ int compositeKeyListKeyCount = 0;
+ int innerListKeyPropertyCount = 0;
+
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
genTypesCount++;
} else if (type instanceof GeneratedTransferObject) {
final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
if (genTO.getName().equals("CompositeKeyListKey")) {
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- int propertyCount = 0;
+ compositeKeyListKeyCount++;
+ final List<GeneratedProperty> properties = genTO.getProperties();
for (final GeneratedProperty prop : properties) {
if (prop.getName().equals("Key1")) {
- propertyCount++;
+ compositeKeyListKeyPropertyCount++;
} else if (prop.getName().equals("Key2")) {
- propertyCount++;
+ compositeKeyListKeyPropertyCount++;
}
}
- assertEquals(2, propertyCount);
genTOsCount++;
} else if (genTO.getName().equals("InnerListKey")) {
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- assertEquals(1, properties.size());
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ innerListKeyPropertyCount = properties.size();
genTOsCount++;
}
}
}
+ assertEquals(1, compositeKeyListKeyCount);
+ assertEquals(2, compositeKeyListKeyPropertyCount);
+
+ assertEquals(1, innerListKeyPropertyCount);
assertEquals(6, genTypesCount);
assertEquals(2, genTOsCount);
@Test
public void testGeneratedTypes() {
- final String filePath = getClass().getResource("/demo-topology.yang")
- .getPath();
+ final String filePath = getClass().getResource("/demo-topology.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(15, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
genTypesCount++;
} else if (type instanceof GeneratedTransferObject) {
genTOsCount++;
type bin:restricted-binary;
}
- leaf-list binary-list {
+ leaf-list binary-leaf-list {
type binary {
length 256;
}
--- /dev/null
+module augment-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:augment-monitoring";
+ prefix "amon";
+
+ import choice-monitoring { prefix nm; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision "2013-07-01" {
+ reference "NO REF";
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" {
+ case autonomous-lock {
+ container autonomous-def {
+ leaf lock-id {
+ type int32;
+ }
+
+ leaf lock-time {
+ type uint32;
+ }
+ }
+ }
+
+ case anonymous-lock {
+ leaf lock-time {
+ type uint32;
+ }
+ }
+
+ leaf leaf-aug-case {
+ type string;
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock" {
+ choice aug-case-by-choice {
+ case foo {
+ leaf foo {
+ type string;
+ }
+ }
+
+ case bar {
+ leaf bar {
+ type boolean;
+ }
+ }
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore" {
+ choice storage-format {
+ case xml {
+ container xml-def {
+ leaf file-name {
+ type string;
+ }
+ }
+ }
+
+ case yang {
+ leaf yang-file-name {
+ type string;
+ }
+ }
+
+ case unknown-files {
+ list files {
+ key "file-name";
+
+ leaf file-name {
+ type string;
+ }
+
+ container file-data {
+ leaf utf8-data {
+ type string;
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module choice-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:choice-monitoring";
+ prefix "ncm";
+
+ import ietf-yang-types { prefix yang; }
+ import ietf-inet-types { prefix inet; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ description
+ "Test model for testing of resolving choice, case nodes and generation types from them.";
+
+ revision 2013-07-01 {
+
+ }
+
+ typedef tls-fingerprint-type {
+ type string {
+ pattern '([0-9a-fA-F]){2}(:([0-9a-fA-F]){2})*';
+ }
+ }
+
+ typedef netconf-datastore-type {
+ type enumeration {
+ enum running;
+ enum candidate;
+ enum startup;
+ }
+ }
+
+ container netconf-state {
+ config false;
+
+ container datastores {
+ list datastore {
+ key name;
+
+ leaf name {
+ type netconf-datastore-type;
+ }
+ container locks {
+ choice lock-type {
+
+ case global-lock {
+ container global-lock {
+
+ leaf locked-by-session {
+ type uint32;
+ mandatory true;
+ }
+
+ leaf locked-time {
+ type yang:date-and-time;
+ mandatory true;
+ }
+
+ container capabilities {
+ leaf-list capability {
+ type inet:uri;
+ }
+ }
+ }
+ }
+
+ case partial-lock {
+ list partial-lock {
+ key lock-id;
+
+ leaf lock-id {
+ type uint32;
+ }
+ leaf-list select {
+ type yang:xpath1.0;
+ min-elements 1;
+ }
+ leaf-list locked-node {
+ type string;
+ }
+ }
+ }
+
+ case fingerprint {
+ choice algorithm-and-hash {
+ mandatory true;
+ case md5 {
+ leaf md5 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha1 {
+ leaf sha1 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha224 {
+ leaf sha224 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha256 {
+ leaf sha256 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha384 {
+ leaf sha384 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha512 {
+ leaf sha512 {
+ type tls-fingerprint-type;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+ module ietf-inet-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+ prefix "inet";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types for Internet addresses and related things.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of protocol field related types ***/
+
+ typedef ip-version {
+ type enumeration {
+ enum unknown {
+ value "0";
+ description
+ "An unknown or unspecified version of the Internet protocol.";
+ }
+ enum ipv4 {
+ value "1";
+ description
+ "The IPv4 protocol as defined in RFC 791.";
+ }
+ enum ipv6 {
+ value "2";
+ description
+ "The IPv6 protocol as defined in RFC 2460.";
+ }
+ }
+ description
+ "This value represents the version of the IP protocol.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetVersion textual convention of the SMIv2.";
+ reference
+ "RFC 791: Internet Protocol
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ typedef dscp {
+ type uint8 {
+ range "0..63";
+ }
+ description
+ "The dscp type represents a Differentiated Services Code-Point
+ that may be used for marking packets in a traffic stream.
+
+ In the value set and its semantics, this type is equivalent
+ to the Dscp textual convention of the SMIv2.";
+ reference
+ "RFC 3289: Management Information Base for the Differentiated
+ Services Architecture
+ RFC 2474: Definition of the Differentiated Services Field
+ (DS Field) in the IPv4 and IPv6 Headers
+ RFC 2780: IANA Allocation Guidelines For Values In
+ the Internet Protocol and Related Headers";
+ }
+
+ typedef ipv6-flow-label {
+ type uint32 {
+ range "0..1048575";
+ }
+ description
+ "The flow-label type represents flow identifier or Flow Label
+ in an IPv6 packet header that may be used to discriminate
+ traffic flows.
+
+ In the value set and its semantics, this type is equivalent
+ to the IPv6FlowLabel textual convention of the SMIv2.";
+ reference
+ "RFC 3595: Textual Conventions for IPv6 Flow Label
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+ }
+
+ typedef port-number {
+ type uint16 {
+ range "0..65535";
+ }
+ description
+ "The port-number type represents a 16-bit port number of an
+ Internet transport layer protocol such as UDP, TCP, DCCP, or
+ SCTP. Port numbers are assigned by IANA. A current list of
+ all assignments is available from <http://www.iana.org/>.
+
+ Note that the port number value zero is reserved by IANA. In
+ situations where the value zero does not make sense, it can
+ be excluded by subtyping the port-number type.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetPortNumber textual convention of the SMIv2.";
+ reference
+ "RFC 768: User Datagram Protocol
+ RFC 793: Transmission Control Protocol
+ RFC 4960: Stream Control Transmission Protocol
+ RFC 4340: Datagram Congestion Control Protocol (DCCP)
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of autonomous system related types ***/
+
+ typedef as-number {
+ type uint32;
+ description
+ "The as-number type represents autonomous system numbers
+ which identify an Autonomous System (AS). An AS is a set
+ of routers under a single technical administration, using
+ an interior gateway protocol and common metrics to route
+ packets within the AS, and using an exterior gateway
+ protocol to route packets to other ASs'. IANA maintains
+ the AS number space and has delegated large parts to the
+ regional registries.
+
+ Autonomous system numbers were originally limited to 16
+ bits. BGP extensions have enlarged the autonomous system
+ number space to 32 bits. This type therefore uses an uint32
+ base type without a range restriction in order to support
+ a larger autonomous system number space.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetAutonomousSystemNumber textual convention of
+ the SMIv2.";
+ reference
+ "RFC 1930: Guidelines for creation, selection, and registration
+ of an Autonomous System (AS)
+ RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+ RFC 4893: BGP Support for Four-octet AS Number Space
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of IP address and hostname related types ***/
+
+ typedef ip-address {
+ type union {
+ type inet:ipv4-address;
+ type inet:ipv6-address;
+ }
+ description
+ "The ip-address type represents an IP address and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-address {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '(%[\p{N}\p{L}]+)?';
+ }
+ description
+ "The ipv4-address type represents an IPv4 address in
+ dotted-quad notation. The IPv4 address may include a zone
+ index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format for the zone index is the numerical
+ format";
+ }
+
+ typedef ipv6-address {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(%[\p{N}\p{L}]+)?';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(%.+)?';
+ }
+ description
+ "The ipv6-address type represents an IPv6 address in full,
+ mixed, shortened, and shortened-mixed notation. The IPv6
+ address may include a zone index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format of IPv6 addresses uses the compressed
+ format described in RFC 4291, Section 2.2, item 2 with the
+ following additional rules: the :: substitution must be
+ applied to the longest sequence of all-zero 16-bit chunks
+ in an IPv6 address. If there is a tie, the first sequence
+ of all-zero 16-bit chunks is replaced by ::. Single
+ all-zero 16-bit chunks are not compressed. The canonical
+ format uses lowercase characters and leading zeros are
+ not allowed. The canonical format for the zone index is
+ the numerical format as described in RFC 4007, Section
+ 11.2.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture
+ RFC 4007: IPv6 Scoped Address Architecture
+ RFC 5952: A Recommendation for IPv6 Address Text Representation";
+ }
+
+ typedef ip-prefix {
+ type union {
+ type inet:ipv4-prefix;
+ type inet:ipv6-prefix;
+ }
+ description
+ "The ip-prefix type represents an IP prefix and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-prefix {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+ }
+ description
+ "The ipv4-prefix type represents an IPv4 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal to 32.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The canonical format of an IPv4 prefix has all bits of
+ the IPv4 address set to zero that are not part of the
+ IPv4 prefix.";
+ }
+
+ typedef ipv6-prefix {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(/.+)';
+ }
+ description
+ "The ipv6-prefix type represents an IPv6 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal 128.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The IPv6 address should have all bits that do not belong
+ to the prefix set to zero.
+
+ The canonical format of an IPv6 prefix has all bits of
+ the IPv6 address set to zero that are not part of the
+ IPv6 prefix. Furthermore, IPv6 address is represented
+ in the compressed format described in RFC 4291, Section
+ 2.2, item 2 with the following additional rules: the ::
+ substitution must be applied to the longest sequence of
+ all-zero 16-bit chunks in an IPv6 address. If there is
+ a tie, the first sequence of all-zero 16-bit chunks is
+ replaced by ::. Single all-zero 16-bit chunks are not
+ compressed. The canonical format uses lowercase
+ characters and leading zeros are not allowed.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture";
+ }
+
+ /*** collection of domain name and URI types ***/
+
+ typedef domain-name {
+ type string {
+ pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+ + '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+ + '|\.';
+ length "1..253";
+ }
+ description
+ "The domain-name type represents a DNS domain name. The
+ name SHOULD be fully qualified whenever possible.
+
+ Internet domain names are only loosely specified. Section
+ 3.5 of RFC 1034 recommends a syntax (modified in Section
+ 2.1 of RFC 1123). The pattern above is intended to allow
+ for current practice in domain name use, and some possible
+ future expansion. It is designed to hold various types of
+ domain names, including names used for A or AAAA records
+ (host names) and other records, such as SRV records. Note
+ that Internet host names have a stricter syntax (described
+ in RFC 952) than the DNS recommendations in RFCs 1034 and
+ 1123, and that systems that want to store host names in
+ schema nodes using the domain-name type are recommended to
+ adhere to this stricter standard to ensure interoperability.
+
+ The encoding of DNS names in the DNS protocol is limited
+ to 255 characters. Since the encoding consists of labels
+ prefixed by a length bytes and there is a trailing NULL
+ byte, only 253 characters can appear in the textual dotted
+ notation.
+
+ The description clause of schema nodes using the domain-name
+ type MUST describe when and how these names are resolved to
+ IP addresses. Note that the resolution of a domain-name value
+ may require to query multiple DNS records (e.g., A for IPv4
+ and AAAA for IPv6). The order of the resolution process and
+ which DNS record takes precedence can either be defined
+ explicitely or it may depend on the configuration of the
+ resolver.
+
+ Domain-name values use the US-ASCII encoding. Their canonical
+ format uses lowercase US-ASCII characters. Internationalized
+ domain names MUST be encoded in punycode as described in RFC
+ 3492";
+ reference
+ "RFC 952: DoD Internet Host Table Specification
+ RFC 1034: Domain Names - Concepts and Facilities
+ RFC 1123: Requirements for Internet Hosts -- Application
+ and Support
+ RFC 2782: A DNS RR for specifying the location of services
+ (DNS SRV)
+ RFC 3492: Punycode: A Bootstring encoding of Unicode for
+ Internationalized Domain Names in Applications
+ (IDNA)
+ RFC 5891: Internationalizing Domain Names in Applications
+ (IDNA): Protocol";
+ }
+
+ typedef host {
+ type union {
+ type inet:ip-address;
+ type inet:domain-name;
+ }
+ description
+ "The host type represents either an IP address or a DNS
+ domain name.";
+ }
+
+ typedef uri {
+ type string;
+ description
+ "The uri type represents a Uniform Resource Identifier
+ (URI) as defined by STD 66.
+
+ Objects using the uri type MUST be in US-ASCII encoding,
+ and MUST be normalized as described by RFC 3986 Sections
+ 6.2.1, 6.2.2.1, and 6.2.2.2. All unnecessary
+ percent-encoding is removed, and all case-insensitive
+ characters are set to lowercase except for hexadecimal
+ digits, which are normalized to uppercase as described in
+ Section 6.2.2.1.
+
+ The purpose of this normalization is to help provide
+ unique URIs. Note that this normalization is not
+ sufficient to provide uniqueness. Two URIs that are
+ textually distinct after this normalization may still be
+ equivalent.
+
+ Objects using the uri type may restrict the schemes that
+ they permit. For example, 'data:' and 'urn:' schemes
+ might not be appropriate.
+
+ A zero-length URI is not a valid URI. This can be used to
+ express 'URI absent' where required.
+
+ In the value set and its semantics, this type is equivalent
+ to the Uri SMIv2 textual convention defined in RFC 5017.";
+ reference
+ "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+ RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+ Group: Uniform Resource Identifiers (URIs), URLs,
+ and Uniform Resource Names (URNs): Clarifications
+ and Recommendations
+ RFC 5017: MIB Textual Conventions for Uniform Resource
+ Identifiers (URIs)";
+ }
+
+ }
--- /dev/null
+ module ietf-yang-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
+ prefix "yang";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of counter and gauge types ***/
+
+ typedef counter32 {
+ type uint32;
+ description
+ "The counter32 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter32 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter32 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter32.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter32 {
+ type yang:counter32;
+ default "0";
+ description
+ "The zero-based-counter32 type represents a counter32
+ that has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter32 textual convention of the SMIv2.";
+ reference
+ "RFC 4502: Remote Network Monitoring Management Information
+ Base Version 2";
+ }
+
+ typedef counter64 {
+ type uint64;
+ description
+ "The counter64 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter64 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter64 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter64.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter64 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter64 {
+ type yang:counter64;
+ default "0";
+ description
+ "The zero-based-counter64 type represents a counter64 that
+ has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter64 textual convention of the SMIv2.";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ typedef gauge32 {
+ type uint32;
+ description
+ "The gauge32 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^32-1 (4294967295 decimal), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge32 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge32 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the Gauge32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef gauge64 {
+ type uint64;
+ description
+ "The gauge64 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^64-1 (18446744073709551615), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge64 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge64 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the CounterBasedGauge64 SMIv2 textual convention defined
+ in RFC 2856";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ /*** collection of identifier related types ***/
+
+ typedef object-identifier {
+ type string {
+ pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))'
+ + '(\.(0|([1-9]\d*)))*';
+ }
+ description
+ "The object-identifier type represents administratively
+ assigned names in a registration-hierarchical-name tree.
+
+ Values of this type are denoted as a sequence of numerical
+ non-negative sub-identifier values. Each sub-identifier
+ value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers
+ are separated by single dots and without any intermediate
+ whitespace.
+
+ The ASN.1 standard restricts the value space of the first
+ sub-identifier to 0, 1, or 2. Furthermore, the value space
+ of the second sub-identifier is restricted to the range
+ 0 to 39 if the first sub-identifier is 0 or 1. Finally,
+ the ASN.1 standard requires that an object identifier
+ has always at least two sub-identifier. The pattern
+ captures these restrictions.
+
+ Although the number of sub-identifiers is not limited,
+ module designers should realize that there may be
+ implementations that stick with the SMIv2 limit of 128
+ sub-identifiers.
+
+ This type is a superset of the SMIv2 OBJECT IDENTIFIER type
+ since it is not restricted to 128 sub-identifiers. Hence,
+ this type SHOULD NOT be used to represent the SMIv2 OBJECT
+ IDENTIFIER type, the object-identifier-128 type SHOULD be
+ used instead.";
+ reference
+ "ISO9834-1: Information technology -- Open Systems
+ Interconnection -- Procedures for the operation of OSI
+ Registration Authorities: General procedures and top
+ arcs of the ASN.1 Object Identifier tree";
+ }
+
+
+
+
+ typedef object-identifier-128 {
+ type object-identifier {
+ pattern '\d*(\.\d*){1,127}';
+ }
+ description
+ "This type represents object-identifiers restricted to 128
+ sub-identifiers.
+
+ In the value set and its semantics, this type is equivalent
+ to the OBJECT IDENTIFIER type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ /*** collection of date and time related types ***/
+
+ typedef date-and-time {
+ type string {
+ pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?'
+ + '(Z|[\+\-]\d{2}:\d{2})';
+ }
+ description
+ "The date-and-time type is a profile of the ISO 8601
+ standard for representation of dates and times using the
+ Gregorian calendar. The profile is defined by the
+ date-time production in Section 5.6 of RFC 3339.
+
+ The date-and-time type is compatible with the dateTime XML
+ schema type with the following notable exceptions:
+
+ (a) The date-and-time type does not allow negative years.
+
+ (b) The date-and-time time-offset -00:00 indicates an unknown
+ time zone (see RFC 3339) while -00:00 and +00:00 and Z all
+ represent the same time zone in dateTime.
+
+ (c) The canonical format (see below) of data-and-time values
+ differs from the canonical format used by the dateTime XML
+ schema type, which requires all times to be in UTC using the
+ time-offset 'Z'.
+
+ This type is not equivalent to the DateAndTime textual
+ convention of the SMIv2 since RFC 3339 uses a different
+ separator between full-date and full-time and provides
+ higher resolution of time-secfrac.
+
+ The canonical format for date-and-time values with a known time
+ zone uses a numeric time zone offset that is calculated using
+ the device's configured known offset to UTC time. A change of
+ the device's offset to UTC time will cause date-and-time values
+ to change accordingly. Such changes might happen periodically
+ in case a server follows automatically daylight saving time
+ (DST) time zone offset changes. The canonical format for
+ date-and-time values with an unknown time zone (usually referring
+ to the notion of local time) uses the time-offset -00:00.";
+ reference
+ "RFC 3339: Date and Time on the Internet: Timestamps
+ RFC 2579: Textual Conventions for SMIv2
+ XSD-TYPES: XML Schema Part 2: Datatypes Second Edition";
+ }
+
+ typedef timeticks {
+ type uint32;
+ description
+ "The timeticks type represents a non-negative integer that
+ represents the time, modulo 2^32 (4294967296 decimal), in
+ hundredths of a second between two epochs. When a schema
+ node is defined that uses this type, the description of
+ the schema node identifies both of the reference epochs.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeTicks type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef timestamp {
+ type yang:timeticks;
+ description
+ "The timestamp type represents the value of an associated
+ timeticks schema node at which a specific occurrence happened.
+ The specific occurrence must be defined in the description
+ of any schema node defined using this type. When the specific
+ occurrence occurred prior to the last time the associated
+ timeticks attribute was zero, then the timestamp value is
+ zero. Note that this requires all timestamp values to be
+ reset to zero when the value of the associated timeticks
+ attribute reaches 497+ days and wraps around to zero.
+
+ The associated timeticks schema node must be specified
+ in the description of any schema node using this type.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeStamp textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of generic address types ***/
+
+ typedef phys-address {
+ type string {
+ pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?';
+ }
+ description
+ "Represents media- or physical-level addresses represented
+ as a sequence octets, each octet represented by two hexadecimal
+ numbers. Octets are separated by colons. The canonical
+ representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the PhysAddress textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ typedef mac-address {
+ type string {
+ pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}';
+ }
+ description
+ "The mac-address type represents an IEEE 802 MAC address.
+ The canonical representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the MacAddress textual convention of the SMIv2.";
+ reference
+ "IEEE 802: IEEE Standard for Local and Metropolitan Area
+ Networks: Overview and Architecture
+ RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of XML specific types ***/
+
+ typedef xpath1.0 {
+ type string;
+ description
+ "This type represents an XPATH 1.0 expression.
+
+ When a schema node is defined that uses this type, the
+ description of the schema node MUST specify the XPath
+ context in which the XPath expression is evaluated.";
+ reference
+ "XPATH: XML Path Language (XPath) Version 1.0";
+ }
+
+ }
\ No newline at end of file
--- /dev/null
+module simple-bits-demo {
+
+ namespace "urn:simple:bits:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-11 {
+
+ }
+
+ typedef byte-type {
+ type bits {
+ bit first-bit {
+ position 10;
+ }
+ bit second-bit {
+ position 20;
+ }
+ bit third-bit {
+ position 30;
+ }
+ bit forth-bit {
+ position 40;
+ }
+ bit fifth-bit {
+ position 50;
+ }
+ bit sixth-bit {
+ position 60;
+ }
+ bit seventh-bit {
+ position 70;
+ }
+ bit eight-bit {
+ position 80;
+ }
+
+ }
+
+ typedef jo {
+ type uint32;
+ }
+
+
+ container leaf-parent-container {
+ leaf byte-leaf {
+ type byte-type;
+ }
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module simple-string-demo {
+
+ namespace "urn:simple:string:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-18 {
+
+ }
+
+
+ typedef typedef-string {
+ type string {
+ length "40";
+ pattern "[0-9A-F]*";
+ pattern "[B-D]*";
+ pattern "[4-7]*";
+ }
+ }
+
+}
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-generator-spi</artifactId>\r
<dependencies>\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-generator-util</artifactId>\r
<dependencies>\r
return name;\r
}\r
\r
+ @Override\r
+ public String getFullyQualifiedName() {\r
+ if (packageName.isEmpty()) {\r
+ return name;\r
+ } else {\r
+ return packageName + "." + name;\r
+ }\r
+ }\r
+\r
protected AbstractBaseType(String pkName, String name) {\r
this.packageName = pkName;\r
this.name = name;\r
}\r
return "Type (" + packageName + "." + name + ")";\r
}\r
-\r
}\r
package org.opendaylight.controller.binding.generator.util;
+import java.util.*;
+
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
-import java.util.*;
-
public final class BindingGeneratorUtil {
- private static final String[] SET_VALUES = new String[]{"abstract",
- "assert", "boolean", "break", "byte", "case", "catch", "char",
- "class", "const", "continue", "default", "double", "do", "else",
- "enum", "extends", "false", "final", "finally", "float", "for",
- "goto", "if", "implements", "import", "instanceof", "int",
- "interface", "long", "native", "new", "null", "package", "private",
- "protected", "public", "return", "short", "static", "strictfp",
- "super", "switch", "synchronized", "this", "throw", "throws",
- "transient", "true", "try", "void", "volatile", "while"};
+ private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",
+ "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",
+ "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
+ "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
+ "true", "try", "void", "volatile", "while" };
private BindingGeneratorUtil() {
}
- public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(
- Arrays.asList(SET_VALUES));
+ public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));
public static String validateJavaPackage(final String packageName) {
if (packageName != null) {
return parameterName;
}
- public static GeneratedTOBuilder schemaNodeToTransferObjectBuilder(
- final String packageName, final SchemaNode schemaNode,
- final String transObjectName) {
- if (packageName != null && schemaNode != null
- && transObjectName != null) {
+ public static GeneratedTOBuilder schemaNodeToTransferObjectBuilder(final String packageName,
+ final SchemaNode schemaNode, final String transObjectName) {
+ if (packageName != null && schemaNode != null && transObjectName != null) {
- final String genTOName = BindingGeneratorUtil
- .parseToClassName(transObjectName);
- final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl(
- packageName, genTOName);
+ final String genTOName = BindingGeneratorUtil.parseToClassName(transObjectName);
+ final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl(packageName, genTOName);
return newType;
return null;
}
- public static String moduleNamespaceToPackageName(
- final Module module) {
+ public static String moduleNamespaceToPackageName(final Module module) {
final StringBuilder packageNameBuilder = new StringBuilder();
final Calendar calendar = Calendar.getInstance();
if (module.getRevision() == null) {
- throw new IllegalArgumentException("Module " + module.getName()
- + " does not specify revision date!");
+ throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");
}
packageNameBuilder.append("org.opendaylight.yang.gen.v");
packageNameBuilder.append(module.getYangVersion());
return validateJavaPackage(packageNameBuilder.toString());
}
- public static String packageNameForGeneratedType(
- final String basePackageName, final SchemaPath schemaPath) {
+ public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {
if (basePackageName == null) {
- throw new IllegalArgumentException("Base Package Name cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
}
if (schemaPath == null) {
throw new IllegalArgumentException("Schema Path cannot be NULL!");
return validateJavaPackage(builder.toString());
}
- public static String packageNameForTypeDefinition(
- final String basePackageName, final TypeDefinition<?> typeDefinition) {
+ public static String packageNameForTypeDefinition(final String basePackageName,
+ final TypeDefinition<?> typeDefinition) {
if (basePackageName == null) {
- throw new IllegalArgumentException("Base Package Name cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
}
if (typeDefinition == null) {
- throw new IllegalArgumentException("Type Definition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definition reference cannot be NULL!");
}
final StringBuilder builder = new StringBuilder();
return validateParameterName(correctStr);
}
+ public static String convertToCapitalLetters(final String token) {
+ String convertedStr = token.replace(" ", "_");
+ convertedStr = convertedStr.replace(".", "_");
+ convertedStr = convertedStr.toUpperCase();
+ return convertedStr;
+ }
+
private static String parseToCamelCase(String token) {
if (token == null) {
throw new NullPointerException("Name can not be null");
// check if 'toBeRemoved' character is not the only character in
// 'text'
if (sb.length() == 0) {
- throw new IllegalArgumentException("Name can not be '"
- + toBeRemoved + "'");
+ throw new IllegalArgumentException("Name can not be '" + toBeRemoved + "'");
}
- String replacement = String.valueOf(sb.charAt(toBeRemovedPos))
- .toUpperCase();
+ String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();
sb.setCharAt(toBeRemovedPos, replacement.charAt(0));
toBeRemovedPos = sb.indexOf(toBeRemoved);
}
*/
package org.opendaylight.controller.binding.generator.util;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+public final class ReferencedTypeImpl extends AbstractBaseType {
-
-public final class ReferencedTypeImpl implements Type {
-
- private final String packageName;
- private final String name;
-
public ReferencedTypeImpl(String packageName, String name) {
- super();
- this.packageName = packageName;
- this.name = name;
- }
-
- /* (non-Javadoc)
- * @see org.opendaylight.controller.sal.binding.model.api.Type#getPackageName()
- */
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- /* (non-Javadoc)
- * @see org.opendaylight.controller.sal.binding.model.api.Type#getName()
- */
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ReferencedTypeImpl other = (ReferencedTypeImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
+ super(packageName, name);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ReferencedTypeImpl [packageName=");
- builder.append(packageName);
+ builder.append(getPackageName());
builder.append(", name=");
- builder.append(name);
+ builder.append(getName());
builder.append("]");
return builder.toString();
}
--- /dev/null
+package org.opendaylight.controller.binding.generator.util;
+
+public final class TypeConstants {
+
+ public static final String PATTERN_CONSTANT_NAME = "PATTERN_CONSTANTS";
+
+ private TypeConstants() {
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
+import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType {
+
+ private final Type parent;
+ private final String comment;
+ private final List<AnnotationType> annotations;
+ private final List<Type> implementsTypes;
+ private final List<Enumeration> enumerations;
+ private final List<Constant> constants;
+ private final List<MethodSignature> methodSignatures;
+ private final List<GeneratedType> enclosedTypes;
+ private final boolean isAbstract;
+
+ public AbstractGeneratedType(final Type parent, final String packageName, final String name, final String comment,
+ final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
+ final List<Type> implementsTypes, final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders, final List<EnumBuilder> enumBuilders,
+ final List<Constant> constants, final List<MethodSignatureBuilder> methodBuilders) {
+ super(packageName, name);
+ this.parent = parent;
+ this.comment = comment;
+ this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+ this.implementsTypes = Collections.unmodifiableList(implementsTypes);
+ this.constants = Collections.unmodifiableList(constants);
+ this.enumerations = toUnmodifiableEnumerations(enumBuilders);
+ this.methodSignatures = toUnmodifiableMethods(methodBuilders);
+ this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders);
+ this.isAbstract = isAbstract;
+ }
+
+ private List<GeneratedType> toUnmodifiableEnclosedTypes(final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
+ final List<GeneratedType> enclosedTypes = new ArrayList<>();
+ for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) {
+ if (builder != null) {
+ enclosedTypes.add(builder.toInstance());
+ }
+ }
+
+ for (final GeneratedTOBuilder builder : enclosedGenTOBuilders) {
+ if (builder != null) {
+ enclosedTypes.add(builder.toInstance());
+ }
+ }
+ return enclosedTypes;
+ }
+
+ protected List<AnnotationType> toUnmodifiableAnnotations(final List<AnnotationTypeBuilder> annotationBuilders) {
+ final List<AnnotationType> annotations = new ArrayList<>();
+ for (final AnnotationTypeBuilder builder : annotationBuilders) {
+ annotations.add(builder.toInstance());
+ }
+ return Collections.unmodifiableList(annotations);
+ }
+
+ protected List<MethodSignature> toUnmodifiableMethods(List<MethodSignatureBuilder> methodBuilders) {
+ final List<MethodSignature> methods = new ArrayList<>();
+ for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
+ methods.add(methodBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(methods);
+ }
+
+ protected List<Enumeration> toUnmodifiableEnumerations(List<EnumBuilder> enumBuilders) {
+ final List<Enumeration> enums = new ArrayList<>();
+ for (final EnumBuilder enumBuilder : enumBuilders) {
+ enums.add(enumBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(enums);
+ }
+
+ @Override
+ public Type getParentType() {
+ return parent;
+ }
+
+ @Override
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public List<AnnotationType> getAnnotations() {
+ return annotations;
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ @Override
+ public List<Type> getImplements() {
+ return implementsTypes;
+ }
+
+ @Override
+ public List<GeneratedType> getEnclosedTypes() {
+ return enclosedTypes;
+ }
+
+ @Override
+ public List<Enumeration> getEnumerations() {
+ return enumerations;
+ }
+
+ @Override
+ public List<Constant> getConstantDefinitions() {
+ return constants;
+ }
+
+ @Override
+ public List<MethodSignature> getMethodDefinitions() {
+ return methodSignatures;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedType [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ if (parent != null) {
+ builder.append(", parent=");
+ builder.append(parent.getFullyQualifiedName());
+ } else {
+ builder.append(", parent=null");
+ }
+ builder.append(", comment=");
+ builder.append(comment);
+ builder.append(", annotations=");
+ builder.append(annotations);
+ builder.append(", enclosedTypes=");
+ builder.append(enclosedTypes);
+ builder.append(", enumerations=");
+ builder.append(enumerations);
+ builder.append(", constants=");
+ builder.append(constants);
+ builder.append(", methodSignatures=");
+ builder.append(methodSignatures);
+ builder.append("]");
+ return builder.toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+abstract class AbstractGeneratedTypeBuilder extends AbstractBaseType implements GeneratedTypeBuilder {
+
+ private final String packageName;
+ private String comment = "";
+ private final String name;
+
+ private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
+ private final List<Type> implementsTypes = new ArrayList<>();
+ private final List<EnumBuilder> enumDefinitions = new ArrayList<>();
+ private final List<Constant> constants = new ArrayList<>();
+ private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<>();
+ private final List<GeneratedTypeBuilder> enclosedTypes = new ArrayList<>();
+ private final List<GeneratedTOBuilder> enclosingTransferObjects = new ArrayList<>();
+ private boolean isAbstract;
+
+ public AbstractGeneratedTypeBuilder(final String packageName, final String name) {
+ super(packageName, name);
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of Generated Type cannot be null!");
+ }
+ this.packageName = packageName;
+ this.name = name;
+ }
+
+ protected String getComment() {
+ return comment;
+ }
+
+ protected List<AnnotationTypeBuilder> getAnnotations() {
+ return annotationBuilders;
+ }
+
+ protected boolean isAbstract() {
+ return isAbstract;
+ }
+
+ protected List<Type> getImplementsTypes() {
+ return implementsTypes;
+ }
+
+ protected List<EnumBuilder> getEnumerations() {
+ return enumDefinitions;
+ }
+
+ protected List<Constant> getConstants() {
+ return constants;
+ }
+
+ protected List<MethodSignatureBuilder> getMethodDefinitions() {
+ return methodDefinitions;
+ }
+
+ protected List<GeneratedTypeBuilder> getEnclosedTypes() {
+ return enclosedTypes;
+ }
+
+ protected List<GeneratedTOBuilder> getEnclosedTransferObjects() {
+ return enclosingTransferObjects;
+ }
+
+ @Override
+ public GeneratedTypeBuilder addEnclosingType(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name for Enclosing Generated Type cannot be null!");
+ }
+ GeneratedTypeBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
+ enclosedTypes.add(builder);
+ return builder;
+ }
+
+ @Override
+ public GeneratedTOBuilder addEnclosingTransferObject(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name for Enclosing Generated Transfer Object cannot be null!");
+ }
+ GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
+ enclosingTransferObjects.add(builder);
+ return builder;
+ }
+
+ @Override
+ public void addComment(String comment) {
+ this.comment = comment;
+ }
+
+ @Override
+ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Annotation Type cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of Annotation Type cannot be null!");
+ }
+
+ final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
+ annotationBuilders.add(builder);
+ return builder;
+ }
+
+ @Override
+ public void setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
+ }
+
+ @Override
+ public boolean addImplementsType(Type genType) {
+ if (genType == null) {
+ throw new IllegalArgumentException("Type cannot be null");
+ }
+ return implementsTypes.add(genType);
+ }
+
+ @Override
+ public Constant addConstant(Type type, String name, Object value) {
+ if (type == null) {
+ throw new IllegalArgumentException("Returning Type for Constant cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of constant cannot be null!");
+ }
+
+ final Constant constant = new ConstantImpl(this, type, name, value);
+ constants.add(constant);
+ return constant;
+ }
+
+ @Override
+ public EnumBuilder addEnumeration(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name of enumeration cannot be null!");
+ }
+ final EnumBuilder builder = new EnumerationBuilderImpl(
+ getFullyQualifiedName(), name);
+ enumDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public MethodSignatureBuilder addMethod(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name of method cannot be null!");
+ }
+ final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name);
+ builder.setAccessModifier(AccessModifier.PUBLIC);
+ builder.setAbstract(true);
+ methodDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getPackageName() == null) ? 0 : getPackageName().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getPackageName() == null) {
+ if (other.getPackageName() != null) {
+ return false;
+ }
+ } else if (!getPackageName().equals(other.getPackageName())) {
+ return false;
+ }
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.TypeMember;
+
+import java.util.Collections;
+import java.util.List;
+
+abstract class AbstractTypeMember implements TypeMember {
+
+ private final String name;
+ private final String comment;
+ private final Type definingType;
+ private final Type returnType;
+ private final List<AnnotationType> annotations;
+ private final boolean isFinal;
+ private final AccessModifier accessModifier;
+
+ public AbstractTypeMember(final Type definingType, final String name, final List<AnnotationType> annotations,
+ final String comment, final AccessModifier accessModifier, final Type returnType,
+ boolean isFinal) {
+ super();
+ this.definingType = definingType;
+ this.name = name;
+ this.annotations = Collections.unmodifiableList(annotations);
+ this.comment = comment;
+ this.accessModifier = accessModifier;
+ this.returnType = returnType;
+ this.isFinal = isFinal;
+ }
+
+ @Override
+ public List<AnnotationType> getAnnotations() {
+ return annotations;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public Type getDefiningType() {
+ return definingType;
+ }
+
+ @Override
+ public AccessModifier getAccessModifier() {
+ return accessModifier;
+ }
+
+ @Override
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureImpl other = (MethodSignatureImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodSignatureImpl [name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", definingType=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append("]");
+ return builder.toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.TypeMemberBuilder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+abstract class AbstractTypeMemberBuilder implements TypeMemberBuilder {
+ private final String name;
+ private Type returnType;
+ private final List<AnnotationTypeBuilder> annotationBuilders;
+ private String comment = "";
+ private boolean isFinal;
+ private AccessModifier accessModifier;
+
+ public AbstractTypeMemberBuilder(final String name) {
+ this.name = name;
+ this.annotationBuilders = new ArrayList<>();
+ }
+
+ @Override
+ public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
+ if (packageName == null) {
+ throw new IllegalArgumentException("Annotation Type cannot have package name null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Annotation Type cannot have name as null!");
+ }
+ final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
+ packageName, name);
+ annotationBuilders.add(builder);
+ return builder;
+ }
+
+ protected Type getReturnType() {
+ return returnType;
+ }
+
+ protected List<AnnotationTypeBuilder> getAnnotationBuilders() {
+ return annotationBuilders;
+ }
+
+ protected String getComment() {
+ return comment;
+ }
+
+ protected boolean isFinal() {
+ return isFinal;
+ }
+
+ protected AccessModifier getAccessModifier() {
+ return accessModifier;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setReturnType(Type returnType) {
+ if (returnType == null) {
+ throw new IllegalArgumentException("Return Type of member cannot be null!");
+ }
+ this.returnType = returnType;
+ }
+
+ @Override
+ public void setAccessModifier(AccessModifier modifier) {
+ if (modifier == null) {
+ throw new IllegalArgumentException("Access Modifier for member type cannot be null!");
+ }
+ this.accessModifier = modifier;
+ }
+
+ @Override
+ public void setComment(String comment) {
+ if (comment == null) {
+ this.comment = "";
+ }
+ this.comment = comment;
+ }
+
+ @Override
+ public void setFinal(boolean isFinal) {
+ this.isFinal = isFinal;
+ }
+
+ protected List<AnnotationType> toAnnotationTypes() {
+ final List<AnnotationType> annotations = new ArrayList<>();
+ for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
+ if (annotBuilder != null) {
+ annotations.add(annotBuilder.toInstance());
+ }
+ }
+ return annotations;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotationBuilders());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
-final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder {
+final class AnnotationTypeBuilderImpl extends AbstractBaseType implements AnnotationTypeBuilder {
private final String packageName;
private final String name;
private final List<AnnotationType.Parameter> parameters;
public AnnotationTypeBuilderImpl(final String packageName, final String name) {
- super();
+ super(packageName, name);
this.packageName = packageName;
this.name = name;
-
- annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- parameters = new ArrayList<AnnotationType.Parameter>();
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
+ annotationBuilders = new ArrayList<>();
+ parameters = new ArrayList<>();
}
@Override
this.packageName = packageName;
this.name = name;
- this.annotations = new ArrayList<AnnotationType>();
+ this.annotations = new ArrayList<>();
for (final AnnotationTypeBuilder builder : annotationBuilders) {
annotations.add(builder.toInstance());
}
this.annotations = Collections.unmodifiableList(annotations);
this.parameters = Collections.unmodifiableList(parameters);
- paramNames = new ArrayList<String>();
+ paramNames = new ArrayList<>();
for (final AnnotationType.Parameter parameter : parameters) {
paramNames.add(parameter.getName());
}
return name;
}
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public List<AnnotationType> getAnnotations() {
return annotations;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.binding.generator.util.generated.type.builder;
-
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-
-final class ConstantBuilderImpl implements ConstantBuilder {
-
- private final Type type;
- private final String name;
- private Object value;
-
- public ConstantBuilderImpl(Type type, String name, Object value) {
- super();
- this.type = type;
- this.name = name;
- this.value = value;
- }
-
- public ConstantBuilderImpl(Type type, String name) {
- super();
- this.type = type;
- this.name = name;
- }
-
- @Override
- public void assignValue(Object value) {
- this.value = value;
- }
-
- @Override
- public Constant toInstance(final Type definingType) {
- return new ConstantImpl(definingType, type, name, value);
- }
-
- private static final class ConstantImpl implements Constant {
-
- final Type definingType;
- private final Type type;
- private final String name;
- private final Object value;
-
- public ConstantImpl(final Type definingType, final Type type,
- final String name, final Object value) {
- super();
- this.definingType = definingType;
- this.type = type;
- this.name = name;
- this.value = value;
- }
-
- @Override
- public Type getDefiningType() {
- return definingType;
- }
-
- @Override
- public Type getType() {
- return type;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Object getValue() {
- return value;
- }
-
- @Override
- public String toFormattedString() {
- StringBuilder builder = new StringBuilder();
- builder.append(type);
- builder.append(" ");
- builder.append(name);
- builder.append(" ");
- builder.append(value);
- return builder.toString();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ConstantImpl other = (ConstantImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (value == null) {
- if (other.value != null) {
- return false;
- }
- } else if (!value.equals(other.value)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Constant [type=");
- builder.append(type);
- builder.append(", name=");
- builder.append(name);
- builder.append(", value=");
- builder.append(value);
- if (definingType != null) {
- builder.append(", definingType=");
- builder.append(definingType.getPackageName());
- builder.append(".");
- builder.append(definingType.getName());
- } else {
- builder.append(", definingType= null");
- }
- builder.append("]");
- return builder.toString();
- }
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+final class ConstantImpl implements Constant {
+
+ final Type definingType;
+ private final Type type;
+ private final String name;
+ private final Object value;
+
+ public ConstantImpl(final Type definingType, final Type type,
+ final String name, final Object value) {
+ super();
+ this.definingType = definingType;
+ this.type = type;
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public Type getDefiningType() {
+ return definingType;
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public String toFormattedString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(type);
+ builder.append(" ");
+ builder.append(name);
+ builder.append(" ");
+ builder.append(value);
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ConstantImpl other = (ConstantImpl) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (type == null) {
+ if (other.type != null) {
+ return false;
+ }
+ } else if (!type.equals(other.type)) {
+ return false;
+ }
+ if (value == null) {
+ if (other.value != null) {
+ return false;
+ }
+ } else if (!value.equals(other.value)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Constant [type=");
+ builder.append(type);
+ builder.append(", name=");
+ builder.append(name);
+ builder.append(", value=");
+ builder.append(value);
+ if (definingType != null) {
+ builder.append(", definingType=");
+ builder.append(definingType.getPackageName());
+ builder.append(".");
+ builder.append(definingType.getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+}
import java.util.Collections;
import java.util.List;
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.Enumeration;
import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
-public final class EnumerationBuilderImpl implements EnumBuilder {
+public final class EnumerationBuilderImpl extends AbstractBaseType implements EnumBuilder {
private final String packageName;
private final String name;
private final List<Enumeration.Pair> values;
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+ private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
public EnumerationBuilderImpl(final String packageName, final String name) {
- super();
+ super(packageName, name);
this.packageName = packageName;
this.name = name;
- values = new ArrayList<Enumeration.Pair>();
- }
-
- @Override
- public String getPackageName() {
- return packageName;
+ values = new ArrayList<>();
}
- @Override
- public String getName() {
- return name;
- }
-
@Override
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
if (packageName != null && name != null) {
private final String packageName;
private final String name;
private final List<Pair> values;
- private List<AnnotationType> annotations = new ArrayList<AnnotationType>();
+ private List<AnnotationType> annotations = new ArrayList<>();
public EnumerationImpl(final Type definingType,
final List<AnnotationTypeBuilder> annotationBuilders,
return name;
}
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public List<Pair> getValues() {
return values;
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+
+import java.util.List;
+
+final class GeneratedPropertyBuilderImpl extends AbstractTypeMemberBuilder implements GeneratedPropertyBuilder {
+
+ private boolean isReadOnly;
+
+ public GeneratedPropertyBuilderImpl(String name) {
+ super(name);
+ this.isReadOnly = true;
+ }
+
+ @Override
+ public void setReadOnly(boolean isReadOnly) {
+ this.isReadOnly = isReadOnly;
+ }
+
+ @Override
+ public GeneratedProperty toInstance(Type definingType) {
+ final List<AnnotationType> annotations = toAnnotationTypes();
+ return new GeneratedPropertyImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
+ getReturnType(), isFinal(), isReadOnly);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotationBuilders());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", isReadOnly=");
+ builder.append(isReadOnly);
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+import java.util.List;
+
+final class GeneratedPropertyImpl extends AbstractTypeMember implements GeneratedProperty {
+
+ private boolean isReadOnly;
+
+ public GeneratedPropertyImpl(Type definingType, String name, List<AnnotationType> annotations, String comment,
+ AccessModifier accessModifier, Type returnType, boolean isFinal, boolean isReadOnly) {
+ super(definingType, name, annotations, comment, accessModifier, returnType, isFinal);
+ this.isReadOnly = isReadOnly;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return isReadOnly;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", parent=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", parent=null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", isReadOnly=");
+ builder.append(isReadOnly);
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
*/
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
-import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-
-public class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
- private String packageName;
- private final String name;
- private String comment = "";
+public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder {
private GeneratedTransferObject extendsType;
- private final List<Type> implementsTypes = new ArrayList<Type>();
- private final List<EnumBuilder> enumerations = new ArrayList<EnumBuilder>();
- private final List<GeneratedPropertyBuilder> properties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<GeneratedPropertyBuilder>();
-
- private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();
- private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+ private final List<GeneratedPropertyBuilder> properties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<>();
public GeneratedTOBuilderImpl(String packageName, String name) {
- super();
- this.packageName = packageName;
- this.name = name;
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void addComment(final String comment) {
- this.comment = comment;
- }
-
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public boolean addImplementsType(final Type genType) {
- if (genType != null) {
- return implementsTypes.add(genType);
- }
- return false;
+ super(packageName, name);
+ setAbstract(false);
}
@Override
- public boolean addExtendsType(final GeneratedTransferObject genTransObj) {
- if (genTransObj != null) {
- extendsType = genTransObj;
- return true;
+ public void setExtendsType(final GeneratedTransferObject genTransObj) {
+ if (genTransObj == null) {
+ throw new IllegalArgumentException("Generated Transfer Object cannot be null!");
}
- return false;
- }
-
- @Override
- public EnumBuilder addEnumeration(String name) {
- final String innerPackageName = packageName + "." + this.name;
- final EnumBuilder builder = new EnumerationBuilderImpl(innerPackageName,
- name);
- enumerations.add(builder);
- return builder;
+ extendsType = genTransObj;
}
@Override
- public ConstantBuilder addConstant(Type type, String name, Object value) {
- final ConstantBuilder builder = new ConstantBuilderImpl(type, name,
- value);
- constantDefintions.add(builder);
+ public GeneratedPropertyBuilder addProperty(String name) {
+ final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
+ builder.setAccessModifier(AccessModifier.PUBLIC);
+ properties.add(builder);
return builder;
}
+ /**
+ * Add new Method Signature definition for Generated Type Builder and
+ * returns Method Signature Builder for specifying all Method parameters.
+ * <br>
+ * Name of Method cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ * <br>
+ * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
+ * {@link MethodSignatureBuilder#setAbstract(false)}, {@link MethodSignatureBuilder#setFinal(false)} and
+ * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}
+ *
+ * @param name Name of Method
+ * @return <code>new</code> instance of Method Signature Builder.
+ */
@Override
public MethodSignatureBuilder addMethod(String name) {
- final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(
- this, name);
- methodDefinitions.add(builder);
- return builder;
- }
-
- @Override
- public GeneratedPropertyBuilder addProperty(String name) {
- final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(
- name);
- properties.add(builder);
+ final MethodSignatureBuilder builder = super.addMethod(name);
+ builder.setAbstract(false);
return builder;
}
@Override
public GeneratedTransferObject toInstance() {
- return new GeneratedTransferObjectImpl(packageName, name, comment,
- annotationBuilders, extendsType, implementsTypes,
- constantDefintions, enumerations, methodDefinitions,
- properties, equalsProperties, hashProperties,
- toStringProperties);
- }
-
- @Override
- public GeneratedTransferObject toIdentityInstance() {
- return new GeneratedTransferIdentityObjectImpl(packageName, name, comment,
- annotationBuilders, extendsType, implementsTypes,
- constantDefintions, enumerations, methodDefinitions,
- properties, equalsProperties, hashProperties,
- toStringProperties);
- }
-
- private static final class GeneratedPropertyBuilderImpl implements
- GeneratedPropertyBuilder {
-
- private final String name;
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- private Type returnType;
- private final List<MethodSignature.Parameter> parameters;
- private String comment = "";
- private AccessModifier accessModifier;
- private boolean isFinal;
- private boolean isReadOnly;
-
- public GeneratedPropertyBuilderImpl(final String name) {
- super();
- this.name = name;
- parameters = new ArrayList<MethodSignature.Parameter>();
- isFinal = true;
- this.isReadOnly = true;
- accessModifier = AccessModifier.PUBLIC;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName,
- String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public boolean addReturnType(Type returnType) {
- if (returnType != null) {
- this.returnType = returnType;
- this.parameters.add(new MethodParameterImpl(name, returnType));
- return true;
- }
- return false;
- }
-
- @Override
- public void accessorModifier(final AccessModifier modifier) {
- accessModifier = modifier;
- }
-
- @Override
- public void addComment(String comment) {
- if (comment != null) {
- this.comment = comment;
- }
- }
-
- @Override
- public void setFinal(boolean isFinal) {
- this.isFinal = isFinal;
- }
-
- @Override
- public void setReadOnly(boolean isReadOnly) {
- this.isReadOnly = isReadOnly;
- }
-
- @Override
- public GeneratedProperty toInstance(final Type definingType) {
- return new GeneratedPropertyImpl(name, comment, annotationBuilders,
- definingType, returnType, isFinal, isReadOnly, parameters,
- accessModifier);
- }
- }
-
- private static final class GeneratedPropertyImpl implements
- GeneratedProperty {
-
- private final String name;
- private List<AnnotationType> annotations;
- private final String comment;
- private final Type parent;
- private final Type returnType;
- private final boolean isFinal;
- private final boolean isReadOnly;
- private final List<MethodSignature.Parameter> parameters;
- private final AccessModifier modifier;
-
- public GeneratedPropertyImpl(final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final Type parent, final Type returnType,
- final boolean isFinal, final boolean isReadOnly,
- final List<Parameter> parameters, final AccessModifier modifier) {
- super();
- this.name = name;
- this.annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- this.annotations.add(builder.toInstance());
- }
- this.annotations = Collections.unmodifiableList(this.annotations);
- this.comment = comment;
- this.parent = parent;
- this.returnType = returnType;
- this.isFinal = isFinal;
- this.isReadOnly = isReadOnly;
- this.parameters = Collections.unmodifiableList(parameters);
- this.modifier = modifier;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public Type getDefiningType() {
- return parent;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public Type getReturnType() {
- return returnType;
- }
-
- @Override
- public List<Parameter> getParameters() {
- return parameters;
- }
-
- @Override
- public AccessModifier getAccessModifier() {
- return modifier;
- }
-
- @Override
- public boolean isReadOnly() {
- return isReadOnly;
- }
-
- @Override
- public boolean isFinal() {
- return isFinal;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((parameters == null) ? 0 : parameters.hashCode());
- result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedPropertyImpl other = (GeneratedPropertyImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (parameters == null) {
- if (other.parameters != null) {
- return false;
- }
- } else if (!parameters.equals(other.parameters)) {
- return false;
- }
- if (returnType == null) {
- if (other.returnType != null) {
- return false;
- }
- } else if (!returnType.getPackageName().equals(
- other.returnType.getPackageName())) {
- return false;
- } else if (!returnType.getName().equals(other.returnType.getName())) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedPropertyImpl [name=");
- builder.append(name);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append(", comment=");
- builder.append(comment);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
- builder.append(", returnType=");
- builder.append(returnType);
- builder.append(", isFinal=");
- builder.append(isFinal);
- builder.append(", isReadOnly=");
- builder.append(isReadOnly);
- builder.append(", parameters=");
- builder.append(parameters);
- builder.append(", modifier=");
- builder.append(modifier);
- builder.append("]");
- return builder.toString();
- }
- }
-
- private static class GeneratedTransferObjectImpl implements
+ return new GeneratedTransferObjectImpl(null, getPackageName(), getName(), getComment(),
+ getAnnotations(), isAbstract(), extendsType, getImplementsTypes(), getEnclosedTypes(),
+ getEnclosedTransferObjects(), getConstants(), getEnumerations(), getMethodDefinitions(), properties,
+ equalsProperties, hashProperties, toStringProperties);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedTransferObject [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", constants=");
+ builder.append(getConstants());
+ builder.append(", enumerations=");
+ builder.append(getEnumerations());
+ builder.append(", properties=");
+ builder.append(properties);
+ builder.append(", equalsProperties=");
+ builder.append(equalsProperties);
+ builder.append(", hashCodeProperties=");
+ builder.append(hashProperties);
+ builder.append(", stringProperties=");
+ builder.append(toStringProperties);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(", methods=");
+ builder.append(getMethodDefinitions());
+ builder.append("]");
+ return builder.toString();
+ }
+
+ private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements
GeneratedTransferObject {
- private final String packageName;
- private final String name;
- private final String comment;
- private final List<Constant> constants;
- private final List<Enumeration> enumerations;
private final List<GeneratedProperty> properties;
private final List<GeneratedProperty> equalsProperties;
private final List<GeneratedProperty> hashCodeProperties;
private final List<GeneratedProperty> stringProperties;
- private final List<AnnotationType> annotations;
- private final List<MethodSignature> methods;
private final GeneratedTransferObject extendsType;
- private final List<Type> implementsTypes;
- public GeneratedTransferObjectImpl(final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final GeneratedTransferObject extendsType,
- final List<Type> implementsTypes,
- final List<ConstantBuilder> constantBuilders,
- final List<EnumBuilder> enumBuilders,
- final List<MethodSignatureBuilder> methodBuilders,
- final List<GeneratedPropertyBuilder> propBuilers,
- final List<GeneratedPropertyBuilder> equalsBuilers,
- final List<GeneratedPropertyBuilder> hashCodeBuilers,
- final List<GeneratedPropertyBuilder> stringBuilers) {
- super();
- this.packageName = packageName;
- this.name = name;
- this.comment = comment;
- this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+ GeneratedTransferObjectImpl(final Type parent,
+ final String packageName,
+ final String name, final String comment,
+ final List<AnnotationTypeBuilder> annotationBuilders,
+ final boolean isAbstract,
+ final GeneratedTransferObject extendsType,
+ final List<Type> implementsTypes,
+ final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders,
+ final List<Constant> constants,
+ final List<EnumBuilder> enumBuilders,
+ final List<MethodSignatureBuilder> methodBuilders,
+ final List<GeneratedPropertyBuilder> propBuilders,
+ final List<GeneratedPropertyBuilder> equalsBuilders,
+ final List<GeneratedPropertyBuilder> hashCodeBuilders,
+ final List<GeneratedPropertyBuilder> stringBuilders) {
+ super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes,
+ enclosedGenTypeBuilders,
+ enclosedGenTOBuilders, enumBuilders, constants, methodBuilders);
this.extendsType = extendsType;
- this.implementsTypes = Collections
- .unmodifiableList(implementsTypes);
- this.constants = toUnmodifiableConstant(constantBuilders);
- this.enumerations = toUnmodifiableEnumerations(enumBuilders);
- this.properties = toUnmodifiableProperties(propBuilers);
- this.methods = toUnmodifiableMethods(methodBuilders);
- this.equalsProperties = toUnmodifiableProperties(equalsBuilers);
- this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilers);
- this.stringProperties = toUnmodifiableProperties(stringBuilers);
- }
-
- private List<AnnotationType> toUnmodifiableAnnotations(
- final List<AnnotationTypeBuilder> annotationBuilders) {
- final List<AnnotationType> annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- annotations.add(builder.toInstance());
- }
- return Collections.unmodifiableList(annotations);
- }
-
- private List<Enumeration> toUnmodifiableEnumerations(
- final List<EnumBuilder> enumBuilders) {
- final List<Enumeration> enumerations = new ArrayList<Enumeration>();
- for (final EnumBuilder builder : enumBuilders) {
- enumerations.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(enumerations);
- }
-
- private List<Constant> toUnmodifiableConstant(
- final List<ConstantBuilder> constBuilders) {
- final List<Constant> constants = new ArrayList<Constant>();
- for (final ConstantBuilder builder : constBuilders) {
- constants.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(constants);
- }
-
- private List<MethodSignature> toUnmodifiableMethods(
- final List<MethodSignatureBuilder> methodBuilders) {
- final List<MethodSignature> methods = new ArrayList<MethodSignature>();
- for (final MethodSignatureBuilder builder : methodBuilders) {
- methods.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(methods);
+ this.properties = toUnmodifiableProperties(propBuilders);
+ this.equalsProperties = toUnmodifiableProperties(equalsBuilders);
+ this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilders);
+ this.stringProperties = toUnmodifiableProperties(stringBuilders);
}
private List<GeneratedProperty> toUnmodifiableProperties(
final List<GeneratedPropertyBuilder> propBuilders) {
- final List<GeneratedProperty> constants = new ArrayList<GeneratedProperty>();
+ final List<GeneratedProperty> properties = new ArrayList<>();
for (final GeneratedPropertyBuilder builder : propBuilders) {
- constants.add(builder.toInstance(this));
+ properties.add(builder.toInstance(this));
}
- return Collections.unmodifiableList(constants);
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- return null;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public List<Type> getImplements() {
- return implementsTypes;
+ return Collections.unmodifiableList(properties);
}
@Override
return extendsType;
}
- @Override
- public List<Enumeration> getEnumDefintions() {
- return enumerations;
- }
-
- @Override
- public List<Constant> getConstantDefinitions() {
- return constants;
- }
-
- @Override
- public List<MethodSignature> getMethodDefinitions() {
- return methods;
- }
-
@Override
public List<GeneratedProperty> getProperties() {
return properties;
return stringProperties;
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedTransferObjectImpl other = (GeneratedTransferObjectImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
- }
-
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeneratedTransferObject [packageName=");
- builder.append(packageName);
+ builder.append(getPackageName());
builder.append(", name=");
- builder.append(name);
+ builder.append(getName());
builder.append(", comment=");
- builder.append(comment);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(getComment());
+ builder.append(", extends=");
+ builder.append(getExtends());
+ builder.append(", implements=");
+ builder.append(getImplements());
+ builder.append(", enclosedTypes=");
+ builder.append(getEnclosedTypes());
builder.append(", constants=");
- builder.append(constants);
+ builder.append(getConstantDefinitions());
builder.append(", enumerations=");
- builder.append(enumerations);
+ builder.append(getEnumerations());
builder.append(", properties=");
builder.append(properties);
builder.append(", equalsProperties=");
builder.append(hashCodeProperties);
builder.append(", stringProperties=");
builder.append(stringProperties);
- builder.append(", annotations=");
- builder.append(annotations);
builder.append(", methods=");
- builder.append(methods);
+ builder.append(getMethodDefinitions());
builder.append("]");
return builder.toString();
}
}
-
- private static final class GeneratedTransferIdentityObjectImpl extends
- GeneratedTransferObjectImpl implements
- GeneratedTransferIdentityObject {
- public GeneratedTransferIdentityObjectImpl(final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final GeneratedTransferObject extendsType,
- final List<Type> implementsTypes,
- final List<ConstantBuilder> constantBuilders,
- final List<EnumBuilder> enumBuilders,
- final List<MethodSignatureBuilder> methodBuilders,
- final List<GeneratedPropertyBuilder> propBuilers,
- final List<GeneratedPropertyBuilder> equalsBuilers,
- final List<GeneratedPropertyBuilder> hashCodeBuilers,
- final List<GeneratedPropertyBuilder> stringBuilers) {
- super(packageName, name, comment, annotationBuilders, extendsType,
- implementsTypes, constantBuilders, enumBuilders,
- methodBuilders, propBuilers, equalsBuilers,
- hashCodeBuilers, stringBuilers);
- }
- }
}
*/
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-
-public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
-
- private final String packageName;
- private String comment = "";
- private final String name;
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- private final List<Type> implementsTypes = new ArrayList<Type>();
- private final List<EnumBuilder> enumDefinitions = new ArrayList<EnumBuilder>();
- private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();
- private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();
-
- public GeneratedTypeBuilderImpl(final String packageName, final String name) {
- this.packageName = packageName;
- this.name = name;
- }
-
- @Override
- public Type getParentType() {
- return this;
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void addComment(String comment) {
- this.comment = comment;
- }
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
+import java.util.List;
- @Override
- public ConstantBuilder addConstant(Type type, String name, Object value) {
- final ConstantBuilder builder = new ConstantBuilderImpl(type, name,
- value);
- constantDefintions.add(builder);
- return builder;
- }
+public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder {
- @Override
- public EnumBuilder addEnumeration(final String name) {
- final String innerPackageName = packageName + "." + this.name;
- final EnumBuilder builder = new EnumerationBuilderImpl(
- innerPackageName, name);
- enumDefinitions.add(builder);
- return builder;
+ public GeneratedTypeBuilderImpl(String packageName, String name) {
+ super(packageName, name);
+ setAbstract(true);
}
@Override
- public MethodSignatureBuilder addMethod(final String name) {
- final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(
- this, name);
- methodDefinitions.add(builder);
- return builder;
+ public GeneratedType toInstance() {
+ return new GeneratedTypeImpl(null, getPackageName(), getName(), getComment(), getAnnotations(), isAbstract(),
+ getImplementsTypes(), getEnclosedTypes(), getEnclosedTransferObjects(), getEnumerations(),
+ getConstants(), getMethodDefinitions());
}
@Override
- public boolean addImplementsType(final Type genType) {
- if (genType != null) {
- return implementsTypes.add(genType);
- }
- return false;
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedTransferObject [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(getComment());
+ builder.append(", implements=");
+ builder.append(getImplementsTypes());
+ builder.append(", enclosedTypes=");
+ builder.append(getEnclosedTypes());
+ builder.append(", constants=");
+ builder.append(getConstants());
+ builder.append(", enumerations=");
+ builder.append(getEnumerations());
+ builder.append(", properties=");
+ builder.append(", methods=");
+ builder.append(getMethodDefinitions());
+ builder.append("]");
+ return builder.toString();
}
-
- @Override
- public GeneratedType toInstance() {
- return new GeneratedTypeImpl(this, packageName, name, comment,
- annotationBuilders, implementsTypes, enumDefinitions, constantDefintions,
- methodDefinitions);
- }
-
- private static final class GeneratedTypeImpl implements GeneratedType {
-
- private final Type parent;
- private final String packageName;
- private final String name;
- private final String comment;
- private final List<AnnotationType> annotations;
- private final List<Type> implementsTypes;
- private final List<Enumeration> enumDefinitions;
- private final List<Constant> constantDefintions;
- private final List<MethodSignature> methodDefinitions;
-
- public GeneratedTypeImpl(final Type parent, final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final List<Type> implementsTypes,
- final List<EnumBuilder> enumBuilders,
- final List<ConstantBuilder> constantBuilders,
- final List<MethodSignatureBuilder> methodBuilders) {
- super();
- this.parent = parent;
- this.packageName = packageName;
- this.name = name;
- this.comment = comment;
- this.annotations = toUnmodifiableAnnotations(annotationBuilders);
- this.implementsTypes = Collections.unmodifiableList(implementsTypes);
- this.constantDefintions = toUnmodifiableConstants(constantBuilders);
- this.enumDefinitions = toUnmodifiableEnums(enumBuilders);
- this.methodDefinitions = toUnmodifiableMethods(methodBuilders);
- }
-
- private List<AnnotationType> toUnmodifiableAnnotations(
- final List<AnnotationTypeBuilder> annotationBuilders) {
- final List<AnnotationType> annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- annotations.add(builder.toInstance());
- }
- return Collections.unmodifiableList(annotations);
- }
-
- private List<MethodSignature> toUnmodifiableMethods(
- List<MethodSignatureBuilder> methodBuilders) {
- final List<MethodSignature> methods = new ArrayList<MethodSignature>();
- for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
- methods.add(methodBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(methods);
- }
-
- private List<Enumeration> toUnmodifiableEnums(
- List<EnumBuilder> enumBuilders) {
- final List<Enumeration> enums = new ArrayList<Enumeration>();
- for (final EnumBuilder enumBuilder : enumBuilders) {
- enums.add(enumBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(enums);
- }
-
- private List<Constant> toUnmodifiableConstants(
- List<ConstantBuilder> constantBuilders) {
- final List<Constant> constants = new ArrayList<Constant>();
- for (final ConstantBuilder enumBuilder : constantBuilders) {
- constants.add(enumBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(constants);
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- return parent;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public List<Type> getImplements() {
- return implementsTypes;
- }
-
- @Override
- public List<Enumeration> getEnumDefintions() {
- return enumDefinitions;
- }
-
- @Override
- public List<Constant> getConstantDefinitions() {
- return constantDefintions;
- }
-
- @Override
- public List<MethodSignature> getMethodDefinitions() {
- return methodDefinitions;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime
- * result
- + ((constantDefintions == null) ? 0 : constantDefintions
- .hashCode());
- result = prime
- * result
- + ((enumDefinitions == null) ? 0 : enumDefinitions
- .hashCode());
- result = prime
- * result
- + ((methodDefinitions == null) ? 0 : methodDefinitions
- .hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedTypeImpl other = (GeneratedTypeImpl) obj;
- if (constantDefintions == null) {
- if (other.constantDefintions != null) {
- return false;
- }
- } else if (!constantDefintions.equals(other.constantDefintions)) {
- return false;
- }
- if (enumDefinitions == null) {
- if (other.enumDefinitions != null) {
- return false;
- }
- } else if (!enumDefinitions.equals(other.enumDefinitions)) {
- return false;
- }
- if (methodDefinitions == null) {
- if (other.methodDefinitions != null) {
- return false;
- }
- } else if (!methodDefinitions.equals(other.methodDefinitions)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedType [packageName=");
- builder.append(packageName);
- builder.append(", name=");
- builder.append(name);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
- builder.append(", comment=");
- builder.append(comment);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append(", enumDefinitions=");
- builder.append(enumDefinitions);
- builder.append(", constantDefintions=");
- builder.append(constantDefintions);
- builder.append(", methodDefinitions=");
- builder.append(methodDefinitions);
- builder.append("]");
- return builder.toString();
+ private static final class GeneratedTypeImpl extends AbstractGeneratedType {
+
+ public GeneratedTypeImpl(final Type parent, final String packageName, final String name, final String comment,
+ final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
+ final List<Type> implementsTypes,
+ final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders,
+ final List<EnumBuilder> enumBuilders, final List<Constant> constants,
+ final List<MethodSignatureBuilder> methodBuilders) {
+ super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes,
+ enclosedGenTypeBuilders, enclosedGenTOBuilders, enumBuilders, constants, methodBuilders);
}
}
}
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-final class MethodSignatureBuilderImpl implements MethodSignatureBuilder {
- private final String name;
- private Type returnType;
+final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder {
+
private final List<MethodSignature.Parameter> parameters;
- private final List<AnnotationTypeBuilder> annotationBuilders;
- private String comment = "";
- private final Type parent;
+ private boolean isAbstract;
- public MethodSignatureBuilderImpl(final Type parent, final String name) {
- super();
- this.name = name;
- this.parent = parent;
- this.parameters = new ArrayList<MethodSignature.Parameter>();
- this.annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+ public MethodSignatureBuilderImpl(final String name) {
+ super(name);
+ this.parameters = new ArrayList<>();
}
@Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public void addReturnType(Type returnType) {
- if (returnType != null) {
- this.returnType = returnType;
- }
+ public void setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
}
@Override
parameters.add(new MethodParameterImpl(name, type));
}
- @Override
- public void addComment(String comment) {
- this.comment = comment;
- }
-
@Override
public MethodSignature toInstance(Type definingType) {
- return new MethodSignatureImpl(definingType, name, annotationBuilders,
- comment, returnType, parameters);
+ final List<AnnotationType> annotations = toAnnotationTypes();
+ return new MethodSignatureImpl(definingType, getName(), annotations,
+ getComment(), getAccessModifier(), getReturnType(), parameters, isFinal(), isAbstract);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result
+ ((parameters == null) ? 0 : parameters.hashCode());
result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
return result;
}
return false;
}
MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
- if (name == null) {
- if (other.name != null) {
+ if (getName() == null) {
+ if (other.getName() != null) {
return false;
}
- } else if (!name.equals(other.name)) {
+ } else if (!getName().equals(other.getName())) {
return false;
}
if (parameters == null) {
} else if (!parameters.equals(other.parameters)) {
return false;
}
- if (returnType == null) {
- if (other.returnType != null) {
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
return false;
}
- } else if (!returnType.equals(other.returnType)) {
+ } else if (!getReturnType().equals(other.getReturnType())) {
return false;
}
return true;
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MethodSignatureBuilderImpl [name=");
- builder.append(name);
+ builder.append(getName());
builder.append(", returnType=");
- builder.append(returnType);
+ builder.append(getReturnType());
builder.append(", parameters=");
builder.append(parameters);
builder.append(", annotationBuilders=");
- builder.append(annotationBuilders);
+ builder.append(getAnnotationBuilders());
builder.append(", comment=");
- builder.append(comment);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
+ builder.append(getComment());
builder.append("]");
return builder.toString();
}
-
- private static final class MethodSignatureImpl implements MethodSignature {
-
- private final String name;
- private final String comment;
- private final Type definingType;
- private final Type returnType;
- private final List<Parameter> params;
- private List<AnnotationType> annotations;
-
- public MethodSignatureImpl(final Type definingType, final String name,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final String comment, final Type returnType,
- final List<Parameter> params) {
- super();
- this.name = name;
- this.comment = comment;
- this.definingType = definingType;
- this.returnType = returnType;
- this.params = Collections.unmodifiableList(params);
-
- this.annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- this.annotations.add(builder.toInstance());
- }
- this.annotations = Collections.unmodifiableList(this.annotations);
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public Type getDefiningType() {
- return definingType;
- }
-
- @Override
- public Type getReturnType() {
- return returnType;
- }
-
- @Override
- public List<Parameter> getParameters() {
- return params;
- }
-
- @Override
- public AccessModifier getAccessModifier() {
- return AccessModifier.PUBLIC;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((params == null) ? 0 : params.hashCode());
- result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- MethodSignatureImpl other = (MethodSignatureImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (params == null) {
- if (other.params != null) {
- return false;
- }
- } else if (!params.equals(other.params)) {
- return false;
- }
- if (returnType == null) {
- if (other.returnType != null) {
- return false;
- }
- } else if (!returnType.equals(other.returnType)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("MethodSignatureImpl [name=");
- builder.append(name);
- builder.append(", comment=");
- builder.append(comment);
- if (definingType != null) {
- builder.append(", definingType=");
- builder.append(definingType.getPackageName());
- builder.append(".");
- builder.append(definingType.getName());
- } else {
- builder.append(", definingType= null");
- }
- builder.append(", returnType=");
- builder.append(returnType);
- builder.append(", params=");
- builder.append(params);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append("]");
- return builder.toString();
- }
- }
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+import java.util.Collections;
+import java.util.List;
+
+class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature {
+
+ private final List<Parameter> params;
+ private final boolean isAbstract;
+
+ public MethodSignatureImpl(final Type definingType, final String name,
+ final List<AnnotationType> annotations,
+ final String comment, final AccessModifier accessModifier,
+ final Type returnType, final List<Parameter> params, boolean isFinal,
+ boolean isAbstract) {
+ super(definingType, name, annotations, comment, accessModifier, returnType, isFinal);
+ this.params = Collections.unmodifiableList(params);
+ this.isAbstract = isAbstract;
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ @Override
+ public List<Parameter> getParameters() {
+ return params;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((params == null) ? 0 : params.hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureImpl other = (MethodSignatureImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (params == null) {
+ if (other.params != null) {
+ return false;
+ }
+ } else if (!params.equals(other.params)) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodSignatureImpl [name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", definingType=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", params=");
+ builder.append(params);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append("]");
+ return builder.toString();
+ }
+}
import org.junit.Test;
import org.opendaylight.controller.binding.generator.util.Types;
-import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
final MethodSignatureBuilder methodBuilder = genTypeBuilder
.addMethod("simpleMethod");
- methodBuilder.addReturnType(Types.typeForClass(Integer.class));
+ methodBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = methodBuilder
.addAnnotation("org.springframework.jmx.export.annotation",
"ManagedAttribute");
final GeneratedPropertyBuilder propertyBuilder = genTOBuilder
.addProperty("simpleProperty");
- propertyBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = propertyBuilder
.addAnnotation("org.springframework.jmx.export.annotation",
"ManagedAttribute");
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-java-api-generator</artifactId>\r
<dependencies>\r
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
+import org.opendaylight.controller.sal.binding.model.api.*;
public final class ClassCodeGenerator implements CodeGenerator {
- private Map<String, LinkedHashMap<String, Integer>> imports;
+ private Map<String, String> imports;
@Override
public Writer generate(Type type) throws IOException {
final Writer writer = new StringWriter();
- boolean isIdentity = type instanceof GeneratedTransferIdentityObject;
if (type instanceof GeneratedTransferObject) {
- GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+ GeneratedTransferObject genTO = (GeneratedTransferObject) type;
imports = GeneratorUtil.createImports(genTO);
-
+
final String currentPkg = genTO.getPackageName();
final List<GeneratedProperty> fields = genTO.getProperties();
- final List<Enumeration> enums = genTO.getEnumDefintions();
+ final List<Enumeration> enums = genTO.getEnumerations();
+ final List<Constant> consts = genTO.getConstantDefinitions();
writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
writer.write(NL);
}
writer.write(NL);
- writer.write(GeneratorUtil.createClassDeclaration(genTO, "",
- imports, isIdentity));
+ writer.write(GeneratorUtil.createClassDeclaration(genTO, "", imports, genTO.isAbstract()));
writer.write(NL);
writer.write(NL);
-
- if (enums != null) {
- EnumGenerator enumGenerator = new EnumGenerator();
- for ( Enumeration e : enums ) {
- writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
- writer.write(NL);
- }
+
+ if (consts != null) {
+ for (Constant con : consts) {
+ writer.write(GeneratorUtil.createConstant(con, TAB, imports, currentPkg));
+ writer.write(NL);
+ }
}
- if (fields != null) {
- for (GeneratedProperty field : fields) {
- writer.write(GeneratorUtil.createField(field, TAB, imports,
- currentPkg) + NL);
+ if (enums != null) {
+ EnumGenerator enumGenerator = new EnumGenerator();
+ for (Enumeration e : enums) {
+ writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
+ writer.write(NL);
}
- writer.write(NL);
- writer.write(GeneratorUtil.createConstructor(genTO, TAB,
- imports, isIdentity) + NL);
- writer.write(NL);
- for (GeneratedProperty field : fields) {
- writer.write(GeneratorUtil.createGetter(field, TAB,
- imports, currentPkg) + NL);
- if (!field.isReadOnly()) {
- writer.write(GeneratorUtil.createSetter(field, TAB,
- imports, currentPkg) + NL);
+ }
+
+ boolean memberPatternListCodeRequired = false;
+ memberPatternListCodeRequired = (GeneratorUtil.isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, genTO));
+ if (fields != null || memberPatternListCodeRequired) {
+ if (fields != null) {
+ for (GeneratedProperty field : fields) {
+ writer.write(GeneratorUtil.createField(field, TAB, imports, currentPkg) + NL);
}
}
- writer.write(NL);
+ if (memberPatternListCodeRequired) {
+ writer.write(TAB + PRIVATE + GAP + "List<Pattern>" + GAP + MEMBER_PATTERN_LIST + GAP + ASSIGN + GAP
+ + "new ArrayList<Pattern>()" + GAP + SC + NL);
- if (!genTO.getHashCodeIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createHashCode(
- genTO.getHashCodeIdentifiers(), TAB)
- + NL);
}
+ writer.write(NL);
+ writer.write(GeneratorUtil.createConstructor(genTO, TAB, imports, genTO.isAbstract()) + NL);
+ writer.write(NL);
+ if (fields != null) {
+ for (GeneratedProperty field : fields) {
+ writer.write(GeneratorUtil.createGetter(field, TAB, imports, currentPkg) + NL);
+ if (!field.isReadOnly()) {
+ writer.write(GeneratorUtil.createSetter(field, TAB, imports, currentPkg) + NL);
+ }
+ }
+ writer.write(NL);
- if (!genTO.getEqualsIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createEquals(genTO,
- genTO.getEqualsIdentifiers(), TAB)
- + NL);
- }
+ if (!genTO.getHashCodeIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createHashCode(genTO.getHashCodeIdentifiers(), TAB) + NL);
+ }
- if (!genTO.getToStringIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createToString(genTO,
- genTO.getToStringIdentifiers(), TAB)
- + NL);
+ if (!genTO.getEqualsIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createEquals(genTO, genTO.getEqualsIdentifiers(), TAB) + NL);
+ }
- }
+ if (!genTO.getToStringIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createToString(genTO, genTO.getToStringIdentifiers(), TAB) + NL);
+ }
- writer.write(RCB);
+ writer.write(RCB);
+ }
}
}
return writer;
}
-
}
public static final String LB = "(";
public static final String RB = ")";
+ public static final String LSB = "[";
+ public static final String RSB = "]";
+
public static final String GAP = " ";
public static final String COMMA = ",";
public static final String NL = "\n";
public static final String SC = ";";
public static final String TAB = " ";
+ public static final String ASSIGN = "=";
+ public static final String DOUBLE_QUOTE = "\"";
public static final String PUBLIC = "public";
public static final String PRIVATE = "private";
public static final String FINAL = "final";
public static final String EXTENDS = "extends";
public static final String IMPLEMENTS = "implements";
-
+
public static final String ENUMERATION_NAME = "value";
- public static final String ENUMERATION_TYPE = "int";
-
- private Constants() {}
+ public static final String ENUMERATION_TYPE = "int";
+
+ public static final String STRING_PATTERN_LIST = "STRING_PATTERNS";
+ public static final String MEMBER_PATTERN_LIST = "patterns";
+
+ private Constants() {
+ }
}
*/
package org.opendaylight.controller.sal.java.api.generator;
-import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
+import static org.opendaylight.controller.sal.java.api.generator.Constants.NL;
import java.io.IOException;
import java.io.StringWriter;
public class EnumGenerator implements CodeGenerator {
- @Override
- public Writer generate(Type type) throws IOException {
- final Writer writer = new StringWriter();
+ @Override
+ public Writer generate(Type type) throws IOException {
+ final Writer writer = new StringWriter();
- if (type instanceof Enumeration) {
- Enumeration enums = (Enumeration) type;
- writer.write(GeneratorUtil.createPackageDeclaration(enums
- .getPackageName()));
- writer.write(NL + NL);
- writer.write(GeneratorUtil.createEnum(enums, ""));
- }
+ if (type instanceof Enumeration) {
+ Enumeration enums = (Enumeration) type;
+ writer.write(GeneratorUtil.createPackageDeclaration(enums.getPackageName()));
+ writer.write(NL + NL);
+ writer.write(GeneratorUtil.createEnum(enums, ""));
+ }
- return writer;
- }
+ return writer;
+ }
- public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
- final Writer writer = new StringWriter();
+ public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
+ final Writer writer = new StringWriter();
- if (type instanceof Enumeration) {
- Enumeration enums = (Enumeration) type;
- writer.write(GeneratorUtil.createEnum(enums, indent));
- }
+ if (type instanceof Enumeration) {
+ Enumeration enums = (Enumeration) type;
+ writer.write(GeneratorUtil.createEnum(enums, indent));
+ }
- return writer;
- }
+ return writer;
+ }
}
*/
package org.opendaylight.controller.sal.java.api.generator;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
+import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class GeneratorJavaFile {
- private static final Logger log = LoggerFactory
- .getLogger(GeneratorJavaFile.class);
+ private static final Logger log = LoggerFactory.getLogger(GeneratorJavaFile.class);
private final CodeGenerator interfaceGenerator;
private final ClassCodeGenerator classGenerator;
private final EnumGenerator enumGenerator;
-
+
private final Set<GeneratedType> genTypes;
private final Set<GeneratedTransferObject> genTransferObjects;
- private final Set<Enumeration> enumerations;
+ private final Set<Enumeration> enumerations;
- public GeneratorJavaFile(final CodeGenerator codeGenerator,
- final Set<GeneratedType> types) {
+ public GeneratorJavaFile(final CodeGenerator codeGenerator, final Set<GeneratedType> types) {
this.interfaceGenerator = codeGenerator;
this.genTypes = types;
this.genTransferObjects = new HashSet<>();
this.enumGenerator = new EnumGenerator();
}
- public GeneratorJavaFile(final Set<GeneratedType> types,
- final Set<GeneratedTransferObject> genTransferObjects,
+ public GeneratorJavaFile(final Set<GeneratedType> types, final Set<GeneratedTransferObject> genTransferObjects,
final Set<Enumeration> enumerations) {
this.interfaceGenerator = new InterfaceGenerator();
this.classGenerator = new ClassCodeGenerator();
this.enumGenerator = new EnumGenerator();
-
+
this.genTypes = types;
this.genTransferObjects = genTransferObjects;
this.enumerations = enumerations;
public List<File> generateToFile(final File parentDirectory) throws IOException {
final List<File> result = new ArrayList<>();
for (GeneratedType type : genTypes) {
- final File genFile = generateTypeToJavaFile(parentDirectory, type,
- interfaceGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, type, interfaceGenerator);
if (genFile != null) {
result.add(genFile);
}
}
for (GeneratedTransferObject transferObject : genTransferObjects) {
- final File genFile = generateTypeToJavaFile(parentDirectory,
- transferObject, classGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, transferObject, classGenerator);
if (genFile != null) {
result.add(genFile);
}
}
-
+
for (Enumeration enumeration : enumerations) {
- final File genFile = generateTypeToJavaFile(parentDirectory,
- enumeration, enumGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, enumeration, enumGenerator);
if (genFile != null) {
result.add(genFile);
}
}
-
+
return result;
}
- private File generateTypeToJavaFile(final File parentDir, final Type type,
- final CodeGenerator generator) throws IOException {
+ private File generateTypeToJavaFile(final File parentDir, final Type type, final CodeGenerator generator)
+ throws IOException {
if (parentDir == null) {
log.warn("Parent Directory not specified, files will be generated "
+ "accordingly to generated Type package path.");
}
if (type == null) {
- log.error("Cannot generate Type into Java File because " +
- "Generated Type is NULL!");
+ log.error("Cannot generate Type into Java File because " + "Generated Type is NULL!");
throw new IllegalArgumentException("Generated Type Cannot be NULL!");
}
if (generator == null) {
- log.error("Cannot generate Type into Java File because " +
- "Code Generator instance is NULL!");
+ log.error("Cannot generate Type into Java File because " + "Code Generator instance is NULL!");
throw new IllegalArgumentException("Code Generator Cannot be NULL!");
}
- final File packageDir = packageToDirectory(parentDir,
- type.getPackageName());
+ final File packageDir = packageToDirectory(parentDir, type.getPackageName());
if (!packageDir.exists()) {
packageDir.mkdirs();
return file;
}
- private File packageToDirectory(final File parentDirectory,
- final String packageName) {
+ private File packageToDirectory(final File parentDirectory, final String packageName) {
if (packageName == null) {
throw new IllegalArgumentException("Package Name cannot be NULL!");
}
import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
+import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.sal.binding.model.api.Enumeration.Pair;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
-import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.WildcardType;
public final class GeneratorUtil {
private GeneratorUtil() {
}
- public static String createIfcDeclaration(final GeneratedType genType,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports) {
- return createFileDeclaration(IFC, genType, indent, availableImports,
- false);
+ public static String createIfcDeclaration(final GeneratedType genType, final String indent,
+ final Map<String, String> availableImports) {
+ return createFileDeclaration(IFC, genType, indent, availableImports, false);
}
- public static String createClassDeclaration(
- final GeneratedTransferObject genTransferObject,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
- return createFileDeclaration(CLASS, genTransferObject, indent,
- availableImports, isIdentity);
+ public static String createClassDeclaration(final GeneratedTransferObject genTransferObject, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
+ return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity);
}
public static String createPackageDeclaration(final String packageName) {
return PKG + GAP + packageName + SC;
}
- private static String createFileDeclaration(final String type,
- final GeneratedType genType, final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
+ private static String createFileDeclaration(final String type, final GeneratedType genType, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
final StringBuilder builder = new StringBuilder();
final String currentPkg = genType.getPackageName();
if (isIdentity) {
if (!(CLASS.equals(type))) {
- throw new IllegalArgumentException(
- "'identity' has to be generated as a class");
+ throw new IllegalArgumentException("'identity' has to be generated as a class");
}
- builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP
- + genType.getName() + GAP);
+ builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
} else {
builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
}
} else {
builder.append(EXTENDS + GAP);
}
- builder.append(getExplicitType(genImplements.get(0),
- availableImports, currentPkg));
+ builder.append(getExplicitType(genImplements.get(0), availableImports, currentPkg));
for (int i = 1; i < genImplements.size(); ++i) {
builder.append(", ");
- builder.append(getExplicitType(genImplements.get(i),
- availableImports, currentPkg));
+ builder.append(getExplicitType(genImplements.get(i), availableImports, currentPkg));
}
}
-
builder.append(GAP + LCB);
return builder.toString();
}
- private static StringBuilder appendAnnotations(final StringBuilder builder,
- final List<AnnotationType> annotations) {
+ private static StringBuilder appendAnnotations(final StringBuilder builder, final List<AnnotationType> annotations) {
if ((builder != null) && (annotations != null)) {
for (final AnnotationType annotation : annotations) {
builder.append("@");
if (annotation.containsParameters()) {
builder.append("(");
- final List<AnnotationType.Parameter> parameters = annotation
- .getParameters();
+ final List<AnnotationType.Parameter> parameters = annotation.getParameters();
appendAnnotationParams(builder, parameters);
builder.append(")");
}
return builder;
}
- private static StringBuilder appendAnnotationParams(
- final StringBuilder builder,
+ private static StringBuilder appendAnnotationParams(final StringBuilder builder,
final List<AnnotationType.Parameter> parameters) {
if (parameters != null) {
int i = 0;
return builder;
}
- public static String createConstant(final Constant constant,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createConstant(final Constant constant, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
+ if (constant == null)
+ throw new IllegalArgumentException();
builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
- builder.append(getExplicitType(constant.getType(), availableImports,
- currentPkg) + GAP + constant.getName());
+ builder.append(getExplicitType(constant.getType(), availableImports, currentPkg) + GAP + constant.getName());
builder.append(GAP + "=" + GAP);
- builder.append(constant.getValue() + SC);
+ final Object constValue = constant.getValue();
+
+ if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+ if (constant.getName() == null || constant.getType() == null || constant.getValue() == null)
+ throw new IllegalArgumentException();
+ if (constValue instanceof List) {
+ builder.append("Arrays.asList" + LB);
+ final List<?> constantValues = (List<?>) constValue;
+ int stringsCount = 0;
+ for (Object value : constantValues) {
+ if (value instanceof String) {
+ if (stringsCount > 0) {
+ builder.append(COMMA);
+ }
+ stringsCount++;
+ builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
+ }
+ }
+ builder.append(RB);
+ }
+ } else {
+ builder.append(constant.getValue());
+ }
+ builder.append(SC);
+
return builder.toString();
}
- public static String createField(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createField(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
if (!property.getAnnotations().isEmpty()) {
final List<AnnotationType> annotations = property.getAnnotations();
builder.append(NL);
}
builder.append(indent + PRIVATE + GAP);
- builder.append(getExplicitType(property.getReturnType(),
- availableImports, currentPkg) + GAP + property.getName());
+ builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg) + GAP
+ + property.getName());
builder.append(SC);
return builder.toString();
}
* @param indent
* @return
*/
- public static String createMethodDeclaration(final MethodSignature method,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createMethodDeclaration(final MethodSignature method, final String indent,
+ Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
if (method == null) {
- throw new IllegalArgumentException(
- "Method Signature parameter MUST be specified and cannot be NULL!");
+ throw new IllegalArgumentException("Method Signature parameter MUST be specified and cannot be NULL!");
}
final String comment = method.getComment();
final Type type = method.getReturnType();
if (type == null) {
- throw new IllegalStateException(
- "Method Return type cannot be NULL!");
+ throw new IllegalStateException("Method Return type cannot be NULL!");
}
final List<Parameter> parameters = method.getParameters();
builder.append(NL);
}
- builder.append(indent
- + getExplicitType(type, availableImports, currentPkg) + GAP
- + name);
+ builder.append(indent + getExplicitType(type, availableImports, currentPkg) + GAP + name);
builder.append(LB);
for (int i = 0; i < parameters.size(); i++) {
Parameter p = parameters.get(i);
if (i + 1 == parameters.size()) {
separator = "";
}
- builder.append(getExplicitType(p.getType(), availableImports,
- currentPkg) + GAP + p.getName() + separator);
+ builder.append(getExplicitType(p.getType(), availableImports, currentPkg) + GAP + p.getName() + separator);
}
builder.append(RB);
builder.append(SC);
return builder.toString();
}
- public static String createConstructor(
- GeneratedTransferObject genTransferObject, final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
+ public static String createConstructor(GeneratedTransferObject genTransferObject, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
final StringBuilder builder = new StringBuilder();
final String currentPkg = genTransferObject.getPackageName();
- final List<GeneratedProperty> properties = genTransferObject
- .getProperties();
+ final List<GeneratedProperty> properties = genTransferObject.getProperties();
final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
- for (final GeneratedProperty property : properties) {
- if (property.isReadOnly()) {
- ctorParams.add(property);
+ if (properties != null) {
+ for (final GeneratedProperty property : properties) {
+ if (property.isReadOnly()) {
+ ctorParams.add(property);
+ }
}
}
builder.append(LB);
if (!ctorParams.isEmpty()) {
- builder.append(getExplicitType(ctorParams.get(0).getReturnType(),
- availableImports, currentPkg));
+ builder.append(getExplicitType(ctorParams.get(0).getReturnType(), availableImports, currentPkg));
builder.append(" ");
builder.append(ctorParams.get(0).getName());
for (int i = 1; i < ctorParams.size(); ++i) {
final GeneratedProperty param = ctorParams.get(i);
builder.append(", ");
- builder.append(getExplicitType(param.getReturnType(),
- availableImports, currentPkg));
+ builder.append(getExplicitType(param.getReturnType(), availableImports, currentPkg));
builder.append(GAP);
builder.append(param.getName());
}
builder.append(NL);
}
}
+ List<Constant> consts = genTransferObject.getConstantDefinitions();
+ for (Constant con : consts) {
+ if (con.getName() == null || con.getType() == null || con.getValue() == null)
+ continue;
+ if (con.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+ Object values = con.getValue();
+ if (values instanceof List) {
+ for (Object regEx : (List<?>) values) {
+ if (regEx instanceof String) {
+ builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME
+ + ") {" + NL);
+ builder.append(indent + TAB + TAB + "this." + MEMBER_PATTERN_LIST
+ + ".add(Pattern.compile(regEx))" + SC + NL);
+ builder.append(indent + TAB + RCB + NL);
+
+ break;
+ }
+ }
+
+ }
+ }
+
+ }
+
builder.append(indent);
builder.append(RCB);
return builder.toString();
}
- public static String createGetter(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createGetter(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
final Type type = property.getReturnType();
final char first = Character.toUpperCase(varName.charAt(0));
final String methodName = "get" + first + varName.substring(1);
- builder.append(indent + PUBLIC + GAP
- + getExplicitType(type, availableImports, currentPkg) + GAP
- + methodName);
+ builder.append(indent + PUBLIC + GAP + getExplicitType(type, availableImports, currentPkg) + GAP + methodName);
builder.append(LB + RB + LCB + NL);
String currentIndent = indent + TAB;
return builder.toString();
}
- public static String createSetter(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- String currentPkg) {
+ public static String createSetter(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
final Type type = property.getReturnType();
final String methodName = "set" + first + varName.substring(1);
builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
- builder.append(LB + getExplicitType(type, availableImports, currentPkg)
- + GAP + varName + RB + LCB + NL);
+ builder.append(LB + getExplicitType(type, availableImports, currentPkg) + GAP + varName + RB + LCB + NL);
String currentIndent = indent + TAB;
- builder.append(currentIndent + "this." + varName + " = " + varName + SC
- + NL);
+ builder.append(currentIndent + "this." + varName + " = " + varName + SC + NL);
builder.append(indent + RCB);
return builder.toString();
}
- public static String createHashCode(
- final List<GeneratedProperty> properties, final String indent) {
+ public static String createHashCode(final List<GeneratedProperty> properties, final String indent) {
StringBuilder builder = new StringBuilder();
builder.append(indent + "public int hashCode() {" + NL);
builder.append(indent + TAB + "final int prime = 31;" + NL);
for (GeneratedProperty property : properties) {
String fieldName = property.getName();
- builder.append(indent + TAB + "result = prime * result + (("
- + fieldName + " == null) ? 0 : " + fieldName
+ builder.append(indent + TAB + "result = prime * result + ((" + fieldName + " == null) ? 0 : " + fieldName
+ ".hashCode());" + NL);
}
return builder.toString();
}
- public static String createEquals(final GeneratedTransferObject type,
- final List<GeneratedProperty> properties, final String indent) {
- StringBuilder builder = new StringBuilder();
+ public static String createEquals(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+ final String indent) {
+ final StringBuilder builder = new StringBuilder();
final String indent1 = indent + TAB;
final String indent2 = indent1 + TAB;
final String indent3 = indent2 + TAB;
builder.append(indent1 + "}" + NL);
String typeStr = type.getName();
- builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;"
- + NL);
+ builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;" + NL);
- for (GeneratedProperty property : properties) {
+ for (final GeneratedProperty property : properties) {
String fieldName = property.getName();
builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
- builder.append(indent2 + "if (other." + fieldName + " != null) {"
- + NL);
+ builder.append(indent2 + "if (other." + fieldName + " != null) {" + NL);
builder.append(indent3 + "return false;" + NL);
builder.append(indent2 + "}" + NL);
- builder.append(indent1 + "} else if (!" + fieldName
- + ".equals(other." + fieldName + ")) {" + NL);
+ builder.append(indent1 + "} else if (!" + fieldName + ".equals(other." + fieldName + ")) {" + NL);
builder.append(indent2 + "return false;" + NL);
builder.append(indent1 + "}" + NL);
}
builder.append(indent1 + "return true;" + NL);
-
builder.append(indent + RCB + NL);
return builder.toString();
}
- public static String createToString(final GeneratedTransferObject type,
- final List<GeneratedProperty> properties, final String indent) {
+ public static String createToString(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+ final String indent) {
StringBuilder builder = new StringBuilder();
builder.append(indent);
builder.append("public String toString() {");
builder.append(" [");
boolean first = true;
- for (GeneratedProperty property : properties) {
+ for (final GeneratedProperty property : properties) {
if (first) {
builder.append(property.getName());
builder.append("=\");");
return builder.toString();
}
- public static String createEnum(final Enumeration enumeration,
- final String indent) {
+ public static String createEnum(final Enumeration enumeration, final String indent) {
if (enumeration == null || indent == null)
throw new IllegalArgumentException();
- final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP
- + ENUM + GAP + enumeration.getName() + GAP + LCB + NL);
+ final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP + ENUM + GAP + enumeration.getName()
+ + GAP + LCB + NL);
String separator = COMMA + NL;
final List<Pair> values = enumeration.getValues();
if (i + 1 == values.size()) {
separator = SC;
}
- builder.append(indent + TAB + values.get(i).getName() + LB
- + values.get(i).getValue() + RB + separator);
+ builder.append(indent + TAB + values.get(i).getName() + LB + values.get(i).getValue() + RB + separator);
}
builder.append(NL);
builder.append(NL);
final String ENUMERATION_NAME = "value";
final String ENUMERATION_TYPE = "int";
- builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME
- + SC);
+ builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + SC);
builder.append(NL);
- builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName()
- + LB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + RB + GAP
- + LCB + NL);
- builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP
- + "=" + GAP + ENUMERATION_NAME + SC + NL);
+ builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName() + LB + ENUMERATION_TYPE + GAP
+ + ENUMERATION_NAME + RB + GAP + LCB + NL);
+ builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP + "=" + GAP + ENUMERATION_NAME + SC + NL);
builder.append(indent + TAB + RCB + NL);
builder.append(indent + RCB);
return builder.toString();
}
- private static String getExplicitType(final Type type,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ private static String getExplicitType(final Type type, final Map<String, String> imports, final String currentPkg) {
if (type == null) {
- throw new IllegalArgumentException(
- "Type parameter MUST be specified and cannot be NULL!");
+ throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
+ }
+ if (type.getName() == null) {
+ throw new IllegalArgumentException("Type name cannot be NULL!");
+ }
+ if (type.getPackageName() == null) {
+ throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
+ }
+ if (imports == null) {
+ throw new IllegalArgumentException("Imports Map cannot be NULL!");
}
- String packageName = type.getPackageName();
-
- LinkedHashMap<String, Integer> imports = availableImports.get(type
- .getName());
- if ((imports != null && packageName
- .equals(findMaxValue(imports).get(0)))
- || packageName.equals(currentPkg)) {
+ final String typePackageName = type.getPackageName();
+ final String typeName = type.getName();
+ final String importedPackageName = imports.get(typeName);
+ if (typePackageName.equals(importedPackageName) || typePackageName.equals(currentPkg)) {
final StringBuilder builder = new StringBuilder(type.getName());
if (type instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) type;
- Type[] pTypes = pType.getActualTypeArguments();
+ final ParameterizedType pType = (ParameterizedType) type;
+ final Type[] pTypes = pType.getActualTypeArguments();
builder.append("<");
- builder.append(getParameters(pTypes, availableImports,
- currentPkg));
+ builder.append(getParameters(pTypes, imports, currentPkg));
builder.append(">");
}
if (builder.toString().equals("Void")) {
return builder.toString();
} else {
final StringBuilder builder = new StringBuilder();
- if (packageName.startsWith("java.lang")) {
+ if (typePackageName.startsWith("java.lang")) {
builder.append(type.getName());
} else {
- if (!packageName.isEmpty()) {
- builder.append(packageName + "." + type.getName());
+ if (!typePackageName.isEmpty()) {
+ builder.append(typePackageName + "." + type.getName());
} else {
builder.append(type.getName());
}
-
}
if (type instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) type;
- Type[] pTypes = pType.getActualTypeArguments();
+ final ParameterizedType pType = (ParameterizedType) type;
+ final Type[] pTypes = pType.getActualTypeArguments();
builder.append("<");
- builder.append(getParameters(pTypes, availableImports,
- currentPkg));
+ builder.append(getParameters(pTypes, imports, currentPkg));
builder.append(">");
}
if (builder.toString().equals("Void")) {
}
}
- private static String getParameters(final Type[] pTypes,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- String currentPkg) {
+ private static String getParameters(final Type[] pTypes, Map<String, String> availableImports, String currentPkg) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < pTypes.length; i++) {
- Type t = pTypes[i];
+ final Type t = pTypes[i];
String separator = COMMA;
- if (i + 1 == pTypes.length) {
+ if (i == (pTypes.length - 1)) {
separator = "";
}
-
+
String wildcardParam = "";
- if(t instanceof WildcardType) {
+ if (t instanceof WildcardType) {
wildcardParam = "? extends ";
}
-
- builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg)
- + separator);
+ builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
}
return builder.toString();
}
- private static List<String> findMaxValue(
- LinkedHashMap<String, Integer> imports) {
- final List<String> result = new ArrayList<String>();
-
- int maxValue = 0;
- int currentValue = 0;
- for (Map.Entry<String, Integer> entry : imports.entrySet()) {
- currentValue = entry.getValue();
- if (currentValue > maxValue) {
- result.clear();
- result.add(entry.getKey());
- maxValue = currentValue;
- } else if (currentValue == maxValue) {
- result.add(entry.getKey());
- }
- }
- return result;
- }
-
- private static void createComment(final StringBuilder builder,
- final String comment, final String indent) {
+ private static void createComment(final StringBuilder builder, final String comment, final String indent) {
if (comment != null && comment.length() > 0) {
builder.append(indent + "/*" + NL);
builder.append(indent + comment + NL);
}
}
- public static Map<String, LinkedHashMap<String, Integer>> createImports(
- GeneratedType genType) {
- final Map<String, LinkedHashMap<String, Integer>> imports = new HashMap<String, LinkedHashMap<String, Integer>>();
- final String genTypePkg = genType.getPackageName();
+ public static Map<String, String> createImports(final GeneratedType genType) {
+ if (genType == null) {
+ throw new IllegalArgumentException("Generated Type cannot be NULL!");
+ }
+ final Map<String, String> imports = new LinkedHashMap<>();
final List<Constant> constants = genType.getConstantDefinitions();
final List<MethodSignature> methods = genType.getMethodDefinitions();
- List<Type> impl = genType.getImplements();
+ final List<Type> impl = genType.getImplements();
// IMPLEMENTATIONS
if (impl != null) {
- for (Type t : impl) {
- addTypeToImports(t, imports, genTypePkg);
+ for (final Type type : impl) {
+ putTypeIntoImports(genType, type, imports);
}
}
// CONSTANTS
if (constants != null) {
- for (Constant c : constants) {
- Type ct = c.getType();
- addTypeToImports(ct, imports, genTypePkg);
+ for (final Constant constant : constants) {
+ final Type constantType = constant.getType();
+ putTypeIntoImports(genType, constantType, imports);
+ }
+ }
+
+ // REGULAR EXPRESSION
+ if (genType instanceof GeneratedTransferObject) {
+ if (isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) {
+ putTypeIntoImports(genType, Types.typeForClass(java.util.regex.Pattern.class), imports);
+ putTypeIntoImports(genType, Types.typeForClass(java.util.Arrays.class), imports);
+ putTypeIntoImports(genType, Types.typeForClass(java.util.ArrayList.class), imports);
}
}
// METHODS
if (methods != null) {
- for (MethodSignature m : methods) {
- Type ct = m.getReturnType();
- addTypeToImports(ct, imports, genTypePkg);
- for (MethodSignature.Parameter p : m.getParameters()) {
- addTypeToImports(p.getType(), imports, genTypePkg);
+ for (final MethodSignature method : methods) {
+ final Type methodReturnType = method.getReturnType();
+ putTypeIntoImports(genType, methodReturnType, imports);
+ for (final MethodSignature.Parameter methodParam : method.getParameters()) {
+ putTypeIntoImports(genType, methodParam.getType(), imports);
}
}
}
// PROPERTIES
if (genType instanceof GeneratedTransferObject) {
- GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
-
- List<GeneratedProperty> props = genTO.getProperties();
- if (props != null) {
- for (GeneratedProperty prop : props) {
- Type pt = prop.getReturnType();
- addTypeToImports(pt, imports, genTypePkg);
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ if (properties != null) {
+ for (GeneratedProperty property : properties) {
+ final Type propertyType = property.getReturnType();
+ putTypeIntoImports(genType, propertyType, imports);
}
}
}
return imports;
}
- private static void addTypeToImports(Type type,
- Map<String, LinkedHashMap<String, Integer>> importedTypes,
- String genTypePkg) {
- String typeName = type.getName();
- String typePkg = type.getPackageName();
- if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) ||
- typePkg.isEmpty()) {
- return;
+ private static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
+ final Map<String, String> imports) {
+ if (parentGenType == null) {
+ throw new IllegalArgumentException("Parent Generated Type parameter MUST be specified and cannot be "
+ + "NULL!");
}
- LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);
- if (packages == null) {
- packages = new LinkedHashMap<String, Integer>();
- packages.put(typePkg, 1);
- importedTypes.put(typeName, packages);
- } else {
- Integer occurrence = packages.get(typePkg);
- if (occurrence == null) {
- packages.put(typePkg, 1);
- } else {
- occurrence++;
- packages.put(typePkg, occurrence);
- }
+ if (parentGenType.getName() == null) {
+ throw new IllegalArgumentException("Parent Generated Type name cannot be NULL!");
+ }
+ if (parentGenType.getPackageName() == null) {
+ throw new IllegalArgumentException("Parent Generated Type cannot have Package Name referenced as NULL!");
+ }
+ if (type == null) {
+ throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
+ }
+ if (type.getName() == null) {
+ throw new IllegalArgumentException("Type name cannot be NULL!");
+ }
+ if (type.getPackageName() == null) {
+ throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
}
+ final String typeName = type.getName();
+ final String typePackageName = type.getPackageName();
+ final String parentTypeName = parentGenType.getName();
+ final String parentTypePackageName = parentGenType.getPackageName();
+ if (typeName.equals(parentTypeName) || typePackageName.startsWith("java.lang")
+ || typePackageName.equals(parentTypePackageName) || typePackageName.isEmpty()) {
+ return;
+ }
+ if (!imports.containsKey(typeName)) {
+ imports.put(typeName, typePackageName);
+ }
if (type instanceof ParameterizedType) {
- ParameterizedType pt = (ParameterizedType) type;
- Type[] params = pt.getActualTypeArguments();
+ final ParameterizedType paramType = (ParameterizedType) type;
+ final Type[] params = paramType.getActualTypeArguments();
for (Type param : params) {
- addTypeToImports(param, importedTypes, genTypePkg);
+ putTypeIntoImports(parentGenType, param, imports);
}
}
}
- public static List<String> createImportLines(
- Map<String, LinkedHashMap<String, Integer>> imports) {
- List<String> importLines = new ArrayList<String>();
+ public static List<String> createImportLines(final Map<String, String> imports) {
+ final List<String> importLines = new ArrayList<>();
- for (Map.Entry<String, LinkedHashMap<String, Integer>> entry : imports
- .entrySet()) {
- String typeName = entry.getKey();
- LinkedHashMap<String, Integer> typePkgMap = entry.getValue();
- String typePkg = typePkgMap.keySet().iterator().next();
- importLines.add("import " + typePkg + "." + typeName + SC);
+ for (Map.Entry<String, String> entry : imports.entrySet()) {
+ final String typeName = entry.getKey();
+ final String packageName = entry.getValue();
+ importLines.add("import " + packageName + "." + typeName + SC);
}
return importLines;
}
+ public static boolean isConstantInTO(String constName, GeneratedTransferObject genTO) {
+ if (constName == null || genTO == null)
+ throw new IllegalArgumentException();
+ List<Constant> consts = genTO.getConstantDefinitions();
+ for (Constant cons : consts) {
+ if (cons.getName().equals(constName)) {
+ return true;
+ }
+
+ }
+ return false;
+ }
}
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
public final class InterfaceGenerator implements CodeGenerator {
- private Map<String, LinkedHashMap<String, Integer>> imports;
-
- private String generateEnums(List<Enumeration> enums) {
- String result = "";
- if (enums != null) {
- EnumGenerator enumGenerator = new EnumGenerator();
- for (Enumeration en : enums) {
- try {
- result = result
- + (enumGenerator.generateInnerEnumeration(en, TAB).toString() + NL);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return result;
- }
-
- private String generateConstants(List<Constant> constants, String pkgName) {
- String result = "";
- if (constants != null) {
- for (Constant c : constants) {
- result = result
- + GeneratorUtil
- .createConstant(c, TAB, imports, pkgName) + NL;
- }
- result.concat(NL);
- }
- return result;
- }
-
- public String generateMethods(List<MethodSignature> methods, String pkgName) {
- String result = "";
-
- if (methods != null) {
- for (MethodSignature m : methods) {
- result = result
- + GeneratorUtil.createMethodDeclaration(m, TAB,
- imports, pkgName) + NL;
- }
- result = result + NL;
- }
- return result;
- }
-
- public Writer generate(Type type) throws IOException {
- Writer writer = new StringWriter();
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
- GeneratedType genType = (GeneratedType) type;
- imports = GeneratorUtil.createImports(genType);
-
- final String currentPkg = genType.getPackageName();
- final List<Constant> constants = genType.getConstantDefinitions();
- final List<MethodSignature> methods = genType
- .getMethodDefinitions();
- final List<Enumeration> enums = genType.getEnumDefintions();
-
- writer.write(GeneratorUtil.createPackageDeclaration(genType
- .getPackageName()));
- writer.write(NL);
-
- List<String> importLines = GeneratorUtil.createImportLines(imports);
- for (String line : importLines) {
- writer.write(line + NL);
- }
- writer.write(NL);
- writer.write(GeneratorUtil.createIfcDeclaration(genType, "",
- imports));
- writer.write(NL);
-
- writer.write(generateEnums(enums));
- writer.write(generateConstants(constants, currentPkg));
- writer.write(generateMethods(methods, currentPkg));
-
- writer.write(RCB);
- }
- return writer;
- }
-
+ private Map<String, String> imports;
+
+ private String generateEnums(List<Enumeration> enums) {
+ String result = "";
+ if (enums != null) {
+ EnumGenerator enumGenerator = new EnumGenerator();
+ for (Enumeration en : enums) {
+ try {
+ result = result + (enumGenerator.generateInnerEnumeration(en, TAB).toString() + NL);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return result;
+ }
+
+ private String generateConstants(List<Constant> constants, String pkgName) {
+ String result = "";
+ if (constants != null) {
+ for (Constant c : constants) {
+ result = result + GeneratorUtil.createConstant(c, TAB, imports, pkgName) + NL;
+ }
+ result.concat(NL);
+ }
+ return result;
+ }
+
+ public String generateMethods(List<MethodSignature> methods, String pkgName) {
+ String result = "";
+
+ if (methods != null) {
+ for (MethodSignature m : methods) {
+ result = result + GeneratorUtil.createMethodDeclaration(m, TAB, imports, pkgName) + NL;
+ }
+ result = result + NL;
+ }
+ return result;
+ }
+
+ public Writer generate(Type type) throws IOException {
+ Writer writer = new StringWriter();
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
+ final GeneratedType genType = (GeneratedType) type;
+ imports = GeneratorUtil.createImports(genType);
+
+ final String currentPkg = genType.getPackageName();
+ final List<Constant> constants = genType.getConstantDefinitions();
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
+ final List<Enumeration> enums = genType.getEnumerations();
+
+ writer.write(GeneratorUtil.createPackageDeclaration(genType.getPackageName()));
+ writer.write(NL);
+
+ final List<String> importLines = GeneratorUtil.createImportLines(imports);
+ for (String line : importLines) {
+ writer.write(line + NL);
+ }
+ writer.write(NL);
+ writer.write(GeneratorUtil.createIfcDeclaration(genType, "", imports));
+ writer.write(NL);
+
+ writer.write(generateEnums(enums));
+ writer.write(generateConstants(constants, currentPkg));
+ writer.write(generateMethods(methods, currentPkg));
+
+ writer.write(RCB);
+ }
+ return writer;
+ }
}
"simple.pack", "DefCtor");
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
- propBuilder.addReturnType(Types.typeForClass(String.class));
+ propBuilder.setReturnType(Types.typeForClass(String.class));
propBuilder.setReadOnly(false);
propBuilder = toBuilder.addProperty("bar");
- propBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propBuilder.setReturnType(Types.typeForClass(Integer.class));
propBuilder.setReadOnly(false);
final GeneratedTransferObject genTO = toBuilder.toInstance();
"simple.pack", "DefCtor");
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
- propBuilder.addReturnType(Types.typeForClass(String.class));
+ propBuilder.setReturnType(Types.typeForClass(String.class));
propBuilder.setReadOnly(false);
toBuilder.addToStringProperty(propBuilder);
propBuilder = toBuilder.addProperty("bar");
- propBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propBuilder.setReturnType(Types.typeForClass(Integer.class));
propBuilder.setReadOnly(false);
toBuilder.addToStringProperty(propBuilder);
final GeneratedTransferObject genTO = toBuilder.toInstance();
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>binding-generator</artifactId>\r
- <version>0.5.1-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>binding-model-api</artifactId>\r
</project>
\ No newline at end of file
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * Enum definition which provides four access modifiers that are described\r
+ * in Java programming language (Default, Private, Protected, Public).\r
+ */\r
public enum AccessModifier {\r
- PRIVATE, PUBLIC, PROTECTED\r
+ DEFAULT, PRIVATE, PUBLIC, PROTECTED\r
}\r
import java.util.List;
-
+/**
+ * The Annotation Type interface is designed to hold information about
+ * annotation for any type that could be annotated in Java.
+ * <br>
+ * For sake of simplicity the Annotation Type is not designed to model exact
+ * behaviour of annotation mechanism, but just to hold information needed to
+ * model annotation over java Type definition.
+ */
public interface AnnotationType extends Type {
-
+
+ /**
+ * Returns the List of Annotations.
+ * <br>
+ * Each Annotation Type MAY have defined multiple Annotations.
+ *
+ * @return the List of Annotations.
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ * Returns Parameter Definition assigned for given parameter name.
+ * <br>
+ * If Annotation does not contain parameter with specified param name,
+ * the method MAY return <code>null</code> value.
+ *
+ * @param paramName Parameter Name
+ * @return Parameter Definition assigned for given parameter name.
+ */
public Parameter getParameter(final String paramName);
-
+
+ /**
+ * Returns List of all parameters assigned to Annotation Type.
+ *
+ * @return List of all parameters assigned to Annotation Type.
+ */
public List<Parameter> getParameters();
-
+
+ /**
+ * Returns List of parameter names.
+ *
+ * @return List of parameter names.
+ */
public List<String> getParameterNames();
-
+
+ /**
+ * Returns <code>true</code> if annotation contains parameters.
+ *
+ * @return <code>true</code> if annotation contains parameters.
+ */
public boolean containsParameters();
-
+
+ /**
+ * Annotation Type parameter interface. For simplicity the Parameter
+ * contains values and value types as Strings. Every annotation which
+ * contains parameters could contain either single parameter or array of
+ * parameters. To model this purposes the by contract if the parameter
+ * contains single parameter the {@link #getValues()} method will return
+ * empty List and {@link #getValue()} MUST always return non-<code>null</code>
+ * parameter. If the Parameter holds List of values the singular {@link
+ * #getValue()} parameter MAY return <code>null</code> value.
+ */
interface Parameter {
-
+
+ /**
+ * Returns the Name of the parameter.
+ *
+ * @return the Name of the parameter.
+ */
public String getName();
-
+
+ /**
+ * Returns value in String format if Parameter contains singular value,
+ * otherwise MAY return <code>null</code>.
+ *
+ * @return value in String format if Parameter contains singular value.
+ */
public String getValue();
-
+
+ /**
+ * Returns List of Parameter assigned values in order in which they
+ * were assigned for given parameter name.
+ * <br>
+ * If there are multiple values assigned for given parameter name the
+ * method MUST NOT return empty List.
+ *
+ * @return List of Parameter assigned values in order in which they
+ * were assigned for given parameter name.
+ */
public List<String> getValues();
}
}
import java.io.IOException;\r
import java.io.Writer;\r
\r
+/**\r
+ *\r
+ *\r
+ */\r
public interface CodeGenerator {\r
\r
+ /**\r
+ *\r
+ * @param type\r
+ * @return\r
+ * @throws IOException\r
+ */\r
Writer generate(Type type) throws IOException;\r
\r
}\r
*/
package org.opendaylight.controller.sal.binding.model.api;
+/**
+ * The Concrete Type is marker interface that encapsulates definition of java
+ * concrete type.
+ */
public interface ConcreteType extends Type {
}
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * Interface Contact is designed to hold and model java constant. In Java\r
+ * there are no constant keywords instead of the constant is defined as\r
+ * static final field with assigned value. For this purpose the Constant\r
+ * interface contains methods {@link #getType()} to provide wrapped return\r
+ * Type of Constant, {@link #getName()} the Name of constant and the {@link\r
+ * #getValue()} for providing of value assigned to Constant. To determine of\r
+ * which type the constant value is it is recommended firstly to retrieve\r
+ * Type from constant. The Type interface holds base information like java\r
+ * package name and java type name (e.g. fully qualified name). From this\r
+ * string user should be able to determine to which type can be {@link\r
+ * #getValue()} type typecasted to unbox and provide value assigned to\r
+ * constant.\r
+ */\r
public interface Constant {\r
\r
+ /**\r
+ * Returns the Type that declares constant.\r
+ *\r
+ * @return the Type that declares constant.\r
+ */\r
public Type getDefiningType();\r
\r
+ /**\r
+ * Returns the return Type (or just Type) of the Constant.\r
+ *\r
+ * @return the return Type (or just Type) of the Constant.\r
+ */\r
public Type getType();\r
\r
+ /**\r
+ * Returns the name of constant.\r
+ * <br>\r
+ * By conventions the name SHOULD be in CAPITALS separated with\r
+ * underscores.\r
+ *\r
+ * @return the name of constant.\r
+ */\r
public String getName();\r
\r
+ /**\r
+ * Returns boxed value that is assigned for context.\r
+ *\r
+ * @return boxed value that is assigned for context.\r
+ */\r
public Object getValue();\r
\r
+ /**\r
+ * Returns Constant definition in formatted string.\r
+ * <br>\r
+ * <br>\r
+ * The expected string SHOULD be in format: <code>public final\r
+ * static [Type] CONSTANT_NAME = [value];</code>\r
+ *\r
+ * @return Constant definition in formatted string.\r
+ */\r
public String toFormattedString();\r
}\r
import java.util.List;
+/**
+ *
+ */
public interface Enumeration extends Type {
-
+
+ /**
+ *
+ * @return
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ *
+ * @return
+ */
public Type getDefiningType();
+ /**
+ *
+ * @return
+ */
public List<Pair> getValues();
+ /**
+ *
+ * @return
+ */
public String toFormattedString();
+ /**
+ *
+ */
interface Pair {
public String getName();
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
-public interface GeneratedProperty extends MethodSignature {\r
+/**\r
+ * Generated Property extends interface {@link MethodSignature} interface.\r
+ * <br>\r
+ * The Generated Property interface is designed to store information of\r
+ * fields (or members) declared in Java Transfer Objects (or any java\r
+ * classes) and their access counterparts (getters and setters).\r
+ *\r
+ * @see MethodSignature\r
+ */\r
+public interface GeneratedProperty extends TypeMember {\r
\r
+ /**\r
+ * Returns <code>true</code> if the property si declared as read-only.\r
+ * <br>\r
+ * If the property has flag <code>isReadOnly == true</code> the property\r
+ * SHOULD be generated as getter only.\r
+ *\r
+ * @return <code>true</code> if the property si declared as read-only.\r
+ */\r
public boolean isReadOnly();\r
-\r
- public boolean isFinal();\r
}\r
import java.util.List;
+/**
+ * Generated Transfer Object extends {@link GeneratedType} and is designed to
+ * represent Java Class. The Generated Transfer Object contains declarations
+ * of member fields stored in List of Properties. The Generated Transfer
+ * Object can be extended by exactly ONE Generated Transfer Object as Java
+ * don't allow multiple inheritance. For retrieval of implementing Generated
+ * Types use {@link #getImplements()} method.
+ * <br>
+ * Every transfer object SHOULD contain equals, hashCode and toString definitions.
+ * For this purpose retrieve definitions through {@link #getEqualsIdentifiers
+ * ()}, {@link #getHashCodeIdentifiers()} and {@link #getToStringIdentifiers
+ * ()}.
+ *
+ */
public interface GeneratedTransferObject extends GeneratedType {
-
+
+ /**
+ * Returns the extending Generated Transfer Object or <code>null</code>
+ * if there is no extending Generated Transfer Object.
+ *
+ * @return the extending Generated Transfer Object or <code>null</code>
+ * if there is no extending Generated Transfer Object.
+ */
public GeneratedTransferObject getExtends();
-
+
+ /**
+ * Returns List of Properties that are declared for Generated Transfer
+ * Object.
+ *
+ * @return List of Properties that are declared for Generated Transfer
+ * Object.
+ */
public List<GeneratedProperty> getProperties();
-
+
+ /**
+ * Returns List of Properties that are designated to define equality for
+ * Generated Transfer Object.
+ *
+ * @return List of Properties that are designated to define equality for
+ * Generated Transfer Object.
+ */
public List<GeneratedProperty> getEqualsIdentifiers();
-
+
+ /**
+ * Returns List of Properties that are designated to define identity for
+ * Generated Transfer Object.
+ *
+ * @return List of Properties that are designated to define identity for
+ * Generated Transfer Object.
+ */
public List<GeneratedProperty> getHashCodeIdentifiers();
-
+
+ /**
+ * Returns List of Properties that will be members of toString definition
+ * for Generated Transfer Object.
+ *
+ * @return List of Properties that will be members of toString definition
+ * for Generated Transfer Object.
+ */
public List<GeneratedProperty> getToStringIdentifiers();
}
* <li><code>interface</code> name (with commentary that <b>SHOULD</b> be
* present to proper define interface and base <i>contracts</i> specified for
* interface)</li>
+ * <li>Each Generated Type can define list of types that Generated Type
+ * can implement to extend it's definition (i.e. interface extends list of
+ * interfaces or java class implements list of interfaces)</li>
+ * <li>Each Generated Type can contain multiple enclosed definitions of
+ * Generated Types (i.e. interface can contain N enclosed interface
+ * definitions or enclosed classes)</li>
* <li><code>enum</code> and <code>constant</code> definitions (i.e. each
* constant definition is by default defined as <code>public static final</code>
* + type (either primitive or object) and constant name</li>
* types) and return values</li>
* </ul>
*
- * By the definition of the interface constant, enum and method definitions MUST
+ * By the definition of the interface constant, enum,
+ * enclosed types and method definitions MUST
* be public, so there is no need to specify the scope of visibility.
- *
- *
*/
public interface GeneratedType extends Type {
+ /**
+ * Returns the parent type if Generated Type is defined as enclosing type,
+ * otherwise returns <code>null</code>
+ *
+ * @return the parent type if Generated Type is defined as enclosing type,
+ * otherwise returns <code>null</code>
+ */
public Type getParentType();
-
+
+ /**
+ * Returns comment string associated with Generated Type.
+ *
+ * @return comment string associated with Generated Type.
+ */
public String getComment();
-
+
+ /**
+ * Returns List of annotation definitions associated with generated type.
+ *
+ * @return List of annotation definitions associated with generated type.
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ * Returns <code>true</code> if The Generated Type is defined as abstract.
+ *
+ * @return <code>true</code> if The Generated Type is defined as abstract.
+ */
+ public boolean isAbstract();
+
+ /**
+ * Returns List of Types that Generated Type will implement.
+ *
+ * @return List of Types that Generated Type will implement.
+ */
public List<Type> getImplements();
-
+
/**
- * Returns Set of all Enumerator definitions associated with interface.
- *
- * @return Set of all Enumerator definitions associated with interface.
+ * Returns List of enclosing Generated Types.
+ *
+ * @return List of enclosing Generated Types.
*/
- public List<Enumeration> getEnumDefintions();
+ public List<GeneratedType> getEnclosedTypes();
/**
+ * Returns List of all Enumerator definitions associated with Generated
+ * Type.
*
- *
- * @return
+ * @return List of all Enumerator definitions associated with Generated
+ * Type.
+ */
+ public List<Enumeration> getEnumerations();
+
+ /**
+ * Returns List of Constant definitions associated with Generated Type.
+ *
+ * @return List of Constant definitions associated with Generated Type.
*/
public List<Constant> getConstantDefinitions();
/**
+ * Returns List of Method Definitions associated with Generated Type.
*
- *
- * @return
+ * @return List of Method Definitions associated with Generated Type.
*/
public List<MethodSignature> getMethodDefinitions();
-
}
import java.util.List;
-public interface MethodSignature {
-
- public List<AnnotationType> getAnnotations();
-
- public String getName();
-
- public String getComment();
-
- public Type getDefiningType();
+/**
+ * The Method Signature interface contains simplified meta model for java
+ * method definition. Each method MUST be defined by name, return type,
+ * parameters and access modifier.
+ * <br>
+ * Additionally method MAY contain associated annotations and comment. By
+ * contract if method does not contain any comments or annotation definitions
+ * the {@link #getComment()} SHOULD rather return empty string and {@link
+ * #getAnnotations()} SHOULD rather return empty list than <code>null</code>
+ * values.
+ * <br>
+ * The defining Type contains the reference to Generated Type that declares
+ * Method Signature.
+ */
+public interface MethodSignature extends TypeMember {
- public Type getReturnType();
+ /**
+ * Returns <code>true</code> if the method signature is defined as abstract.
+ * <br>
+ * By default in java all method declarations in interface are defined as abstract,
+ * but the user don't need necessary to declare abstract keyword in front of each method.
+ * <br>
+ * The abstract methods are allowed in Class definitions but only when the class is declared as abstract.
+ *
+ * @return <code>true</code> if the method signature is defined as abstract.
+ */
+ public boolean isAbstract();
+ /**
+ * Returns the List of parameters that method declare. If the method does
+ * not contain any parameters, the method will return empty List.
+ *
+ * @return the List of parameters that method declare.
+ */
public List<Parameter> getParameters();
- public AccessModifier getAccessModifier();
-
+ /**
+ * The Parameter interface is designed to hold the information of method
+ * Parameter(s). The parameter is defined by his Name which MUST be
+ * unique as java does not allow multiple parameters with same names for
+ * one method and Type that is associated with parameter.
+ */
interface Parameter {
+
+ /**
+ * Returns the parameter name.
+ *
+ * @return the parameter name.
+ */
public String getName();
+ /**
+ * Returns Type that is bounded to parameter name.
+ *
+ * @return Type that is bounded to parameter name.
+ */
public Type getType();
}
}
\r
/**\r
* Represents an instance of simple parametrized type such as List<String>.\r
+ *\r
+ * The parametrized Type is designed to be used to store information of Java\r
+ * Generic Type. The array of {@link #getActualTypeArguments()} holds\r
+ * information of all generic parameters defined for Parameterized Type.\r
*/\r
public interface ParameterizedType extends Type {\r
\r
+ /**\r
+ * Returns array of Types that are defined for Parameterized Type.\r
+ * <br>\r
+ * (for example if ParameterizedType encapsulates java generic Map that\r
+ * specifies two parameters Map<K,V> and the K is java.lang.Integer and V\r
+ * is defined as GeneratedType the array will contain two Types to store\r
+ * the information of generic parameters.)\r
+ *\r
+ * @return array of Types that are defined for Parameterized Type.\r
+ */\r
Type[] getActualTypeArguments();\r
\r
+ /**\r
+ * Returns the Raw Type definition of Parameterized Type.\r
+ *\r
+ * @return the Raw Type definition of Parameterized Type.\r
+ */\r
Type getRawType();\r
}\r
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * The Type interface defines the base type for all types defined in java.\r
+ * Each Type defined in java MUST contain name and package name,\r
+ * except of primitive types like int, byte etc. In case of mapping of\r
+ * primitive type the package name MUST be left as empty string.\r
+ *\r
+ */\r
public interface Type {\r
/**\r
* Returns name of the package that interface belongs to.\r
* @return name of the interface.\r
*/\r
public String getName();\r
+\r
+ /**\r
+ * Returns fully qualified name of Type.\r
+ * <br>\r
+ * The fully qualified name of Type MUST be returned in following format:\r
+ * <ul>\r
+ * <li>If does not contains package name: [type name] (e.g. int, byte,\r
+ * byte[],...)</li>\r
+ * <li>If Type contains package name: [package name].[type name]\r
+ * (e.g java.lang.Byte, org.opendaylight.controller.gen.GenType)</li>\r
+ * </ul>\r
+ *\r
+ * @return fully qualified name of Type.\r
+ */\r
+ public String getFullyQualifiedName();\r
}\r
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.model.api;
+
+import java.util.List;
+
+public interface TypeMember {
+
+ /**
+ * Returns List of annotation definitions associated with generated type.
+ *
+ * @return List of annotation definitions associated with generated type.
+ */
+ public List<AnnotationType> getAnnotations();
+
+ /**
+ * Returns the name of method.
+ *
+ * @return the name of method.
+ */
+ public String getName();
+
+ /**
+ * Returns comment string associated with method.
+ *
+ * @return comment string associated with method.
+ */
+ public String getComment();
+
+ /**
+ * Returns the Type that declares method.
+ *
+ * @return the Type that declares method.
+ */
+ public Type getDefiningType();
+
+ /**
+ * Returns the access modifier of method.
+ *
+ * @return the access modifier of method.
+ */
+ public AccessModifier getAccessModifier();
+
+ /**
+ * Returns the returning Type that methods returns.
+ *
+ * @return the returning Type that methods returns.
+ */
+ public Type getReturnType();
+
+ /**
+ * Returns <code>true</code> if method is declared as final.
+ *
+ * @return <code>true</code> if method is declared as final.
+ */
+ public boolean isFinal();
+}
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.Type;
+/**
+ * Annotation Type Builder Interface serves for creation and instantiation of
+ * immutable copy of Annotation Type. The Annotation Type Builder extends
+ * from {@link Type} interface. The Annotation Type contains set of methods
+ * which are capable to provide information about other Annotation Types and
+ * Annotation Parameters.
+ *
+ * @see AnnotationType
+ */
public interface AnnotationTypeBuilder extends Type {
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ * Adds the parameter into List of parameters for Annotation Type.
+ * <br>
+ * If there is already stored parameter with the same name as the new
+ * parameter, the value of the old one will be simply overwritten by the
+ * newer parameter.
+ * <br>
+ * Neither the param name or value can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param paramName Parameter Name
+ * @param value Parameter Value
+ * @return <code>true</code> if the parameter has been successfully
+ * assigned for Annotation Type
+ */
public boolean addParameter(final String paramName, String value);
-
+
+ /**
+ * Adds the parameter with specified List of parameter values into List of
+ * parameters for Annotation Type.
+ * <br>
+ * If there is already stored parameter with the same name as the new
+ * parameter, the value of the old one will be simply overwritten by the
+ * newer parameter.
+ * <br>
+ * Neither the param name or value can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param paramName Parameter Name
+ * @param values List of Values bounded to Parameter Name
+ * @return <code>true</code> if the parameter has been successfully
+ * assigned for Annotation Type
+ */
public boolean addParameters(final String paramName, List<String> values);
-
+
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Annotation Type
+ * with values assigned in current instance of Annotation Type Builder.
+ * <br>
+ * The return Annotation Type instance is immutable thus no additional
+ * modification to Annotation Type Builder will have an impact to
+ * instantiated Annotation Type.
+ * <br>
+ * For this purpose call this method after
+ * all additions are complete.
+ *
+ * @return <code>new</code> <i>immutable</i> instance of Annotation Type.
+ */
public AnnotationType toInstance();
}
import org.opendaylight.controller.sal.binding.model.api.Type;\r
\r
/**\r
-\r
*\r
*/\r
public interface ConstantBuilder {\r
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Enum Builder is interface that contains methods to build and instantiate
+ * Enumeration definition.
*
+ * @see Enumeration
*/
public interface EnumBuilder extends Type {
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ *
+ * @param name
+ * @param value
+ */
public void addValue(final String name, final Integer value);
+ /**
+ *
+ * @param definingType
+ * @return
+ */
public Enumeration toInstance(final Type definingType);
}
*/
package org.opendaylight.controller.sal.binding.model.api.type.builder;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Generated Property Builder is interface that contains methods to build and
+ * instantiate Generated Property definition.
*
+ * @see GeneratedProperty
*/
-public interface GeneratedPropertyBuilder {
-
- public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
- public String getName();
-
- public boolean addReturnType(final Type returnType);
-
- public void accessorModifier(final AccessModifier modifier);
-
- public void addComment(final String comment);
-
- public void setFinal(final boolean isFinal);
-
+public interface GeneratedPropertyBuilder extends TypeMemberBuilder {
+
+ /**
+ * Sets isReadOnly flag for property. If property is marked as read only
+ * it is the same as set property in java as final.
+ *
+ * @param isReadOnly Read Only property flag.
+ */
public void setReadOnly(final boolean isReadOnly);
-
+
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Generated
+ * Property.
+ * <br>
+ * The <code>definingType</code> param cannot be <code>null</code>. The
+ * every member in Java MUST be declared and defined inside the scope of
+ * <code>class</code> definition. In case that
+ * defining Type will be passed as <code>null</code> reference the method
+ * SHOULD thrown {@link IllegalArgumentException}.
+ *
+ * @param definingType Defining Type of Generated Property
+ * @return <code>new</code> <i>immutable</i> instance of Generated
+ * Property.
+ */
public GeneratedProperty toInstance(final Type definingType);
}
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
/**
-
+ * Generated Transfer Object Builder is interface that contains methods to
+ * build and instantiate Generated Transfer Object definition.
+ *
+ * @see GeneratedTransferObject
*/
public interface GeneratedTOBuilder extends GeneratedTypeBuilder {
- public boolean addExtendsType(final GeneratedTransferObject genTransObj);
+ /**
+ * Add Generated Transfer Object from which will be extended current
+ * Generated Transfer Object.
+ * <br>
+ * By definition Java does not allow multiple
+ * inheritance, hence if there is already definition of Generated
+ * Transfer Object the extending object will be overwritten by lastly
+ * added Generated Transfer Object.
+ * <br>
+ * If Generated Transfer Object is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param genTransObj Generated Transfer Object
+ */
+ public void setExtendsType(final GeneratedTransferObject genTransObj);
+ /**
+ * Add new Generated Property definition for Generated Transfer Object
+ * Builder and returns Generated Property Builder for specifying Property.
+ * <br>
+ * Name of Property cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Property
+ * @return <code>new</code> instance of Generated Property Builder.
+ */
public GeneratedPropertyBuilder addProperty(final String name);
+ /**
+ * Add Property that will be part of <code>equals</code> definition.
+ * <br>
+ * If Generated Property Builder is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param property Generated Property Builder
+ * @return <code>true</code> if addition of Generated Property into list
+ * of <code>equals</code> properties is successful.
+ */
public boolean addEqualsIdentity(final GeneratedPropertyBuilder property);
+ /**
+ * Add Property that will be part of <code>hashCode</code> definition.
+ * <br>
+ * If Generated Property Builder is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param property Generated Property Builder
+ * @return <code>true</code> if addition of Generated Property into list
+ * of <code>hashCode</code> properties is successful.
+ */
public boolean addHashIdentity(final GeneratedPropertyBuilder property);
+ /**
+ * Add Property that will be part of <code>toString</code> definition.
+ * <br>
+ * If Generated Property Builder is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param property Generated Property Builder
+ * @return <code>true</code> if addition of Generated Property into list
+ * of <code>toString</code> properties is successful.
+ */
public boolean addToStringProperty(final GeneratedPropertyBuilder property);
@Override
public GeneratedTransferObject toInstance();
-
- public GeneratedTransferObject toIdentityInstance();
-
}
*/
package org.opendaylight.controller.sal.binding.model.api.type.builder;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Generated Type Builder interface is helper interface for building and
+ * defining the GeneratedType.
*
+ * @see GeneratedType
*/
public interface GeneratedTypeBuilder extends Type {
- public Type getParentType();
+ /**
+ * Adds new Enclosing Type into definition of Generated Type and returns
+ * <code>new</code> Instance of Generated Type Builder.
+ * <br>
+ * There is no need of specifying of Package Name because enclosing Type
+ * is already defined inside Generated Type with specific package name.
+ * <br>
+ * The name of enclosing Type cannot be same as Name of parent type and
+ * if there is already defined enclosing type with the same name,
+ * the new enclosing type will simply overwrite the older definition.
+ * <br>
+ * If the name of enclosing type is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Enclosing Type
+ * @return <code>new</code> Instance of Generated Type Builder.
+ */
+ public GeneratedTypeBuilder addEnclosingType(final String name);
+
+ /**
+ * Adds new Enclosing Transfer Object into definition of Generated Type
+ * and returns <code>new</code> Instance of Generated TO Builder.
+ * <br>
+ * There is no need of specifying of Package Name because enclosing Type
+ * is already defined inside Generated Type with specific package name.
+ * <br>
+ * The name of enclosing Type cannot be same as Name of parent type and
+ * if there is already defined enclosing type with the same name,
+ * the new enclosing type will simply overwrite the older definition.
+ * <br>
+ * If the name of enclosing type is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Enclosing Type
+ * @return <code>new</code> Instance of Generated Type Builder.
+ */
+ public GeneratedTOBuilder addEnclosingTransferObject(final String name);
+ /**
+ * Adds String definition of comment into Method Signature definition.
+ * <br>
+ * The comment String MUST NOT contain anny comment specific chars (i.e.
+ * "/**" or "//") just plain String text description.
+ *
+ * @param comment Comment String.
+ */
public void addComment(final String comment);
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ * Sets the <code>abstract</code> flag to define Generated Type as <i>abstract</i> type.
+ *
+ * @param isAbstract abstract flag
+ */
+ public void setAbstract(boolean isAbstract);
+
+ /**
+ * Add Type to implements.
+ *
+ * @param genType Type to implement
+ * @return <code>true</code> if the addition of type is successful.
+ */
public boolean addImplementsType(final Type genType);
-
- public ConstantBuilder addConstant(final Type type, final String name,
+
+ /**
+ * Adds Constant definition and returns <code>new</code> Constant instance.
+ * <br>
+ * By definition Constant MUST be defined by return Type,
+ * Name and assigned value. The name SHOULD be defined with cpaital
+ * letters. Neither of method parameters can be <code>null</code> and the
+ * method SHOULD throw {@link IllegalArgumentException} if the contract
+ * is broken.
+ *
+ * @param type Constant Type
+ * @param name Name of Constant
+ * @param value Assigned Value
+ * @return <code>new</code> Constant instance.
+ */
+ public Constant addConstant(final Type type, final String name,
final Object value);
+ /**
+ * Adds new Enumeration definition for Generated Type Builder and returns
+ * Enum Builder for specifying all Enum parameters.
+ * <br>
+ * If there is already Enumeration stored with the same name,
+ * the old enum will be simply overwritten byt new enum definition.
+ * <br>
+ * Name of Enumeration cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param name Enumeration Name
+ * @return <code>new</code> instance of Enumeration Builder.
+ */
public EnumBuilder addEnumeration(final String name);
+ /**
+ * Add new Method Signature definition for Generated Type Builder and
+ * returns Method Signature Builder for specifying all Method parameters.
+ * <br>
+ * Name of Method cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ * <br>
+ * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
+ * {@link MethodSignatureBuilder#setAbstract(true)}, {@link MethodSignatureBuilder#setFinal(false)} and
+ * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}
+ *
+ * @param name Name of Method
+ * @return <code>new</code> instance of Method Signature Builder.
+ */
public MethodSignatureBuilder addMethod(final String name);
+ /**
+ * Returns the <code>new</code> <i>immutable</i> instance of Generated
+ * Type.
+ *
+ * @return the <code>new</code> <i>immutable</i> instance of Generated
+ * Type.
+ */
public GeneratedType toInstance();
}
import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.Type;
-public interface MethodSignatureBuilder {
-
- public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
- public void addReturnType(final Type returnType);
+/**
+ * Method Signature Builder serves solely for building Method Signature and
+ * returning the <code>new</code> instance of Method Signature.
+ * <br>
+ * By definition of {@link MethodSignature} the Method in java MUST contain
+ * Name, Return Type and Access Modifier. By default the Access Modifier can
+ * be set to public. The Method Signature builder does not contain method for
+ * addName due to enforce reason that MethodSignatureBuilder SHOULD be
+ * instantiated only once with defined method name.
+ * <br>
+ * The methods as {@link #addAnnotation(String, String)} and {@link #setComment(String)}
+ * can be used as optional because not all methods MUST contain annotation or
+ * comment definitions.
+ *
+ *
+ * @see MethodSignature
+ */
+public interface MethodSignatureBuilder extends TypeMemberBuilder {
- public void addParameter(final Type type, final String name);
+ /**
+ * Sets the flag for declaration of method as abstract or non abstract. If the flag <code>isAbstract == true</code>
+ * The instantiated Method Signature MUST have return value for {@link org.opendaylight.controller.sal.binding
+ * .model.api.MethodSignature#isAbstract()} also equals to <code>true</code>.
+ *
+ * @param isAbstract is abstract flag
+ */
+ public void setAbstract(boolean isAbstract);
- public void addComment(final String comment);
+ /**
+ * Adds Parameter into the List of method parameters. Neither the Name or
+ * Type of parameter can be <code>null</code>.
+ *
+ * <br>
+ * In case that any of parameters are defined as <code>null</code> the
+ * method SHOULD throw an {@link IllegalArgumentException}
+ *
+ * @param type Parameter Type
+ * @param name Parameter Name
+ */
+ public void addParameter(final Type type, final String name);
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Method Signature.
+ * <br>
+ * The <code>definingType</code> param cannot be <code>null</code>. The
+ * every method in Java MUST be declared and defined inside the scope of
+ * <code>class</code> or <code>interface</code> definition. In case that
+ * defining Type will be passed as <code>null</code> reference the method
+ * SHOULD thrown {@link IllegalArgumentException}.
+ *
+ * @param definingType Defining Type of Method Signature
+ * @return <code>new</code> <i>immutable</i> instance of Method Signature.
+ */
public MethodSignature toInstance(final Type definingType);
}
--- /dev/null
+package org.opendaylight.controller.sal.binding.model.api.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+/**
+ *
+ */
+public interface TypeMemberBuilder {
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
+ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
+
+ /**
+ * Returns the name of property.
+ *
+ * @return the name of property.
+ */
+ public String getName();
+
+ /**
+ * Adds return Type into Builder definition for Generated Property.
+ * <br>
+ * The return Type MUST NOT be <code>null</code>,
+ * otherwise the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param returnType Return Type of property.
+ */
+ public void setReturnType(final Type returnType);
+
+ /**
+ * Sets the access modifier of property.
+ *
+ * @param modifier Access Modifier value.
+ */
+ public void setAccessModifier(final AccessModifier modifier);
+
+ /**
+ * Adds String definition of comment into Method Signature definition.
+ * <br>
+ * The comment String MUST NOT contain anny comment specific chars (i.e.
+ * "/**" or "//") just plain String text description.
+ *
+ * @param comment Comment String.
+ */
+ public void setComment(final String comment);
+
+ /**
+ * Sets the flag final for method signature. If this is set the method will be prohibited from overriding.
+ * <br>
+ * This setting is irrelevant for methods designated to be defined in interface definitions because interface
+ * can't have final method.
+ *
+ * @param isFinal Is Final
+ */
+ public void setFinal(final boolean isFinal);
+}
<parent>
<artifactId>binding-generator</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</parent>
<artifactId>maven-sal-api-gen-plugin</artifactId>
File outputBaseDir, Set<Module> yangModules) throws IOException {
final BindingGenerator bindingGenerator = new BindingGeneratorImpl();
- final List<Type> types = bindingGenerator.generateTypes(context);
+ final List<Type> types = bindingGenerator.generateTypes(context,yangModules);
final Set<GeneratedType> typesToGenerate = new HashSet<>();
final Set<GeneratedTransferObject> tosToGenerate = new HashSet<>();
final Set<Enumeration> enumsToGenerate = new HashSet<>();
<parent>
<artifactId>yang</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<relativePath>../../yang/pom.xml</relativePath>
</parent>
<artifactId>yang-maven-plugin-it</artifactId>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</dependency>
</dependencies>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</dependency>
</dependencies>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<groupId>org.opendaylight.controller</groupId>
<artifactId>generator-test1</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>generator-test2</artifactId>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>generator-test1</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<scope>system</scope>
- <systemPath>${project.basedir}/../GenerateTest1/target/generator-test1-0.5.1-SNAPSHOT.jar</systemPath>
+ <systemPath>${project.basedir}/../GenerateTest1/target/generator-test1-0.5.3-SNAPSHOT.jar</systemPath>
</dependency>
</dependencies>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<parent>
<artifactId>binding-generator</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</parent>
<artifactId>test</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>generator-test2</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<build>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin-spi</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>test</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<parent>
<artifactId>yang</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<relativePath>../../yang/pom.xml</relativePath>
</parent>
<parent>
<artifactId>yang</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<relativePath>../../yang/pom.xml</relativePath>
</parent>
<artifactId>yang-maven-plugin-spi</artifactId>
<artifactId>yang-prototype</artifactId>
<version>0.5-SNAPSHOT</version>
</parent>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>binding-generator</artifactId>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- version of YANG tools dependencies -->
- <yang.version>0.5.2-SNAPSHOT</yang.version>
+ <yang.version>0.5.3-SNAPSHOT</yang.version>
</properties>
<modules>
<parent>
<artifactId>binding-generator</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</parent>
<artifactId>maven-code-gen-sample</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-binding</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
--- /dev/null
+module augment-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:augment-monitoring";
+ prefix "amon";
+
+ import choice-monitoring { prefix nm; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision "2013-07-01" {
+ reference "NO REF";
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" {
+ case autonomous-lock {
+ container autonomous-def {
+ leaf lock-id {
+ type int32;
+ }
+
+ leaf lock-time {
+ type uint32;
+ }
+ }
+ }
+
+ case anonymous-lock {
+ leaf lock-time {
+ type uint32;
+ }
+ }
+
+ leaf leaf-aug-case {
+ type string;
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock" {
+ choice aug-case-by-choice {
+ case foo {
+ leaf foo {
+ type string;
+ }
+ }
+
+ case bar {
+ leaf bar {
+ type boolean;
+ }
+ }
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore" {
+ choice storage-format {
+ case xml {
+ container xml-def {
+ leaf file-name {
+ type string;
+ }
+ }
+ }
+
+ case yang {
+ leaf yang-file-name {
+ type string;
+ }
+ }
+
+ case unknown-files {
+ list files {
+ key "file-name";
+
+ leaf file-name {
+ type string;
+ }
+
+ container file-data {
+ leaf utf8-data {
+ type string;
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module choice-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:choice-monitoring";
+ prefix "ncm";
+
+ import ietf-yang-types { prefix yang; }
+ import ietf-inet-types { prefix inet; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ description
+ "Test model for testing of resolving choice, case nodes and generation types from them.";
+
+ revision 2013-07-01 {
+
+ }
+
+ typedef tls-fingerprint-type {
+ type string {
+ pattern '([0-9a-fA-F]){2}(:([0-9a-fA-F]){2})*';
+ }
+ }
+
+ typedef netconf-datastore-type {
+ type enumeration {
+ enum running;
+ enum candidate;
+ enum startup;
+ }
+ }
+
+ container netconf-state {
+ config false;
+
+ container datastores {
+ list datastore {
+ key name;
+
+ leaf name {
+ type netconf-datastore-type;
+ }
+ container locks {
+ choice lock-type {
+
+ case global-lock {
+ container global-lock {
+
+ leaf locked-by-session {
+ type uint32;
+ mandatory true;
+ }
+
+ leaf locked-time {
+ type yang:date-and-time;
+ mandatory true;
+ }
+
+ container capabilities {
+ leaf-list capability {
+ type inet:uri;
+ }
+ }
+ }
+ }
+
+ case partial-lock {
+ list partial-lock {
+ key lock-id;
+
+ leaf lock-id {
+ type uint32;
+ }
+ leaf-list select {
+ type yang:xpath1.0;
+ min-elements 1;
+ }
+ leaf-list locked-node {
+ type string;
+ }
+ }
+ }
+
+ case fingerprint {
+ choice algorithm-and-hash {
+ mandatory true;
+ case md5 {
+ leaf md5 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha1 {
+ leaf sha1 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha224 {
+ leaf sha224 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha256 {
+ leaf sha256 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha384 {
+ leaf sha384 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha512 {
+ leaf sha512 {
+ type tls-fingerprint-type;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
module controller-openflow-ne {
- yang-version 1;
- namespace "urn:opendaylight:controller:network:openflow";
- prefix "of";
-
- import controller-network {
- prefix cn;
- }
- import ietf-inet-types { prefix "inet"; }
-
- revision 2013-06-07 {
- description "Initial demo";
- }
+ yang-version 1;
+ namespace "urn:opendaylight:controller:network:openflow";
+ prefix "of";
+
+ import controller-network {
+ prefix cn;
+ }
+ import ietf-inet-types { prefix "inet"; }
+
+ revision 2013-06-07 {
+ description "Initial demo";
+ }
- augment "/cn:network/cn:network-elements/cn:network-element" {
+ augment "/cn:network/cn:network-elements/cn:network-element" {
- container flow-tables {
- list flow-table {
+ container flow-tables {
+ list flow-table {
- key "id";
- leaf id {
- type int32;
- }
+ key "id";
+ leaf id {
+ type int32;
+ }
- container flows {
- list flow {
- key "name";
- leaf name {
- type string;
- }
- container match {
- leaf input-port {
- type cn:tp-ref;
- }
- leaf nl-src {
- type inet:ipv4-address;
- }
- leaf nl-dst {
- type inet:ipv4-address;
- }
- }
- container actions {
- list action {
- leaf type {
- type string;
- }
- }
- }
- }
- }
- }
- }
- }
+ container flows {
+ list flow {
+ key "name";
+ leaf name {
+ type string;
+ }
+ container match {
+ leaf input-port {
+ type cn:tp-ref;
+ }
+ leaf nl-src {
+ type inet:ipv4-address;
+ }
+ leaf nl-dst {
+ type inet:ipv4-address;
+ }
+ }
+ container actions {
+ list action {
+ leaf type {
+ type string;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
module controller-network {
- yang-version 1;
- namespace "urn:opendaylight:controller:network";
- prefix "topos";
-
- import ietf-inet-types { prefix "inet"; }
-
- revision 2013-05-20 {
- description "Initial demo";
- }
-
+ yang-version 1;
+ namespace "urn:opendaylight:controller:network";
+ prefix "topos";
+
+ import ietf-inet-types { prefix "inet"; }
+
+ revision 2013-05-20 {
+ description "Initial demo";
+ }
-
- typedef topology-id {
- type string;
- }
+ typedef topology-id {
+ type string;
+ }
- typedef node-id {
- type string;
- }
+ typedef node-id {
+ type string;
+ }
- typedef link-id {
- type string;
- }
+ typedef link-id {
+ type string;
+ }
- typedef tp-id {
- type string;
- description "identifier for termination points on a port";
- }
+ typedef tp-id {
+ type string;
+ description "identifier for termination points on a port";
+ }
- typedef tp-ref {
- type leafref {
- path "/network/topologies/topology/nodes/node/termination-points/termination-point/tp-id";
- }
- }
- typedef topology-ref {
- type leafref {
- path "/network/topologies/topology/topology-id";
- }
- description "This type is used for leafs that reference topology identifier instance.";
- // currently not used
- }
+ typedef tp-ref {
+ type leafref {
+ path "/network/topologies/topology/nodes/node/termination-points/termination-point/tp-id";
+ }
+ }
+ typedef topology-ref {
+ type leafref {
+ path "/network/topologies/topology/topology-id";
+ }
+ description "This type is used for leafs that reference topology identifier instance.";
+ // currently not used
+ }
- typedef node-ref {
- type leafref {
- path "/network/topologies/topology/nodes/node/node-id";
- }
- description "This type is used for leafs that reference a node instance.";
- }
+ typedef node-ref {
+ type leafref {
+ path "/network/topologies/topology/nodes/node/node-id";
+ }
+ description "This type is used for leafs that reference a node instance.";
+ }
- typedef link-ref {
- type leafref {
- path "/network/topologies/topology/links/link/link-id";
- }
- description "This type is used for leafs that reference a link instance.";
- // currently not used
- }
-
- typedef network-element-ref {
- type leafref {
- path "/network/network-elements/network-element/element-id";
- }
- }
+ typedef link-ref {
+ type leafref {
+ path "/network/topologies/topology/links/link/link-id";
+ }
+ description "This type is used for leafs that reference a link instance.";
+ // currently not used
+ }
+
+ typedef network-element-ref {
+ type leafref {
+ path "/network/network-elements/network-element/element-id";
+ }
+ }
+ typedef element-id {
+ type string;
+ }
+
+ container network {
+ container topologies {
+ list topology {
+ description "
+ This is the model of abstract topology which contains only Network
+ Nodes and Network Links. Each topology MUST be identified by
+ unique topology-id for reason that the store could contain many
+ topologies.
+ ";
+ key "topology-id";
+ leaf topology-id {
+ type topology-id;
+ description "
+ It is presumed that datastore will contain many topologies. To
+ distinguish between topologies it is vital to have UNIQUE
+ topology identifier.
+ ";
+ }
- typedef element-id {
- type string;
- }
-
- container network {
- container topologies {
- list topology {
- description "
- This is the model of abstract topology which contains only Network
- Nodes and Network Links. Each topology MUST be identified by
- unique topology-id for reason that the store could contain many
- topologies.
- ";
- key "topology-id";
- leaf topology-id {
- type topology-id;
- description "
- It is presumed that datastore will contain many topologies. To
- distinguish between topologies it is vital to have UNIQUE
- topology identifier.
- ";
- }
+ container types {
+ description "
+ The container for definition of topology types.
+ The augmenting modules should add empty optional leaf
+ to this container to signalize topology type.";
+ }
- container types {
- description "
- The container for definition of topology types.
- The augmenting modules should add empty optional leaf
- to this container to signalize topology type.
- ";
- }
+ container nodes {
+ list node {
+ description "The list of network nodes defined for topology.";
- container nodes {
- list node {
- description "The list of network nodes defined for topology.";
+ key "node-id";
+ leaf node-id {
+ type node-id;
+ description "The Topology identifier of network-node.";
+ }
- key "node-id";
- leaf node-id {
- type node-id;
- description "The Topology identifier of network-node.";
- }
-
- leaf supporting-ne {
- type network-element-ref;
- }
-
- container termination-points {
- list termination-point {
- key "tp-id";
- leaf tp-id {
- type tp-id;
- }
- }
- }
- }
- }
-
- container links {
- list link {
- description "
- The Network Link which is defined by Local (Source) and
- Remote (Destination) Network Nodes. Every link MUST be
- defined either by identifier and his local and remote
- Network Nodes (in real applications it is common that many
- links are originated from one node and end up in same
- remote node). To ensure that we would always know to
- distinguish between links, every link SHOULD have
- identifier.
- ";
- key "link-id";
-
- leaf link-id {
- type link-id;
- }
- container source {
- leaf source-node {
- type node-ref;
- description "Source node identifier.";
- }
- leaf source-tp {
- type tp-ref;
- }
- }
- container destination {
- leaf dest-node {
- type node-ref;
- description "Destination node identifier.";
- }
- leaf dest-tp {
- type tp-ref;
- }
- }
- }
- }
- }
- }
- container network-elements {
- config true;
- list network-element {
- key "element-id";
- leaf element-id {
- type element-id;
- }
- }
- }
- }
+ leaf supporting-ne {
+ type network-element-ref;
+ }
+
+ container termination-points {
+ list termination-point {
+ key "tp-id";
+ leaf tp-id {
+ type tp-id;
+ }
+ }
+ }
+ }
+ }
+
+ container links {
+ list link {
+ description "
+ The Network Link which is defined by Local (Source) and
+ Remote (Destination) Network Nodes. Every link MUST be
+ defined either by identifier and his local and remote
+ Network Nodes (in real applications it is common that many
+ links are originated from one node and end up in same
+ remote node). To ensure that we would always know to
+ distinguish between links, every link SHOULD have
+ identifier.
+ ";
+ key "link-id";
+
+ leaf link-id {
+ type link-id;
+ }
+ container source {
+ leaf source-node {
+ type node-ref;
+ description "Source node identifier.";
+ }
+ leaf source-tp {
+ type tp-ref;
+ }
+ }
+ container destination {
+ leaf dest-node {
+ type node-ref;
+ description "Destination node identifier.";
+ }
+ leaf dest-tp {
+ type tp-ref;
+ }
+ }
+ }
+ }
+ }
+ }
+ container network-elements {
+ config true;
+ list network-element {
+ key "element-id";
+ leaf element-id {
+ type element-id;
+ }
+ }
+ }
+ }
}
revision 2013-06-07 {
description "Initial demo";
}
-
-
-
- augment "/cn:network/cn:network-elements/cn:network-element/of:flow-tables/of:flow-table/of:flows/of:flow/of:match" {
-
- leaf nl-src {
- type inet:ipv6-prefix;
- }
-
- leaf nl-dst {
- type inet:ipv6-prefix;
- }
- }
-
}
\ No newline at end of file
namespace "urn:opendaylight:controller:openflow";
prefix "of";
import controller-network {prefix cn;}
-
-
+
revision 2013-05-20 {
description "Initial demo";
}
-
-
-
-
typedef datapath-id {
type string {
length 16;
--- /dev/null
+module simple-string-demo {
+
+ namespace "urn:simple:string:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-18 {
+
+ }
+
+ typedef typedef-string {
+ type string {
+ length "40";
+ pattern "[0-9A-F]\.*";
+ pattern "[B-D]*";
+ pattern "[4-7]*";
+ }
+ }
+
+}
<parent>
<artifactId>binding-generator</artifactId>
<groupId>org.opendaylight.controller</groupId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
</parent>
<artifactId>modeling-sample</artifactId>
<plugin>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<parent>
<groupId>org.opendaylight.controller</groupId>
<artifactId>yang</artifactId>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<relativePath>../../yang/pom.xml</relativePath>
</parent>
<artifactId>yang-model-parser-api</artifactId>
/**
* Parse one or more Yang model files and return the definitions of Yang
- * modules defined in *.Yang files; <br>
+ * modules defined in *.yang files; <br>
* This method SHOULD be used if user need to parse multiple yang models
* that are referenced either through import or include statements.
*
*/
Set<Module> parseYangModels(final List<File> yangFiles);
+ /**
+ * Parse one or more Yang model files and return the definitions of Yang
+ * modules defined in *.yang files. <br>
+ * This method SHOULD be used if user has already parsed context and need to
+ * parse additinal yang models which can have dependencies on models in this
+ * context.
+ *
+ * @param yangFiles
+ * yang files to parse
+ * @param context
+ * SchemaContext containing already parsed yang models
+ * @return Set of Yang Modules
+ */
+ Set<Module> parseYangModels(final List<File> yangFiles, final SchemaContext context);
+
/**
* Equivalent to {@link #parseYangModels(List)} that returns parsed modules
* mapped to Files from which they were parsed.
*/
Map<File, Module> parseYangModelsMapped(final List<File> yangFiles);
- Set<Module> parseYangModelsFromStreams(
- final List<InputStream> yangModelStreams);
+ /**
+ * Parse one or more Yang model streams and return the definitions of Yang
+ * modules defined in *.yang files; <br>
+ * This method SHOULD be used if user need to parse multiple yang models
+ * that are referenced either through import or include statements.
+ *
+ * @param yangModelStreams
+ * yang streams to parse
+ * @return Set of Yang Modules
+ */
+ Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams);
+
+ /**
+ * Parse one or more Yang model streams and return the definitions of Yang
+ * modules defined in *.yang files. <br>
+ * This method SHOULD be used if user has already parsed context and need to
+ * parse additinal yang models which can have dependencies on models in this
+ * context.
+ *
+ * @param yangModelStreams
+ * yang streams to parse
+ * @param context
+ * SchemaContext containing already parsed yang models
+ * @return Set of Yang Modules
+ */
+ Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams, final SchemaContext context);
- Map<InputStream, Module> parseYangModelsFromStreamsMapped(
- final List<InputStream> yangModelStreams);
+ /**
+ * Equivalent to {@link #parseYangModels(List)} that returns parsed modules
+ * mapped to IputStreams from which they were parsed.
+ *
+ * @param yangModelStreams
+ * yang streams to parse
+ * @return Map of Yang Modules
+ */
+ Map<InputStream, Module> parseYangModelsFromStreamsMapped(final List<InputStream> yangModelStreams);
/**
* Creates {@link SchemaContext} from specified Modules. The modules SHOULD
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
<relativePath>../../yang/pom.xml</relativePath>\r
</parent>\r
<artifactId>yang-model-parser-impl</artifactId>\r
import java.util.Set;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
+ protected final int line;
+ protected final QName qname;
+ protected Builder parent;
- private final QName qname;
- protected final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
- protected final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
+ protected Set<DataSchemaNode> childNodes;
+ protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
- protected AbstractDataNodeContainerBuilder(QName qname) {
+ protected Set<GroupingDefinition> groupings;
+ protected final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
+
+ protected AbstractDataNodeContainerBuilder(final int line, final QName qname) {
+ this.line = line;
this.qname = qname;
}
+ @Override
+ public int getLine() {
+ return line;
+ }
+
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
@Override
public QName getQName() {
return qname;
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ public Set<DataSchemaNode> getChildNodes() {
return childNodes;
}
+ public void setChildNodes(Set<DataSchemaNode> childNodes) {
+ this.childNodes = childNodes;
+ }
+
+ @Override
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
+ return addedChildNodes;
+ }
+
@Override
public void addChildNode(DataSchemaNodeBuilder childNode) {
- childNodes.add(childNode);
+ addedChildNodes.add(childNode);
}
- public Set<GroupingBuilder> getGroupings() {
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
return groupings;
}
+ public void setGroupings(final Set<GroupingDefinition> groupings) {
+ this.groupings = groupings;
+ }
+
+ public Set<GroupingBuilder> getGroupingBuilders() {
+ return addedGroupings;
+ }
+
@Override
public void addGrouping(GroupingBuilder grouping) {
- groupings.add(grouping);
+ addedGroupings.add(grouping);
}
}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.yang.parser.builder.api;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.Status;\r
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;\r
+\r
+/**\r
+ * Basic implementation of SchemaNodeBuilder.\r
+ */\r
+public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {\r
+ protected final int line;\r
+ protected final QName qname;\r
+ protected Builder parent;\r
+ protected SchemaPath schemaPath;\r
+ protected String description;\r
+ protected String reference;\r
+ protected Status status = Status.CURRENT;\r
+ protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
+\r
+ protected AbstractSchemaNodeBuilder(final int line, final QName qname) {\r
+ this.line = line;\r
+ this.qname = qname;\r
+ }\r
+\r
+ @Override\r
+ public int getLine() {\r
+ return line;\r
+ }\r
+\r
+ public QName getQName() {\r
+ return qname;\r
+ }\r
+\r
+ @Override\r
+ public Builder getParent() {\r
+ return parent;\r
+ }\r
+\r
+ @Override\r
+ public void setParent(final Builder parent) {\r
+ this.parent = parent;\r
+ }\r
+\r
+ public SchemaPath getPath() {\r
+ return schemaPath;\r
+ }\r
+\r
+ public void setPath(SchemaPath schemaPath) {\r
+ this.schemaPath = schemaPath;\r
+ }\r
+\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
+ }\r
+\r
+ public String getReference() {\r
+ return reference;\r
+ }\r
+\r
+ public void setReference(String reference) {\r
+ this.reference = reference;\r
+ }\r
+\r
+ public Status getStatus() {\r
+ return status;\r
+ }\r
+\r
+ public void setStatus(Status status) {\r
+ if (status != null) {\r
+ this.status = status;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+ addedUnknownNodes.add(unknownNode);\r
+ }\r
+\r
+}\r
*/
package org.opendaylight.controller.yang.parser.builder.api;
+import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
/**
* Basic implementation for TypeAwareBuilder builders.
*/
public abstract class AbstractTypeAwareBuilder implements TypeAwareBuilder {
-
+ protected final int line;
+ protected final QName qname;
+ protected Builder parent;
protected TypeDefinition<?> type;
protected TypeDefinitionBuilder typedef;
+ public AbstractTypeAwareBuilder(final int line, final QName qname) {
+ this.line = line;
+ this.qname = qname;
+ }
+
+ @Override
+ public int getLine() {
+ return line;
+ }
+
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
@Override
public TypeDefinition<?> getType() {
return type;
*/
package org.opendaylight.controller.yang.parser.builder.api;
-import java.util.Set;
-
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
*/
public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
+ Builder getParent();
+
String getWhenCondition();
void addWhenCondition(String whenCondition);
void setTargetPath(SchemaPath path);
- Set<DataSchemaNodeBuilder> getChildNodes();
-
AugmentationSchema build();
boolean isResolved();
*/
void addAugmentation(AugmentationSchemaBuilder augment);
+ /**
+ * Build again already built data node.
+ *
+ * In general, when Builder.build is called first time, it creates YANG data
+ * model node instance. With every other call it just return this instance
+ * without checking for properties change. This method causes that builder
+ * object process again all its properties and return an updated instance of
+ * YANG data node.
+ */
+ void rebuild();
+
}
*/
package org.opendaylight.controller.yang.parser.builder.api;
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
/**
* Parent interface for all builder interfaces.
*/
public interface Builder {
+ /**
+ * Get current line in yang file.
+ *
+ * @return current line in yang file
+ */
+ int getLine();
+
+ /**
+ * Get parent node of this node.
+ *
+ * @return parent node builder or null if this is top level node
+ */
+ Builder getParent();
+
+ /**
+ * Set parent of this node.
+ *
+ * @param parent
+ * parent node builder
+ */
+ void setParent(Builder parent);
+
+ /**
+ * Build YANG data model node.
+ *
+ * This method should create an instance of YANG data model node. After
+ * creating an instance, this instance should be returned for each call
+ * without repeating build process.
+ *
+ * @return YANG data model node
+ */
Object build();
- int getLine();
+ void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode);
}
package org.opendaylight.controller.yang.parser.builder.api;
/**
- * Builders of all nodes, which can have 'typedef' statement must implement this interface.
- * [module, submodule, container, list, grouping, rpc, input, output, notification]
+ * Interface for all nodes which can have 'config' statement.
+ * [container, leaf, leaf-list, list, choice, anyxml, deviate]
+ *
*/
-public interface TypeDefinitionAwareBuilder {
+public interface ConfigNode {
+
+ Boolean isConfiguration();
- void addTypedef(TypeDefinitionBuilder typedefBuilder);
+ void setConfiguration(Boolean config);
}
import java.util.Set;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.SchemaPath;
/**
QName getQName();
- Set<DataSchemaNodeBuilder> getChildNodes();
+ SchemaPath getPath();
+
+ Set<DataSchemaNode> getChildNodes();
+
+ Set<DataSchemaNodeBuilder> getChildNodeBuilders();
void addChildNode(DataSchemaNodeBuilder childNode);
- Set<GroupingBuilder> getGroupings();
+ Set<GroupingDefinition> getGroupings();
+
+ Set<GroupingBuilder> getGroupingBuilders();
void addGrouping(GroupingBuilder groupingBuilder);
void addUsesNode(UsesNodeBuilder usesBuilder);
- Set<TypeDefinitionBuilder> getTypeDefinitions();
+ Set<TypeDefinitionBuilder> getTypeDefinitionBuilders();
void addTypedef(TypeDefinitionBuilder typedefBuilder);
- SchemaPath getPath();
-
}
DataSchemaNode build();
- void setAugmenting(boolean augmenting);
+ boolean isAugmenting();
- void setConfiguration(boolean configuration);
+ void setAugmenting(boolean augmenting);
ConstraintsBuilder getConstraints();
import java.util.Set;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
/**
* Interface for builders of 'grouping' statement.
*/
-public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
- TypeDefinitionAwareBuilder {
-
- String getDescription();
-
- String getReference();
-
- Status getStatus();
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder, GroupingMember {
GroupingDefinition build();
List<UnknownSchemaNodeBuilder> getUnknownNodes();
- Set<GroupingBuilder> getGroupings();
-
Set<UsesNodeBuilder> getUses();
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.builder.api;
+
+/**
+ * Marker interface for nodes which can be defined in grouping statement.
+ * [anyxml, choice, container, grouping, leaf, leaf-list, list, typedef, uses]
+ */
+public interface GroupingMember extends Builder {
+
+ boolean isAddedByUses();
+
+ void setAddedByUses(boolean addedByUses);
+
+}
\r
void setPath(SchemaPath schemaPath);\r
\r
+ String getDescription();\r
+\r
void setDescription(String description);\r
\r
+ String getReference();\r
+\r
void setReference(String reference);\r
\r
+ Status getStatus();\r
+\r
void setStatus(Status status);\r
\r
void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode);\r
\r
import java.util.List;\r
\r
-import org.opendaylight.controller.yang.model.api.Status;\r
import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;\r
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;\r
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;\r
/**\r
* Interface for builders of 'typedef' statement.\r
*/\r
-public interface TypeDefinitionBuilder extends TypeAwareBuilder,\r
- SchemaNodeBuilder {\r
+public interface TypeDefinitionBuilder extends TypeAwareBuilder, SchemaNodeBuilder, GroupingMember {\r
\r
TypeDefinition<?> build();\r
\r
- String getDescription();\r
-\r
- String getReference();\r
-\r
- Status getStatus();\r
-\r
List<RangeConstraint> getRanges();\r
\r
void setRanges(List<RangeConstraint> ranges);\r
\r
void setFractionDigits(Integer fractionDigits);\r
\r
- List<UnknownSchemaNodeBuilder> getUnknownNodes();\r
+ List<UnknownSchemaNode> getUnknownNodes();\r
+\r
+ List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders();\r
\r
Object getDefaultValue();\r
\r
/**
* Interface for builders of 'uses' statement.
*/
-public interface UsesNodeBuilder extends Builder {
+public interface UsesNodeBuilder extends GroupingMember, Builder {
- String getGroupingName();
+ DataNodeContainerBuilder getParent();
- void setGroupingPath(SchemaPath groupingPath);
+ String getGroupingName();
- SchemaPath getPath();
+ SchemaPath getGroupingPath();
- void setPath(SchemaPath path);
+ void setGroupingPath(SchemaPath groupingPath);
Set<AugmentationSchemaBuilder> getAugmentations();
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
+public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder, GroupingMember,
+ ConfigNode {
private boolean built;
- private final int line;
- private final QName qname;
- private SchemaPath path;
private final AnyXmlSchemaNodeImpl instance;
private final ConstraintsBuilder constraints;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ private List<UnknownSchemaNode> unknownNodes;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
- private boolean configuration;
+ private Boolean configuration;
private boolean augmenting;
+ private boolean addedByUses;
- public AnyXmlBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public AnyXmlBuilder(final int line, final QName qname, final SchemaPath schemaPath) {
+ super(line, qname);
+ this.schemaPath = schemaPath;
instance = new AnyXmlSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public AnyXmlBuilder(final AnyXmlBuilder builder) {
+ super(builder.getLine(), builder.getQName());
+ parent = builder.getParent();
+ instance = new AnyXmlSchemaNodeImpl(qname);
+ constraints = builder.getConstraints();
+ schemaPath = builder.getPath();
+ unknownNodes = builder.unknownNodes;
+ addedUnknownNodes.addAll(builder.getUnknownNodes());
+ description = builder.getDescription();
+ reference = builder.getReference();
+ status = builder.getStatus();
+ configuration = builder.isConfiguration();
+ augmenting = builder.isAugmenting();
+ addedByUses = builder.isAddedByUses();
+ }
+
@Override
public AnyXmlSchemaNode build() {
if (!built) {
- instance.setPath(path);
+ instance.setPath(schemaPath);
instance.setConstraints(constraints.build());
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
instance.setConfiguration(configuration);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
}
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
instance.setUnknownSchemaNodes(unknownNodes);
built = true;
}
@Override
- public int getLine() {
- return line;
+ public ConstraintsBuilder getConstraints() {
+ return constraints;
}
- @Override
- public QName getQName() {
- return qname;
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
}
- public SchemaPath getPath() {
- return path;
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
}
@Override
- public void setPath(final SchemaPath path) {
- this.path = path;
+ public boolean isAugmenting() {
+ return augmenting;
}
@Override
- public ConstraintsBuilder getConstraints() {
- return constraints;
+ public void setAugmenting(final boolean augmenting) {
+ this.augmenting = augmenting;
}
@Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
- return addedUnknownNodes;
- }
-
- public String getDescription() {
- return description;
+ public boolean isAddedByUses() {
+ return addedByUses;
}
@Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- public String getReference() {
- return reference;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
@Override
- public void setReference(final String reference) {
- this.reference = reference;
- }
-
- public Status getStatus() {
- return status;
+ public Boolean isConfiguration() {
+ return configuration;
}
@Override
- public void setStatus(final Status status) {
- if (status != null) {
- this.status = status;
- }
+ public void setConfiguration(final Boolean configuration) {
+ this.configuration = configuration;
}
@Override
- public void setAugmenting(final boolean augmenting) {
- this.augmenting = augmenting;
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
}
- public boolean isConfiguration() {
- return configuration;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AnyXmlBuilder other = (AnyXmlBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
}
@Override
- public void setConfiguration(final boolean configuration) {
- instance.setConfiguration(configuration);
+ public String toString() {
+ return "anyxml " + qname.getLocalName();
}
private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
private boolean configuration;
private ConstraintDefinition constraintsDef;
private boolean augmenting;
+ private boolean addedByUses;
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private AnyXmlSchemaNodeImpl(final QName qname) {
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- AnyXmlSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
*/
package org.opendaylight.controller.yang.parser.builder.impl;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
import org.opendaylight.controller.yang.parser.util.YangParseException;
private boolean built;
private final AugmentationSchemaImpl instance;
private final int line;
+ private Builder parent;
+
+ private String whenCondition;
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
+
private final String augmentTargetStr;
- private SchemaPath augmentTarget;
+ private SchemaPath dirtyAugmentTarget;
private SchemaPath finalAugmentTarget;
- private String whenCondition;
+
private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private boolean resolved;
- AugmentationSchemaBuilderImpl(final String augmentTargetStr, final int line) {
+ AugmentationSchemaBuilderImpl(final int line, final String augmentTargetStr) {
this.augmentTargetStr = augmentTargetStr;
this.line = line;
- final SchemaPath targetPath = YangModelBuilderUtil
- .parseAugmentPath(augmentTargetStr);
- augmentTarget = targetPath;
+ final SchemaPath targetPath = YangModelBuilderUtil.parseAugmentPath(augmentTargetStr);
+ dirtyAugmentTarget = targetPath;
instance = new AugmentationSchemaImpl(targetPath);
}
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
@Override
public void addChildNode(DataSchemaNodeBuilder childNode) {
childNodes.add(childNode);
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ public Set<DataSchemaNode> getChildNodes() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
return childNodes;
}
@Override
- public Set<GroupingBuilder> getGroupings() {
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<GroupingBuilder> getGroupingBuilders() {
return groupings;
}
@Override
public AugmentationSchema build() {
if (!built) {
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
instance.setTargetPath(finalAugmentTarget);
RevisionAwareXPath whenStmt;
instance.setWhenCondition(whenStmt);
// CHILD NODES
- final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
+ final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
for (DataSchemaNodeBuilder node : childNodes) {
childs.put(node.getQName(), node.build());
}
instance.setChildNodes(childs);
// GROUPINGS
- final Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();
+ final Set<GroupingDefinition> groupingDefinitions = new TreeSet<GroupingDefinition>(
+ Comparators.SCHEMA_NODE_COMP);
for (GroupingBuilder builder : groupings) {
groupingDefinitions.add(builder.build());
}
}
instance.setUses(usesNodeDefinitions);
+ // UNKNOWN NODES
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+ instance.setUnknownSchemaNodes(unknownNodes);
+
built = true;
}
return instance;
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return Collections.emptySet();
}
@Override
public void addTypedef(TypeDefinitionBuilder type) {
- throw new YangParseException(line,
- "Augmentation can not contains type definitions");
+ throw new YangParseException(line, "Augmentation can not contains typedef statement.");
}
@Override
public void setDescription(String description) {
- instance.setDescription(description);
+ this.description = description;
}
@Override
public void setReference(String reference) {
- instance.setReference(reference);
+ this.reference = reference;
}
@Override
public void setStatus(Status status) {
- instance.setStatus(status);
+ if (status != null) {
+ this.status = status;
+ }
}
@Override
public SchemaPath getTargetPath() {
- return augmentTarget;
+ return dirtyAugmentTarget;
}
@Override
return augmentTargetStr;
}
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
@Override
public int hashCode() {
final int prime = 17;
int result = 1;
- result = prime
- * result
- + ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
- result = prime * result
- + ((whenCondition == null) ? 0 : whenCondition.hashCode());
- result = prime * result
- + ((childNodes == null) ? 0 : childNodes.hashCode());
+ result = prime * result + ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
+ result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+ result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
return result;
}
return true;
}
+ public String toString() {
+ return "augment " + augmentTargetStr;
+ }
+
private final class AugmentationSchemaImpl implements AugmentationSchema {
private SchemaPath targetPath;
private RevisionAwareXPath whenCondition;
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<UsesNode> uses = Collections.emptySet();
-
private String description;
private String reference;
private Status status;
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private AugmentationSchemaImpl(SchemaPath targetPath) {
this.targetPath = targetPath;
@Override
public Set<DataSchemaNode> getChildNodes() {
- return new HashSet<DataSchemaNode>(childNodes.values());
+ final Set<DataSchemaNode> result = new TreeSet<DataSchemaNode>(Comparators.SCHEMA_NODE_COMP);
+ result.addAll(childNodes.values());
+ return result;
}
private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
this.status = status;
}
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+ if (unknownSchemaNodes != null) {
+ this.unknownNodes = unknownSchemaNodes;
+ }
+ }
+
@Override
public DataSchemaNode getDataChildByName(QName name) {
return childNodes.get(name);
public int hashCode() {
final int prime = 17;
int result = 1;
- result = prime * result
- + ((targetPath == null) ? 0 : targetPath.hashCode());
- result = prime * result
- + ((whenCondition == null) ? 0 : whenCondition.hashCode());
- result = prime * result
- + ((childNodes == null) ? 0 : childNodes.hashCode());
+ result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
+ result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+ result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
return result;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- AugmentationSchemaImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
sb.append("[");
sb.append("targetPath=" + targetPath);
- sb.append(", childNodes=" + childNodes.values());
- sb.append(", groupings=" + groupings);
- sb.append(", uses=" + uses);
+ sb.append(", when=" + whenCondition);
sb.append("]");
return sb.toString();
}
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.Comparators;
+import org.opendaylight.controller.yang.parser.util.ParserUtils;
-public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
- private boolean built;
+public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder, GroupingMember, ConfigNode {
+ private boolean isBuilt;
private final ChoiceNodeImpl instance;
- private final int line;
// SchemaNode args
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ private List<UnknownSchemaNode> unknownNodes;
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// AugmentationTarget args
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
// ChoiceNode args
- private final Set<ChoiceCaseBuilder> cases = new HashSet<ChoiceCaseBuilder>();
+ private Set<ChoiceCaseNode> cases;
+ private final Set<ChoiceCaseBuilder> addedCases = new HashSet<ChoiceCaseBuilder>();
private String defaultCase;
- public ChoiceBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public ChoiceBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new ChoiceNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ChoiceBuilder(ChoiceBuilder b) {
+ super(b.getLine(), b.getQName());
+ parent = b.getParent();
+ instance = new ChoiceNodeImpl(qname);
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ addedAugmentations.addAll(b.getAugmentations());
+ cases = b.cases;
+ addedCases.addAll(b.getCases());
+ defaultCase = b.getDefaultCase();
+ }
+
@Override
public ChoiceNode build() {
- if (!built) {
+ if (!isBuilt) {
instance.setPath(schemaPath);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setConstraints(constraints.build());
instance.setDefaultCase(defaultCase);
// CASES
- final Set<ChoiceCaseNode> choiceCases = new HashSet<ChoiceCaseNode>();
- for (ChoiceCaseBuilder caseBuilder : cases) {
- choiceCases.add(caseBuilder.build());
+ if (cases == null) {
+ cases = new TreeSet<ChoiceCaseNode>(Comparators.SCHEMA_NODE_COMP);
+ for (ChoiceCaseBuilder caseBuilder : addedCases) {
+ cases.add(caseBuilder.build());
+ }
}
- instance.setCases(choiceCases);
+ instance.setCases(cases);
// AUGMENTATIONS
final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
- built = true;
+ isBuilt = true;
}
return instance;
}
@Override
- public int getLine() {
- return line;
+ public void rebuild() {
+ isBuilt = false;
+ build();
}
public Set<ChoiceCaseBuilder> getCases() {
- return cases;
+ return addedCases;
}
public void addChildNode(DataSchemaNodeBuilder childNode) {
if (!(childNode instanceof ChoiceCaseBuilder)) {
- ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(childNode.getQName(), childNode.getLine());
+ ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(childNode.getLine(), childNode.getQName());
+ if(childNode.isAugmenting()) {
+ caseBuilder.setAugmenting(true);
+ childNode.setAugmenting(false);
+ }
+ caseBuilder.setPath(childNode.getPath());
+ SchemaPath newPath = ParserUtils.createSchemaPath(childNode.getPath(), childNode.getQName().getLocalName());
+ childNode.setPath(newPath);
caseBuilder.addChildNode(childNode);
- cases.add(caseBuilder);
+ addedCases.add(caseBuilder);
} else {
- cases.add((ChoiceCaseBuilder) childNode);
+ addedCases.add((ChoiceCaseBuilder) childNode);
}
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- public SchemaPath getPath() {
- return schemaPath;
+ public void setCases(Set<ChoiceCaseNode> cases) {
+ this.cases = cases;
}
@Override
- public void setPath(final SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- public String getReference() {
- return reference;
+ public boolean isAugmenting() {
+ return augmenting;
}
@Override
- public void setReference(String reference) {
- this.reference = reference;
- }
-
- public Status getStatus() {
- return status;
+ public void setAugmenting(boolean augmenting) {
+ this.augmenting = augmenting;
}
@Override
- public void setStatus(Status status) {
- if (status != null) {
- this.status = status;
- }
- }
-
- public boolean isAugmenting() {
- return augmenting;
+ public boolean isAddedByUses() {
+ return addedByUses;
}
@Override
- public void setAugmenting(boolean augmenting) {
- this.augmenting = augmenting;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
- public boolean isConfiguration() {
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
return constraints;
}
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
- return addedUnknownNodes;
- }
-
public Set<AugmentationSchemaBuilder> getAugmentations() {
return addedAugmentations;
}
addedAugmentations.add(augment);
}
- @Override
- public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
}
public String getDefaultCase() {
this.defaultCase = defaultCase;
}
- private final class ChoiceNodeImpl implements ChoiceNode {
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ChoiceBuilder other = (ChoiceBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "choice " + qname.getLocalName();
+ }
+
+ public final class ChoiceNodeImpl implements ChoiceNode {
private final QName qname;
private SchemaPath path;
private String description;
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<ChoiceCaseNode> cases = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
return cases;
}
+ @Override
+ public ChoiceCaseNode getCaseNodeByName(final QName name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
+ }
+ for (final ChoiceCaseNode caseNode : cases) {
+ if (caseNode != null) {
+ if (name.equals(caseNode.getQName())) {
+ return caseNode;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ChoiceCaseNode getCaseNodeByName(final String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
+ }
+ for (final ChoiceCaseNode caseNode : cases) {
+ if (caseNode != null && (caseNode.getQName() != null)) {
+ if (name.equals(caseNode.getQName().getLocalName())) {
+ return caseNode;
+ }
+ }
+ }
+ return null;
+ }
+
private void setCases(Set<ChoiceCaseNode> cases) {
if (cases != null) {
this.cases = cases;
this.defaultCase = defaultCase;
}
+ public ChoiceBuilder toBuilder() {
+ return ChoiceBuilder.this;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
- DataSchemaNodeBuilder {
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder {
+ private boolean isBuilt;
private final ChoiceCaseNodeImpl instance;
- private final int line;
+ // SchemaNode args
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // DataSchemaNode args
private boolean augmenting;
private final ConstraintsBuilder constraints;
+ // DataNodeContainer args
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
- private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ // AugmentationTarget args
+ private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
- ChoiceCaseBuilder(final QName qname, final int line) {
- super(qname);
- this.line = line;
+ ChoiceCaseBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new ChoiceCaseNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
@Override
public ChoiceCaseNode build() {
- instance.setConstraints(constraints.build());
- instance.setPath(schemaPath);
- instance.setDescription(description);
- instance.setReference(reference);
- instance.setStatus(status);
- instance.setAugmenting(augmenting);
- instance.setAvailableAugmentations(augmentations);
+ if (!isBuilt) {
+ instance.setConstraints(constraints.build());
+ instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
+ instance.setAugmenting(augmenting);
+
+ // CHILD NODES
+ final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
+ childs.put(node.getQName(), node.build());
+ }
+ instance.setChildNodes(childs);
- // CHILD NODES
- final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- for (DataSchemaNodeBuilder node : childNodes) {
- childs.put(node.getQName(), node.build());
- }
- instance.setChildNodes(childs);
+ // USES
+ final Set<UsesNode> uses = new HashSet<UsesNode>();
+ for (UsesNodeBuilder builder : addedUsesNodes) {
+ uses.add(builder.build());
+ }
+ instance.setUses(uses);
- // USES
- final Set<UsesNode> uses = new HashSet<UsesNode>();
- for (UsesNodeBuilder builder : addedUsesNodes) {
- uses.add(builder.build());
- }
- instance.setUses(uses);
+ // UNKNOWN NODES
+ final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+ instance.setUnknownSchemaNodes(unknownNodes);
- // UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ // AUGMENTATIONS
+ final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ for (AugmentationSchemaBuilder builder : addedAugmentations) {
+ augmentations.add(builder.build());
+ }
+ instance.setAvailableAugmentations(augmentations);
+
+ isBuilt = true;
}
- instance.setUnknownSchemaNodes(unknownNodes);
return instance;
}
@Override
- public int getLine() {
- return line;
+ public void rebuild() {
+ isBuilt = false;
+ build();
}
public SchemaPath getPath() {
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return Collections.emptySet();
}
@Override
public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
- throw new YangParseException(line,
- "Can not add type definition to choice case.");
+ throw new YangParseException(line, "Can not add type definition to choice case.");
}
@Override
- public void setConfiguration(boolean configuration) {
- throw new YangParseException(line,
- "Can not add config definition to choice case.");
+ public ConstraintsBuilder getConstraints() {
+ return constraints;
}
@Override
- public ConstraintsBuilder getConstraints() {
- return constraints;
+ public void addAugmentation(AugmentationSchemaBuilder augment) {
+ addedAugmentations.add(augment);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ChoiceCaseBuilder other = (ChoiceCaseBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
}
- public Set<AugmentationSchema> getAugmentations() {
- return augmentations;
+ @Override
+ public String toString() {
+ return "case " + getQName().getLocalName();
}
- private final class ChoiceCaseNodeImpl implements ChoiceCaseNode {
+ public final class ChoiceCaseNodeImpl implements ChoiceCaseNode {
private final QName qname;
private SchemaPath path;
private String description;
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
}
+ public ChoiceCaseBuilder toBuilder() {
+ return ChoiceCaseBuilder.this;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ChoiceCaseNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ChoiceCaseNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append("]");
import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
public final class ConstraintsBuilder implements Builder {
private final ConstraintDefinitionImpl instance;
private final int line;
+ private Builder parent;
private final Set<MustDefinition> mustDefinitions;
private String whenCondition;
private boolean mandatory;
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ throw new YangParseException(line, "Can not add unknown node to constraints.");
+ }
+
public Integer getMinElements() {
return min;
}
this.mandatory = mandatory;
}
- private final class ConstraintDefinitionImpl implements
- ConstraintDefinition {
+
+ private final class ConstraintDefinitionImpl implements ConstraintDefinition {
private RevisionAwareXPath whenCondition;
private Set<MustDefinition> mustConstraints;
private boolean mandatory;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((whenCondition == null) ? 0 : whenCondition.hashCode());
- result = prime
- * result
- + ((mustConstraints == null) ? 0 : mustConstraints
- .hashCode());
- result = prime * result
- + ((minElements == null) ? 0 : minElements.hashCode());
- result = prime * result
- + ((maxElements == null) ? 0 : maxElements.hashCode());
+ result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+ result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
+ result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
+ result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
result = prime * result + (mandatory ? 1231 : 1237);
return result;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ConstraintDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ConstraintDefinitionImpl.class.getSimpleName());
sb.append("[");
sb.append("whenCondition=" + whenCondition);
sb.append(", mustConstraints=" + mustConstraints);
sb.append("]");
return sb.toString();
}
-
}
}
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
- implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
- DataSchemaNodeBuilder {
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements
+ AugmentationTargetBuilder, DataSchemaNodeBuilder, GroupingMember, ConfigNode {
private boolean isBuilt;
private final ContainerSchemaNodeImpl instance;
- private final int line;
- private final ConstraintsBuilder constraints;
+
+ // SchemaNode args
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
- private boolean presence;
+ private List<UnknownSchemaNode> unknownNodes;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
-
+ private boolean addedByUses;
+ private Boolean configuration;
+ private final ConstraintsBuilder constraints;
+ // DataNodeContainer args
+ private Set<TypeDefinition<?>> typedefs;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
+ private Set<UsesNode> usesNodes;
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+ // AugmentationTarget args
+ private Set<AugmentationSchema> augmentations;
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // ContainerSchemaNode args
+ private boolean presence;
- public ContainerSchemaNodeBuilder(final QName qname, final int line) {
- super(qname);
- this.line = line;
+ public ContainerSchemaNodeBuilder(final int line, final QName qname, final SchemaPath schemaPath) {
+ super(line, qname);
+ this.schemaPath = schemaPath;
instance = new ContainerSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ContainerSchemaNodeBuilder(final ContainerSchemaNodeBuilder b) {
+ super(b.getLine(), b.getQName());
+ instance = new ContainerSchemaNodeImpl(b.getQName());
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ presence = b.isPresence();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ childNodes = b.getChildNodes();
+ addedChildNodes.addAll(b.getChildNodeBuilders());
+ groupings = b.getGroupings();
+ addedGroupings.addAll(b.getGroupingBuilders());
+ typedefs = b.typedefs;
+ addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+ usesNodes = b.usesNodes;
+ addedUsesNodes.addAll(b.getUsesNodes());
+ augmentations = b.augmentations;
+ addedAugmentations.addAll(b.getAugmentations());
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public ContainerSchemaNode build() {
if (!isBuilt) {
instance.setStatus(status);
instance.setPresenceContainer(presence);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
+
+ // if this builder represents rpc input or output, it can has
+ // configuration value set to null
+ if (configuration == null) {
+ configuration = false;
+ }
instance.setConfiguration(configuration);
// CHILD NODES
- final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- for (DataSchemaNodeBuilder node : childNodes) {
- childs.put(node.getQName(), node.build());
+ final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+ if (childNodes == null) {
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
+ childs.put(node.getQName(), node.build());
+ }
+ } else {
+ for (DataSchemaNode node : childNodes) {
+ childs.put(node.getQName(), node);
+ }
}
instance.setChildNodes(childs);
// GROUPINGS
- final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
- for (GroupingBuilder builder : groupings) {
- groupingDefs.add(builder.build());
+ if (groupings == null) {
+ groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (GroupingBuilder builder : addedGroupings) {
+ groupings.add(builder.build());
+ }
}
- instance.setGroupings(groupingDefs);
+ instance.setGroupings(groupings);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
- for (TypeDefinitionBuilder entry : addedTypedefs) {
- typedefs.add(entry.build());
+ if (typedefs == null) {
+ typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+ for (TypeDefinitionBuilder entry : addedTypedefs) {
+ typedefs.add(entry.build());
+ }
}
instance.setTypeDefinitions(typedefs);
// USES
- final Set<UsesNode> uses = new HashSet<UsesNode>();
- for (UsesNodeBuilder builder : addedUsesNodes) {
- uses.add(builder.build());
+ if (usesNodes == null) {
+ usesNodes = new HashSet<UsesNode>();
+ for (UsesNodeBuilder builder : addedUsesNodes) {
+ usesNodes.add(builder.build());
+ }
}
- instance.setUses(uses);
+ instance.setUses(usesNodes);
// AUGMENTATIONS
- final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
- for (AugmentationSchemaBuilder builder : addedAugmentations) {
- augmentations.add(builder.build());
+ if (augmentations == null) {
+ augmentations = new HashSet<AugmentationSchema>();
+ for (AugmentationSchemaBuilder builder : addedAugmentations) {
+ augmentations.add(builder.build());
+ }
}
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
}
@Override
- public int getLine() {
- return line;
+ public void rebuild() {
+ isBuilt = false;
+ build();
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
addedTypedefs.add(type);
}
+ public void setTypedefs(final Set<TypeDefinition<?>> typedefs) {
+ this.typedefs = typedefs;
+ }
+
public Set<AugmentationSchemaBuilder> getAugmentations() {
return addedAugmentations;
}
addedAugmentations.add(augment);
}
+ public void setAugmentations(final Set<AugmentationSchema> augmentations) {
+ this.augmentations = augmentations;
+ }
+
public SchemaPath getPath() {
return schemaPath;
}
this.schemaPath = schemaPath;
}
+ @Override
public String getDescription() {
return description;
}
this.description = description;
}
+ @Override
public String getReference() {
return reference;
}
this.reference = reference;
}
+ @Override
public Status getStatus() {
return status;
}
}
}
+ @Override
public boolean isAugmenting() {
return augmenting;
}
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ @Override
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
addedUsesNodes.add(usesNodeBuilder);
}
+ public void setUsesnodes(final Set<UsesNode> usesNodes) {
+ this.usesNodes = usesNodes;
+ }
+
public boolean isPresence() {
return presence;
}
addedUnknownNodes.add(unknownNode);
}
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ContainerSchemaNodeBuilder other = (ContainerSchemaNodeBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
+ }
+
@Override
public String toString() {
- return "container " + getQName().getLocalName();
+ return "container " + qname.getLocalName();
}
- private final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
+ public final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
private final QName qname;
private SchemaPath path;
private String description;
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<AugmentationSchema> augmentations = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- List<UnknownSchemaNode> unknownSchemaNodes) {
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
if (unknownSchemaNodes != null) {
this.unknownNodes = unknownSchemaNodes;
}
}
+ public ContainerSchemaNodeBuilder toBuilder() {
+ return ContainerSchemaNodeBuilder.this;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ContainerSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ContainerSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append("]");
*/
package org.opendaylight.controller.yang.parser.builder.impl;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import org.opendaylight.controller.yang.model.api.Deviation;
import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
import org.opendaylight.controller.yang.parser.util.YangParseException;
public final class DeviationBuilder implements Builder {
- private final DeviationImpl instance;
private final int line;
+ private Builder parent;
+ private final DeviationImpl instance;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
DeviationBuilder(final String targetPathStr, final int line) {
this.line = line;
@Override
public Deviation build() {
+ // UNKNOWN NODES
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+ instance.setUnknownSchemaNodes(unknownNodes);
+
return instance;
}
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
public void setDeviate(final String deviate) {
if ("not-supported".equals(deviate)) {
instance.setDeviate(Deviate.NOT_SUPPORTED);
private final SchemaPath targetPath;
private Deviate deviate;
private String reference;
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private DeviationImpl(final SchemaPath targetPath) {
this.targetPath = targetPath;
this.reference = reference;
}
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+ if (unknownSchemaNodes != null) {
+ this.unknownNodes = unknownSchemaNodes;
+ }
+ }
+
@Override
public int hashCode() {
final int prime = 31;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class ExtensionBuilder implements SchemaNodeBuilder {
+public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final ExtensionDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
-
- ExtensionBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+
+ ExtensionBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new ExtensionDefinitionImpl(qname);
}
@Override
public ExtensionDefinition build() {
- if(!isBuilt) {
+ if (!isBuilt) {
instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
// UNKNOWN NODES
- final List<UnknownSchemaNode> extensions = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder e : addedExtensions) {
- extensions.add(e.build());
+ final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder un : addedUnknownNodes) {
+ unknownNodes.add(un.build());
}
- instance.setUnknownSchemaNodes(extensions);
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+ instance.setUnknownSchemaNodes(unknownNodes);
isBuilt = true;
}
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- public void addExtension(UnknownSchemaNodeBuilder extension) {
- addedExtensions.add(extension);
- }
-
public void setYinElement(boolean yin) {
instance.setYinElement(yin);
}
instance.setArgument(argument);
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public void setDescription(String description) {
- instance.setDescription(description);
- }
-
- @Override
- public void setReference(String reference) {
- instance.setReference(reference);
- }
-
- @Override
- public void setStatus(Status status) {
- instance.setStatus(status);
- }
-
- @Override
- public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
private final class ExtensionDefinitionImpl implements ExtensionDefinition {
private final QName qname;
private String argument;
private String description;
private String reference;
private Status status = Status.CURRENT;
- private List<UnknownSchemaNode> unknownNodes = Collections
- .emptyList();
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private boolean yin;
private ExtensionDefinitionImpl(QName qname) {
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- List<UnknownSchemaNode> unknownNodes) {
- if(unknownNodes != null) {
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
+ if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
}
final int prime = 31;
int result = 1;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
- result = prime * result
- + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
return result;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ExtensionDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ExtensionDefinitionImpl.class.getSimpleName());
sb.append("[");
- sb.append("argument="+ argument);
+ sb.append("argument=" + argument);
sb.append(", qname=" + qname);
sb.append(", schemaPath=" + schemaPath);
sb.append(", extensionSchemaNodes=" + unknownNodes);
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class FeatureBuilder implements SchemaNodeBuilder {
+public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final FeatureDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
-
- FeatureBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+
+ FeatureBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new FeatureDefinitionImpl(qname);
}
@Override
public FeatureDefinitionImpl build() {
- if(!isBuilt) {
+ if (!isBuilt) {
instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
// UNKNOWN NODES
final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
instance.setUnknownSchemaNodes(unknownNodes);
isBuilt = true;
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public void setDescription(final String description) {
- instance.setDescription(description);
- }
-
- @Override
- public void setReference(final String reference) {
- instance.setReference(reference);
- }
-
- @Override
- public void setStatus(final Status status) {
- instance.setStatus(status);
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
private final class FeatureDefinitionImpl implements FeatureDefinition {
private final QName qname;
private SchemaPath path;
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- final List<UnknownSchemaNode> unknownNodes) {
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- FeatureDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
sb.append("[name=" + qname + "]");
return sb.toString();
}
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
+import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
public final class GroupingBuilderImpl implements GroupingBuilder {
+ private Builder parent;
private boolean isBuilt;
private final GroupingDefinitionImpl instance;
private final int line;
private SchemaPath schemaPath;
private String description;
private String reference;
- private Status status;
- private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
- private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
+ private Status status = Status.CURRENT;
+ private boolean addedByUses;
+
+ private Set<DataSchemaNode> childNodes;
+ private final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
+
+ private Set<GroupingDefinition> groupings;
+ private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
+
+ private Set<TypeDefinition<?>> typedefs;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
- private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+
+ private Set<UsesNode> usesNodes;
+ private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+
+ private List<UnknownSchemaNode> unknownNodes;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
public GroupingBuilderImpl(final QName qname, final int line) {
this.qname = qname;
- this.instance = new GroupingDefinitionImpl(qname);
+ instance = new GroupingDefinitionImpl(qname);
this.line = line;
}
+ public GroupingBuilderImpl(GroupingBuilder builder) {
+ qname = builder.getQName();
+ parent = builder.getParent();
+ instance = new GroupingDefinitionImpl(qname);
+ line = builder.getLine();
+ schemaPath = builder.getPath();
+ description = builder.getDescription();
+ reference = builder.getReference();
+ status = builder.getStatus();
+ addedByUses = builder.isAddedByUses();
+ childNodes = builder.getChildNodes();
+ addedChildNodes.addAll(builder.getChildNodeBuilders());
+ groupings = builder.getGroupings();
+ addedGroupings.addAll(builder.getGroupingBuilders());
+ addedUsesNodes.addAll(builder.getUses());
+ addedUnknownNodes.addAll(builder.getUnknownNodes());
+ }
+
@Override
public GroupingDefinition build() {
if (!isBuilt) {
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
+ instance.setAddedByUses(addedByUses);
// CHILD NODES
final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- for (DataSchemaNodeBuilder node : childNodes) {
- childs.put(node.getQName(), node.build());
+ if (childNodes == null) {
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
+ childs.put(node.getQName(), node.build());
+ }
+ } else {
+ for (DataSchemaNode node : childNodes) {
+ childs.put(node.getQName(), node);
+ }
}
instance.setChildNodes(childs);
// GROUPINGS
- final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
- for (GroupingBuilder builder : groupings) {
- groupingDefs.add(builder.build());
+ if (groupings == null) {
+ groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (GroupingBuilder builder : addedGroupings) {
+ groupings.add(builder.build());
+ }
}
- instance.setGroupings(groupingDefs);
+ instance.setGroupings(groupings);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
- for (TypeDefinitionBuilder entry : addedTypedefs) {
- typedefs.add(entry.build());
+ if (typedefs == null) {
+ typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+ for (TypeDefinitionBuilder entry : addedTypedefs) {
+ typedefs.add(entry.build());
+ }
}
instance.setTypeDefinitions(typedefs);
// USES
- final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
- for (UsesNodeBuilder builder : usesNodes) {
- usesNodeDefs.add(builder.build());
+ if (usesNodes == null) {
+ usesNodes = new HashSet<UsesNode>();
+ for (UsesNodeBuilder builder : addedUsesNodes) {
+ usesNodes.add(builder.build());
+ }
}
- instance.setUses(usesNodeDefs);
+ instance.setUses(usesNodes);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
@Override
public QName getQName() {
return qname;
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
addedTypedefs.add(type);
}
+ public void setTypedefs(final Set<TypeDefinition<?>> typedefs) {
+ this.typedefs = typedefs;
+ }
+
@Override
public SchemaPath getPath() {
return schemaPath;
this.status = status;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public DataSchemaNodeBuilder getChildNode(String name) {
DataSchemaNodeBuilder result = null;
- for (DataSchemaNodeBuilder node : childNodes) {
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
if (node.getQName().getLocalName().equals(name)) {
result = node;
break;
return result;
}
+ @Override
+ public Set<DataSchemaNode> getChildNodes() {
+ return childNodes;
+ }
+
@Override
public void addChildNode(final DataSchemaNodeBuilder childNode) {
- childNodes.add(childNode);
+ addedChildNodes.add(childNode);
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
- return childNodes;
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
+ return addedChildNodes;
+ }
+
+ public void setChildNodes(final Set<DataSchemaNode> childNodes) {
+ this.childNodes = childNodes;
+ }
+
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
}
@Override
- public Set<GroupingBuilder> getGroupings() {
- return groupings;
+ public Set<GroupingBuilder> getGroupingBuilders() {
+ return addedGroupings;
}
@Override
public void addGrouping(final GroupingBuilder grouping) {
- groupings.add(grouping);
+ addedGroupings.add(grouping);
+ }
+
+ public void setGroupings(final Set<GroupingDefinition> groupings) {
+ this.groupings = groupings;
}
@Override
public Set<UsesNodeBuilder> getUses() {
- return usesNodes;
+ return addedUsesNodes;
}
@Override
public void addUsesNode(final UsesNodeBuilder usesBuilder) {
- usesNodes.add(usesBuilder);
+ addedUsesNodes.add(usesBuilder);
+ }
+
+ public void setUsesnodes(final Set<UsesNode> usesNodes) {
+ this.usesNodes = usesNodes;
}
@Override
addedUnknownNodes.add(unknownNode);
}
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
+ }
+
private final class GroupingDefinitionImpl implements GroupingDefinition {
private final QName qname;
private SchemaPath path;
private String description;
private String reference;
private Status status;
+ private boolean addedByUses;
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
this.status = status;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public Set<DataSchemaNode> getChildNodes() {
- return new HashSet<DataSchemaNode>(childNodes.values());
+ final Set<DataSchemaNode> result = new TreeSet<DataSchemaNode>(Comparators.SCHEMA_NODE_COMP);
+ result.addAll(childNodes.values());
+ return result;
}
private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- GroupingDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(GroupingDefinitionImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append("]");
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
+public final class IdentitySchemaNodeBuilder extends AbstractSchemaNodeBuilder {
+ private boolean isBuilt;
private final IdentitySchemaNodeImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private IdentitySchemaNodeBuilder baseIdentity;
+ private IdentitySchemaNodeBuilder baseIdentityBuilder;
+ private IdentitySchemaNode baseIdentity;
private String baseIdentityName;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- IdentitySchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ IdentitySchemaNodeBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new IdentitySchemaNodeImpl(qname);
}
@Override
public IdentitySchemaNode build() {
- instance.setPath(schemaPath);
- if (baseIdentity != null) {
- instance.setBaseIdentity(baseIdentity.build());
- }
-
- // UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
- }
- instance.setUnknownSchemaNodes(unknownNodes);
-
- return instance;
- }
-
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
+ if (!isBuilt) {
+ instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
- @Override
- public void setDescription(final String description) {
- instance.setDescription(description);
- }
+ if (baseIdentity == null) {
+ if (baseIdentityBuilder != null) {
+ instance.setBaseIdentity(baseIdentityBuilder.build());
+ }
+ } else {
+ instance.setBaseIdentity(baseIdentity);
+ }
- @Override
- public void setReference(final String reference) {
- instance.setReference(reference);
- }
+ // UNKNOWN NODES
+ final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+ instance.setUnknownSchemaNodes(unknownNodes);
- @Override
- public void setStatus(final Status status) {
- if (status != null) {
- instance.setStatus(status);
+ isBuilt = true;
}
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-
- addedUnknownNodes.add(unknownNode);
+ return instance;
}
public String getBaseIdentityName() {
}
public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) {
+ this.baseIdentityBuilder = baseType;
+ }
+
+ public void setBaseIdentity(final IdentitySchemaNode baseType) {
this.baseIdentity = baseType;
}
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- List<UnknownSchemaNode> unknownSchemaNodes) {
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
if (unknownSchemaNodes != null) {
this.unknownNodes = unknownSchemaNodes;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- IdentitySchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(IdentitySchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("base=" + baseIdentity);
sb.append(", qname=" + qname);
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
* When build is called, types in builder form will be built and add to resolved
* types.
*/
-public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
- implements TypeDefinitionBuilder {
+public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private static final String NAME = "identityref";
- private final int line;
private final String baseString;
private final SchemaPath schemaPath;
private QName baseQName;
- IdentityrefTypeBuilder(final String baseString,
- final SchemaPath schemaPath, final int line) {
- this.line = line;
+ IdentityrefTypeBuilder(final String baseString, final SchemaPath schemaPath, final int line) {
+ super(line, null);
this.baseString = baseString;
this.schemaPath = schemaPath;
}
this.baseQName = baseQName;
}
- @Override
- public int getLine() {
- return line;
- }
-
@Override
public TypeDefinition<?> getType() {
return null;
throw new YangParseException(line, "Can not set status to " + NAME);
}
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ throw new YangParseException(line, "Identityref type can not be added by uses.");
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new YangParseException(line, "Can not add unknown node to "
- + NAME);
+ throw new YangParseException(line, "Can not add unknown node to " + NAME);
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new YangParseException(line, "Can not set fraction digits to "
- + NAME);
+ throw new YangParseException(line, "Can not set fraction digits to " + NAME);
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return Collections.emptyList();
}
@Override
public void setDefaultValue(Object defaultValue) {
- throw new YangParseException(line, "Can not set default value to "
- + NAME);
+ throw new YangParseException(line, "Can not set default value to " + NAME);
}
@Override
@Override
public String toString() {
- final StringBuilder result = new StringBuilder(
- IdentityrefTypeBuilder.class.getSimpleName() + "[");
+ final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName() + "[");
result.append(", base=" + baseQName);
result.append("]");
return result.toString();
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder
- implements SchemaNodeBuilder, DataSchemaNodeBuilder {
+public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+ GroupingMember, ConfigNode {
private boolean isBuilt;
private final LeafListSchemaNodeImpl instance;
- private final int line;
// SchemaNode args
- private final QName qname;
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
+ private List<UnknownSchemaNode> unknownNodes;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// LeafListSchemaNode args
private boolean userOrdered;
- public LeafListSchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public LeafListSchemaNodeBuilder(final int line, final QName qname, final SchemaPath schemaPath) {
+ super(line, qname);
+ this.schemaPath = schemaPath;
instance = new LeafListSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
+ super(b.getLine(), b.getQName());
+ instance = new LeafListSchemaNodeImpl(qname);
+
+ type = b.getType();
+ typedef = b.getTypedef();
+
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ userOrdered = b.isUserOrdered();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public LeafListSchemaNode build() {
if (!isBuilt) {
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setUserOrdered(userOrdered);
}
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
public SchemaPath getPath() {
return schemaPath;
}
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
addedUnknownNodes.add(unknownNode);
}
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "leaf-list " + qname.getLocalName();
+ }
+
private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
private final QName qname;
private SchemaPath path;
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraintsDef;
private TypeDefinition<?> type;
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- LeafListSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(LeafListSchemaNodeImpl.class.getSimpleName());
sb.append("[");
- sb.append("qname=" + qname);
- sb.append(", path=" + path);
- sb.append(", augmenting=" + augmenting);
- sb.append(", configuration=" + configuration);
- sb.append(", constraints=" + constraintsDef);
- sb.append(", type=" + type);
- sb.append(", userOrdered=" + userOrdered);
+ sb.append(qname);
sb.append("]");
return sb.toString();
}
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder
- implements DataSchemaNodeBuilder, SchemaNodeBuilder {
+public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+ GroupingMember, ConfigNode {
private boolean isBuilt;
private final LeafSchemaNodeImpl instance;
- private final int line;
// SchemaNode args
- private final QName qname;
- private SchemaPath path;
+ private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
+ private List<UnknownSchemaNode> unknownNodes;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// leaf args
private String defaultStr;
private String unitsStr;
- public LeafSchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public LeafSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
+ super(line, qname);
+ this.schemaPath = schemaPath;
instance = new LeafSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public LeafSchemaNodeBuilder(final LeafSchemaNodeBuilder b) {
+ super(b.getLine(), b.getQName());
+ instance = new LeafSchemaNodeImpl(qname);
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+
+ type = b.getType();
+ typedef = b.getTypedef();
+
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+
+ defaultStr = b.getDefaultStr();
+ unitsStr = b.getUnits();
+ }
+
@Override
public LeafSchemaNode build() {
if (!isBuilt) {
- instance.setPath(path);
+ instance.setPath(schemaPath);
instance.setConstraints(constraints.build());
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setDefault(defaultStr);
instance.setUnits(unitsStr);
}
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
public SchemaPath getPath() {
- return path;
+ return schemaPath;
}
@Override
public void setPath(final SchemaPath path) {
- this.path = path;
+ this.schemaPath = path;
}
@Override
return addedUnknownNodes;
}
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
+ }
+
public String getDescription() {
return description;
}
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(final boolean configuration) {
- instance.setConfiguration(configuration);
+ public void setConfiguration(final Boolean configuration) {
+ this.configuration = configuration;
}
public String getDefaultStr() {
this.unitsStr = unitsStr;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ LeafSchemaNodeBuilder other = (LeafSchemaNodeBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
+ }
+
@Override
public String toString() {
return "leaf " + qname.getLocalName();
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraintsDef;
private TypeDefinition<?> type;
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- LeafSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(LeafSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
- implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
- TypeDefinitionAwareBuilder {
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder, GroupingMember, ConfigNode {
private boolean isBuilt;
private final ListSchemaNodeImpl instance;
- private final int line;
// SchemaNode args
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
+ private List<UnknownSchemaNode> unknownNodes;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// DataNodeContainer args
+ private Set<TypeDefinition<?>> typedefs;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
+ private Set<UsesNode> usesNodes;
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
// AugmentationTarget args
+ private Set<AugmentationSchema> augmentations;
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
// ListSchemaNode args
private List<QName> keyDefinition = Collections.emptyList();
private boolean userOrdered;
- public ListSchemaNodeBuilder(final QName qname, final int line) {
- super(qname);
- this.line = line;
+ public ListSchemaNodeBuilder(final int line, final QName qname, final SchemaPath schemaPath) {
+ super(line, qname);
+ this.schemaPath = schemaPath;
instance = new ListSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ListSchemaNodeBuilder(final ListSchemaNodeBuilder b) {
+ super(b.getLine(), b.getQName());
+ instance = new ListSchemaNodeImpl(b.getQName());
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ keyDefinition = b.getKeyDefinition();
+ userOrdered = b.isUserOrdered();
+ childNodes = b.getChildNodes();
+ addedChildNodes.addAll(b.getChildNodeBuilders());
+ groupings = b.getGroupings();
+ addedGroupings.addAll(b.getGroupingBuilders());
+ typedefs = b.typedefs;
+ addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+ usesNodes = b.usesNodes;
+ addedUsesNodes.addAll(b.getUsesNodes());
+ augmentations = b.augmentations;
+ addedAugmentations.addAll(b.getAugmentations());
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public ListSchemaNode build() {
if (!isBuilt) {
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setUserOrdered(userOrdered);
// CHILD NODES
- final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- for (DataSchemaNodeBuilder node : childNodes) {
- childs.put(node.getQName(), node.build());
+ final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+ if (childNodes == null) {
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
+ childs.put(node.getQName(), node.build());
+ }
+ } else {
+ for (DataSchemaNode node : childNodes) {
+ childs.put(node.getQName(), node);
+ }
}
instance.setChildNodes(childs);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
- for (TypeDefinitionBuilder entry : addedTypedefs) {
- typedefs.add(entry.build());
+ if (typedefs == null) {
+ typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+ for (TypeDefinitionBuilder entry : addedTypedefs) {
+ typedefs.add(entry.build());
+ }
}
instance.setTypeDefinitions(typedefs);
// USES
- final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
- for (UsesNodeBuilder builder : addedUsesNodes) {
- usesNodeDefs.add(builder.build());
+ if (usesNodes == null) {
+ usesNodes = new HashSet<UsesNode>();
+ for (UsesNodeBuilder builder : addedUsesNodes) {
+ usesNodes.add(builder.build());
+ }
}
- instance.setUses(usesNodeDefs);
+ instance.setUses(usesNodes);
// GROUPINGS
- final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
- for (GroupingBuilder builder : groupings) {
- groupingDefs.add(builder.build());
+ if (groupings == null) {
+ groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (GroupingBuilder builder : addedGroupings) {
+ groupings.add(builder.build());
+ }
}
- instance.setGroupings(groupingDefs);
+ instance.setGroupings(groupings);
// AUGMENTATIONS
- final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
- for (AugmentationSchemaBuilder builder : addedAugmentations) {
- augmentations.add(builder.build());
+ if (augmentations == null) {
+ augmentations = new HashSet<AugmentationSchema>();
+ for (AugmentationSchemaBuilder builder : addedAugmentations) {
+ augmentations.add(builder.build());
+ }
}
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
}
@Override
- public int getLine() {
- return line;
+ public void rebuild() {
+ isBuilt = false;
+ build();
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
addedTypedefs.add(type);
}
+ public void setTypedefs(final Set<TypeDefinition<?>> typedefs) {
+ this.typedefs = typedefs;
+ }
+
public SchemaPath getPath() {
return schemaPath;
}
addedUsesNodes.add(usesBuilder);
}
+ public void setUsesnodes(final Set<UsesNode> usesNodes) {
+ this.usesNodes = usesNodes;
+ }
+
public Set<AugmentationSchemaBuilder> getAugmentations() {
return addedAugmentations;
}
addedAugmentations.add(augment);
}
+ public void setAugmentations(final Set<AugmentationSchema> augmentations) {
+ this.augmentations = augmentations;
+ }
+
public List<QName> getKeyDefinition() {
return keyDefinition;
}
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
addedUnknownNodes.add(unknownNode);
}
- private final class ListSchemaNodeImpl implements ListSchemaNode {
+ public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ListSchemaNodeBuilder other = (ListSchemaNodeBuilder) obj;
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "list " + qname.getLocalName();
+ }
+
+ public final class ListSchemaNodeImpl implements ListSchemaNode {
private final QName qname;
private SchemaPath path;
private String description;
private Status status = Status.CURRENT;
private List<QName> keyDefinition = Collections.emptyList();
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<AugmentationSchema> augmentations = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
}
}
+ public ListSchemaNodeBuilder toBuilder() {
+ return ListSchemaNodeBuilder.this;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ListSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ListSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.RpcDefinition;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
import org.opendaylight.controller.yang.parser.util.RefineHolder;
import org.opendaylight.controller.yang.parser.util.YangParseException;
* module/modules, these dependencies must be resolved before module is built,
* otherwise result may not be valid.
*/
-public class ModuleBuilder implements Builder {
+public class ModuleBuilder implements DataNodeContainerBuilder {
private final ModuleImpl instance;
private final String name;
private URI namespace;
* Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
* list, leaf, leaf-list.
*/
- private final Map<List<String>, DataSchemaNodeBuilder> childNodes = new HashMap<List<String>, DataSchemaNodeBuilder>();
+ private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
- private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
+ private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
- private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
- private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
+ private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<AugmentationSchemaBuilder>();
+ private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+ private final List<UsesNodeBuilder> allUsesNodes = new ArrayList<UsesNodeBuilder>();
+ private final Set<RpcDefinitionBuilder> addedRpcs = new HashSet<RpcDefinitionBuilder>();
private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
- private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
+ private final Set<FeatureBuilder> addedFeatures = new HashSet<FeatureBuilder>();
private final Map<List<String>, DeviationBuilder> addedDeviations = new HashMap<List<String>, DeviationBuilder>();
- private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
+ private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
- private final Set<UnknownSchemaNodeBuilder> addedUnknownNodes = new HashSet<UnknownSchemaNodeBuilder>();
+ private final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes = new HashMap<List<String>, List<UnknownSchemaNodeBuilder>>();
private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
instance.setNamespace(namespace);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
+ final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+ for (TypeDefinitionBuilder tdb : addedTypedefs) {
+ typedefs.add(tdb.build());
+ }
instance.setTypeDefinitions(typedefs);
// CHILD NODES
- final Map<QName, DataSchemaNode> children = buildModuleChildNodes(childNodes);
+ final Map<QName, DataSchemaNode> children = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+ for (DataSchemaNodeBuilder child : childNodes) {
+ children.put(child.getQName(), child.build());
+ }
instance.setChildNodes(children);
// GROUPINGS
- final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
+ final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (GroupingBuilder gb : addedGroupings) {
+ groupings.add(gb.build());
+ }
instance.setGroupings(groupings);
// USES
- final Set<UsesNode> usesDefinitions = buildUsesNodes(addedUsesNodes);
+ final Set<UsesNode> usesDefinitions = new HashSet<UsesNode>();
+ for (UsesNodeBuilder unb : addedUsesNodes) {
+ usesDefinitions.add(unb.build());
+ }
instance.setUses(usesDefinitions);
// FEATURES
- final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
+ final Set<FeatureDefinition> features = new TreeSet<FeatureDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (FeatureBuilder fb : addedFeatures) {
+ features.add(fb.build());
+ }
instance.setFeatures(features);
// NOTIFICATIONS
- final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
+ final Set<NotificationDefinition> notifications = new TreeSet<NotificationDefinition>(
+ Comparators.SCHEMA_NODE_COMP);
for (NotificationBuilder entry : addedNotifications) {
- notifications.add((NotificationDefinition) entry.build());
+ notifications.add(entry.build());
}
instance.setNotifications(notifications);
instance.setAugmentations(augmentations);
// RPCs
- final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
+ final Set<RpcDefinition> rpcs = new TreeSet<RpcDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (RpcDefinitionBuilder rpc : addedRpcs) {
+ rpcs.add(rpc.build());
+ }
instance.setRpcs(rpcs);
// DEVIATIONS
final Set<Deviation> deviations = new HashSet<Deviation>();
- for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations
- .entrySet()) {
+ for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations.entrySet()) {
deviations.add(entry.getValue().build());
}
instance.setDeviations(deviations);
// EXTENSIONS
final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
- for (ExtensionBuilder b : addedExtensions) {
- extensions.add(b.build());
+ for (ExtensionBuilder eb : addedExtensions) {
+ extensions.add(eb.build());
}
+ Collections.sort(extensions, Comparators.SCHEMA_NODE_COMP);
instance.setExtensionSchemaNodes(extensions);
// IDENTITIES
- final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
- for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
- identities.add(idBuilder.build());
+ final Set<IdentitySchemaNode> identities = new TreeSet<IdentitySchemaNode>(Comparators.SCHEMA_NODE_COMP);
+ for (IdentitySchemaNodeBuilder id : addedIdentities) {
+ identities.add(id.build());
}
instance.setIdentities(identities);
+ // UNKNOWN NODES
+ final List<UnknownSchemaNode> unknownNodes = buildModuleUnknownNodes(addedUnknownNodes);
+ instance.setUnknownSchemaNodes(unknownNodes);
+
return instance;
}
return 0;
}
+ @Override
+ public Builder getParent() {
+ return null;
+ }
+
+ @Override
+ public void setParent(Builder parent) {
+ throw new YangParseException(name, 0, "Can not set parent to module");
+ }
+
+ @Override
+ public QName getQName() {
+ return new QName(namespace, revision, prefix, name);
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
+ return addedTypedefs;
+ }
+
public void enterNode(final Builder node) {
actualPath.push(node);
}
}
}
- public Builder getModuleNode(final List<String> path) {
- return childNodes.get(path);
+ public Builder getActualParent() {
+ if (actualPath.size() < 2) {
+ return null;
+ } else {
+ return actualPath.get(1);
+ }
}
- public GroupingBuilder getGrouping(final List<String> path) {
- return addedGroupings.get(path);
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
}
- public Builder getModuleTypedef(final List<String> path) {
- return addedTypedefs.get(path);
+ @Override
+ public Set<GroupingBuilder> getGroupingBuilders() {
+ return addedGroupings;
}
- public Set<DataSchemaNodeBuilder> getChildNodes() {
- final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
- for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes
- .entrySet()) {
- final List<String> path = entry.getKey();
- final DataSchemaNodeBuilder child = entry.getValue();
- if (path.size() == 2) {
- children.add(child);
- }
- }
- return children;
+ @Override
+ public Set<DataSchemaNode> getChildNodes() {
+ return Collections.emptySet();
+ }
+
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
+ return childNodes;
}
public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
return dirtyNodes;
}
- public List<AugmentationSchemaBuilder> getAugments() {
- return addedAugments;
+ public List<AugmentationSchemaBuilder> getAllAugments() {
+ return allAugments;
}
public Set<IdentitySchemaNodeBuilder> getIdentities() {
return addedIdentities;
}
- public Map<List<String>, UsesNodeBuilder> getUsesNodes() {
- return addedUsesNodes;
- }
-
- public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
- return addedUnknownNodes;
+ public List<UsesNodeBuilder> getAllUsesNodes() {
+ return allUsesNodes;
}
- public Set<TypeDefinitionBuilder> getModuleTypedefs() {
- final Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
- for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- typedefs.add(entry.getValue());
- }
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ List<UnknownSchemaNodeBuilder> result = new ArrayList<UnknownSchemaNodeBuilder>();
+ for (List<UnknownSchemaNodeBuilder> entry : addedUnknownNodes.values()) {
+ result.addAll(entry);
}
- return typedefs;
- }
-
- public Set<GroupingBuilder> getModuleGroupings() {
- final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
- for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- groupings.add(entry.getValue());
- }
- }
- return groupings;
+ return result;
}
public String getName() {
public void addDirtyNode(final List<String> path) {
final List<String> dirtyNodePath = new ArrayList<String>(path);
- final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath
- .getFirst();
+ final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath.getFirst();
dirtyNodes.put(dirtyNodePath, nodeBuilder);
}
instance.setContact(contact);
}
- public boolean addModuleImport(final String moduleName,
- final Date revision, final String prefix) {
- final ModuleImport moduleImport = createModuleImport(moduleName,
- revision, prefix);
+ public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) {
+ final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix);
return imports.add(moduleImport);
}
}
public ExtensionBuilder addExtension(final QName qname, final int line) {
- final ExtensionBuilder builder = new ExtensionBuilder(qname, line);
+ final ExtensionBuilder builder = new ExtensionBuilder(line, qname);
addedExtensions.add(builder);
return builder;
}
- public ContainerSchemaNodeBuilder addContainerNode(
- final QName containerName, final List<String> parentPath,
- final int line) {
- final List<String> pathToNode = new ArrayList<String>(parentPath);
- final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
- containerName, line);
- updateParent(containerBuilder, line, "container");
+ @Override
+ public void addChildNode(DataSchemaNodeBuilder child) {
+ for (DataSchemaNodeBuilder childNode : childNodes) {
+ if (childNode.getQName().getLocalName().equals(child.getQName().getLocalName())) {
+ throw new YangParseException(name, child.getLine(), "Duplicate node found at line "
+ + childNode.getLine());
+ }
+ }
+ childNodes.add(child);
+ }
+
+ public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName containerName,
+ final SchemaPath schemaPath) {
+ final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(line, containerName, schemaPath);
- pathToNode.add(containerName.getLocalName());
- childNodes.put(pathToNode, containerBuilder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, containerName.getLocalName());
- return containerBuilder;
+ return builder;
}
- public ListSchemaNodeBuilder addListNode(final QName listName,
- final List<String> parentPath, final int line) {
- final List<String> pathToNode = new ArrayList<String>(parentPath);
- final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
- listName, line);
- updateParent(listBuilder, line, "list");
+ public ListSchemaNodeBuilder addListNode(final int line, final QName listName, final SchemaPath schemaPath) {
+ final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(line, listName, schemaPath);
- pathToNode.add(listName.getLocalName());
- childNodes.put(pathToNode, listBuilder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, listName.getLocalName());
- return listBuilder;
+ return builder;
}
- public LeafSchemaNodeBuilder addLeafNode(final QName leafName,
- final List<String> parentPath, final int line) {
- final List<String> pathToNode = new ArrayList<String>(parentPath);
- final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
- leafName, line);
- updateParent(leafBuilder, line, "leaf");
+ public LeafSchemaNodeBuilder addLeafNode(final int line, final QName leafName, final SchemaPath schemaPath) {
+ final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leafName, schemaPath, line);
- pathToNode.add(leafName.getLocalName());
- childNodes.put(pathToNode, leafBuilder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, leafName.getLocalName());
- return leafBuilder;
+ return builder;
}
- public LeafListSchemaNodeBuilder addLeafListNode(final QName qname,
- final List<String> parentPath, final int line) {
- final List<String> pathToNode = new ArrayList<String>(parentPath);
- final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
- qname, line);
- updateParent(leafListBuilder, line, "leaf-list");
+ public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName leafListName,
+ final SchemaPath schemaPath) {
+ final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(line, leafListName, schemaPath);
- pathToNode.add(qname.getLocalName());
- childNodes.put(pathToNode, leafListBuilder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, leafListName.getLocalName());
- return leafListBuilder;
+ return builder;
}
- public GroupingBuilder addGrouping(final QName qname,
- final List<String> parentPath, final int line) {
- final List<String> pathToGroup = new ArrayList<String>(parentPath);
+ @Override
+ public void addGrouping(GroupingBuilder groupingBuilder) {
+ for (GroupingBuilder gb : addedGroupings) {
+ if (gb.getQName().getLocalName().equals(groupingBuilder.getQName().getLocalName())) {
+ throw new YangParseException(name, groupingBuilder.getLine(), "Duplicate node found at line "
+ + gb.getLine());
+ }
+ }
+ addedGroupings.add(groupingBuilder);
+ }
+
+ public GroupingBuilder addGrouping(final int line, final QName qname) {
final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+
+ if (parent == null) {
+ for (GroupingBuilder child : addedGroupings) {
+ if (child.getQName().getLocalName().equals(qname.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine());
+ }
+ }
+ addedGroupings.add(builder);
+ } else {
if (parent instanceof DataNodeContainerBuilder) {
- ((DataNodeContainerBuilder) parent).addGrouping(builder);
+ DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+ for (DataSchemaNodeBuilder child : parentNode.getChildNodeBuilders()) {
+ if (child.getQName().getLocalName().equals(qname.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine());
+ }
+ }
+ parentNode.addGrouping(builder);
+ } else if (parent instanceof RpcDefinitionBuilder) {
+ RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent;
+ for (GroupingBuilder child : parentNode.getGroupings()) {
+ if (child.getQName().getLocalName().equals(qname.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine());
+ }
+ }
+ parentNode.addGrouping(builder);
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of grouping " + qname.getLocalName());
+ throw new YangParseException(name, line, "Unresolved parent of grouping " + qname.getLocalName());
}
}
- pathToGroup.add(qname.getLocalName());
- addedGroupings.put(pathToGroup, builder);
-
return builder;
}
- public AugmentationSchemaBuilder addAugment(final String name,
- final List<String> parentPath, final int line) {
- final List<String> pathToAugment = new ArrayList<String>(parentPath);
- final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(
- name, line);
+ public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) {
+ final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(line, augmentTargetStr);
- // augment can only be in 'module' or 'uses' statement
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+
+ if (parent == null) {
+ addedAugments.add(builder);
+ } else {
+ // augment can only be in 'module' or 'uses' statement
if (parent instanceof UsesNodeBuilder) {
((UsesNodeBuilder) parent).addAugment(builder);
} else {
- throw new YangParseException(this.name, line,
- "Unresolved parent of augment " + name);
+ throw new YangParseException(name, line, "Augment can be declared only under module or uses.");
}
}
-
- pathToAugment.add(name);
- addedAugments.add(builder);
+ allAugments.add(builder);
return builder;
}
- public UsesNodeBuilder addUsesNode(final String groupingPathStr,
- final List<String> parentPath, final int line) {
- final List<String> pathToUses = new ArrayList<String>(parentPath);
- final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
- groupingPathStr, line);
+ @Override
+ public void addUsesNode(UsesNodeBuilder usesBuilder) {
+ addedUsesNodes.add(usesBuilder);
+ allUsesNodes.add(usesBuilder);
+ }
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof DataNodeContainerBuilder) {
- if (parent instanceof AugmentationSchemaBuilder) {
- usesBuilder.setAugmenting(true);
- }
- ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
- } else {
- throw new YangParseException(name, line,
- "Unresolved parent of uses " + groupingPathStr);
+ public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) {
+ final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(line, groupingPathStr);
+
+ Builder parent = getActualNode();
+ usesBuilder.setParent(parent);
+
+ if (parent == null) {
+ addedUsesNodes.add(usesBuilder);
+ } else {
+ if (!(parent instanceof DataNodeContainerBuilder)) {
+ throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'.");
}
+ if (parent instanceof AugmentationSchemaBuilder) {
+ usesBuilder.setAugmenting(true);
+ }
+ ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
}
-
- pathToUses.add(groupingPathStr);
- addedUsesNodes.put(pathToUses, usesBuilder);
+ allUsesNodes.add(usesBuilder);
return usesBuilder;
}
- public void addRefine(final RefineHolder refine,
- final List<String> parentPath) {
+ public void addRefine(final RefineHolder refine, final List<String> parentPath) {
final List<String> path = new ArrayList<String>(parentPath);
if (actualPath.isEmpty()) {
- throw new YangParseException(name, refine.getLine(),
- "refine can be defined only in uses statement");
+ throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
} else {
- final Builder parent = actualPath.getFirst();
+ final Builder parent = getActualNode();
if (parent instanceof UsesNodeBuilder) {
((UsesNodeBuilder) parent).addRefine(refine);
} else {
- throw new YangParseException(name, refine.getLine(),
- "refine can be defined only in uses statement");
+ throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
}
+ refine.setParent(parent);
}
path.add(refine.getName());
}
- public RpcDefinitionBuilder addRpc(final QName qname,
- final List<String> parentPath, final int line) {
-
- if (!(actualPath.isEmpty())) {
- throw new YangParseException(name, line,
- "rpc can be defined only in module or submodule");
+ public RpcDefinitionBuilder addRpc(final int line, final QName qname) {
+ Builder parent = getActualNode();
+ if (parent != null) {
+ throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
}
- final List<String> pathToRpc = new ArrayList<String>(parentPath);
- final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname,
- line);
-
- pathToRpc.add(qname.getLocalName());
- addedRpcs.put(pathToRpc, rpcBuilder);
-
+ final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(line, qname);
+ for (RpcDefinitionBuilder rpc : addedRpcs) {
+ if (rpc.getQName().getLocalName().equals(qname.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + rpc.getLine());
+ }
+ }
+ addedRpcs.add(rpcBuilder);
return rpcBuilder;
}
- public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName,
- final int line) {
- final Builder parent = actualPath.getFirst();
+ public ContainerSchemaNodeBuilder addRpcInput(final SchemaPath schemaPath, final QName inputQName, final int line) {
+ final Builder parent = getActualNode();
if (!(parent instanceof RpcDefinitionBuilder)) {
- throw new YangParseException(name, line,
- "input can be defined only in rpc statement");
+ throw new YangParseException(name, line, "input can be defined only in rpc statement");
}
final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
- final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
- inputQName, line);
+ final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(line, inputQName, schemaPath);
+ inputBuilder.setParent(rpc);
+
rpc.setInput(inputBuilder);
return inputBuilder;
}
- public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName,
- final int line) {
+ public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName outputQName, final int line) {
final Builder parent = actualPath.getFirst();
if (!(parent instanceof RpcDefinitionBuilder)) {
- throw new YangParseException(name, line,
- "output can be defined only in rpc statement");
+ throw new YangParseException(name, line, "output can be defined only in rpc statement");
}
final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
- final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
- outputQName, line);
+ final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(line, outputQName, schemaPath);
+ outputBuilder.setParent(rpc);
+
rpc.setOutput(outputBuilder);
return outputBuilder;
}
- public NotificationBuilder addNotification(final QName notificationName,
- final List<String> parentPath, final int line) {
+ public NotificationBuilder addNotification(final QName notificationName, final List<String> parentPath,
+ final int line) {
if (!(actualPath.isEmpty())) {
- throw new YangParseException(name, line,
- "notification can be defined only in module or submodule");
+ throw new YangParseException(name, line, "notification can be defined only in module or submodule");
+ }
+ for (NotificationBuilder nb : addedNotifications) {
+ if (nb.getQName().equals(notificationName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + nb.getLine());
+ }
}
- final NotificationBuilder builder = new NotificationBuilder(
- notificationName, line);
-
- final List<String> notificationPath = new ArrayList<String>(parentPath);
- notificationPath.add(notificationName.getLocalName());
+ final NotificationBuilder builder = new NotificationBuilder(line, notificationName);
addedNotifications.add(builder);
return builder;
}
- public FeatureBuilder addFeature(final QName featureName,
- final List<String> parentPath, final int line) {
- if (!(actualPath.isEmpty())) {
- throw new YangParseException(name, line,
- "feature can be defined only in module or submodule");
+ public FeatureBuilder addFeature(final int line, final QName featureName) {
+ Builder parent = getActualNode();
+ if (parent != null) {
+ throw new YangParseException(name, line, "feature can be defined only in module or submodule");
}
- final List<String> pathToFeature = new ArrayList<String>(parentPath);
- pathToFeature.add(featureName.getLocalName());
-
- final FeatureBuilder builder = new FeatureBuilder(featureName, line);
- addedFeatures.put(pathToFeature, builder);
+ final FeatureBuilder builder = new FeatureBuilder(line, featureName);
+ for (FeatureBuilder fb : addedFeatures) {
+ if (fb.getQName().getLocalName().equals(featureName.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + fb.getLine());
+ }
+ }
+ addedFeatures.add(builder);
return builder;
}
- public ChoiceBuilder addChoice(final QName choiceName,
- final List<String> parentPath, final int line) {
- final List<String> pathToChoice = new ArrayList<String>(parentPath);
- final ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
-
- if (!(actualPath.isEmpty())) {
- Builder parent = actualPath.getFirst();
- if (parent instanceof DataNodeContainerBuilder) {
- if (parent instanceof AugmentationSchemaBuilder) {
- builder.setAugmenting(true);
- }
- ((DataNodeContainerBuilder) parent).addChildNode(builder);
- } else {
- throw new YangParseException(name, line,
- "Unresolved parent of choice "
- + choiceName.getLocalName());
- }
- }
+ public ChoiceBuilder addChoice(final int line, final QName choiceName) {
+ final ChoiceBuilder builder = new ChoiceBuilder(line, choiceName);
- pathToChoice.add(choiceName.getLocalName());
- childNodes.put(pathToChoice, builder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, choiceName.getLocalName());
return builder;
}
- public ChoiceCaseBuilder addCase(final QName caseName,
- final List<String> parentPath, final int line) {
- final List<String> pathToCase = new ArrayList<String>(parentPath);
- final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
-
- if (actualPath.isEmpty()) {
+ public ChoiceCaseBuilder addCase(final int line, final QName caseName) {
+ Builder parent = getActualNode();
+ if (parent == null) {
throw new YangParseException(name, line, "'case' parent not found");
- } else {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof ChoiceBuilder) {
- ((ChoiceBuilder) parent).addChildNode(builder);
- } else if (parent instanceof AugmentationSchemaBuilder) {
- builder.setAugmenting(true);
- ((AugmentationSchemaBuilder) parent).addChildNode(builder);
- } else {
- throw new YangParseException(name, line,
- "Unresolved parent of 'case' "
- + caseName.getLocalName());
- }
}
- pathToCase.add(caseName.getLocalName());
- childNodes.put(pathToCase, builder);
+ final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(line, caseName);
+ builder.setParent(parent);
+
+ if (parent instanceof ChoiceBuilder) {
+ ((ChoiceBuilder) parent).addChildNode(builder);
+ } else if (parent instanceof AugmentationSchemaBuilder) {
+ ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+ } else {
+ throw new YangParseException(name, line, "Unresolved parent of 'case' " + caseName.getLocalName());
+ }
return builder;
}
- public AnyXmlBuilder addAnyXml(final QName anyXmlName,
- final List<String> parentPath, final int line) {
- final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
- final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
- updateParent(builder, line, "anyxml");
+ public AnyXmlBuilder addAnyXml(final int line, final QName anyXmlName, final SchemaPath schemaPath) {
+ final AnyXmlBuilder builder = new AnyXmlBuilder(line, anyXmlName, schemaPath);
- pathToAnyXml.add(anyXmlName.getLocalName());
- childNodes.put(pathToAnyXml, builder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+ addChildToParent(parent, builder, anyXmlName.getLocalName());
return builder;
}
- public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName,
- final List<String> parentPath, final int line) {
- final List<String> pathToType = new ArrayList<String>(parentPath);
- final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(
- typeDefName, line);
+ @Override
+ public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
+ for (TypeDefinitionBuilder tdb : addedTypedefs) {
+ if (tdb.getQName().getLocalName().equals(typedefBuilder.getQName().getLocalName())) {
+ throw new YangParseException(name, typedefBuilder.getLine(), "Duplicate node found at line "
+ + tdb.getLine());
+ }
+ }
+ addedTypedefs.add(typedefBuilder);
+ }
+
+ public TypeDefinitionBuilderImpl addTypedef(final int line, final QName typeDefName) {
+ final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typeDefName, line);
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof TypeDefinitionAwareBuilder) {
- ((TypeDefinitionAwareBuilder) parent).addTypedef(builder);
+ Builder parent = getActualNode();
+ builder.setParent(parent);
+
+ if (parent == null) {
+ for (TypeDefinitionBuilder tdb : addedTypedefs) {
+ if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {
+ throw new YangParseException(name, builder.getLine(), "Duplicate node found at line "
+ + tdb.getLine());
+ }
+ }
+ addedTypedefs.add(builder);
+ } else {
+ if (parent instanceof DataNodeContainerBuilder) {
+ DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+ for (DataSchemaNodeBuilder child : parentNode.getChildNodeBuilders()) {
+ if (child.getQName().getLocalName().equals(typeDefName.getLocalName())) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine());
+ }
+ }
+ parentNode.addTypedef(builder);
+ } else if (parent instanceof RpcDefinitionBuilder) {
+ RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent;
+ for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) {
+ if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {
+ throw new YangParseException(name, builder.getLine(), "Duplicate node found at line "
+ + tdb.getLine());
+ }
+ }
+ rpcParent.addTypedef(builder);
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of typedef "
- + typeDefName.getLocalName());
+ throw new YangParseException(name, line, "Unresolved parent of typedef " + typeDefName.getLocalName());
}
}
- pathToType.add(typeDefName.getLocalName());
- addedTypedefs.put(pathToType, builder);
return builder;
}
- public void setType(final TypeDefinition<?> type,
- final List<String> parentPath) {
-
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof TypeAwareBuilder) {
- ((TypeAwareBuilder) parent).setType(type);
- } else {
- throw new YangParseException("Failed to set type '"
- + type.getQName().getLocalName()
- + "'. Unknown parent node: " + parent);
- }
+ public void setType(final TypeDefinition<?> type) {
+ Builder parent = getActualNode();
+ if (parent == null || !(parent instanceof TypeAwareBuilder)) {
+ throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()
+ + "'. Unknown parent node: " + parent);
}
+ ((TypeAwareBuilder) parent).setType(type);
}
- public UnionTypeBuilder addUnionType(final List<String> currentPath,
- final URI namespace, final Date revision, final int line) {
+ public UnionTypeBuilder addUnionType(final List<String> currentPath, final URI namespace, final Date revision,
+ final int line) {
final List<String> pathToUnion = new ArrayList<String>(currentPath);
final UnionTypeBuilder union = new UnionTypeBuilder(line);
addedUnionTypes.put(path, union);
return union;
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of union type.");
+ throw new YangParseException(name, line, "Unresolved parent of union type.");
}
}
}
- public void addIdentityrefType(final String baseString,
- final List<String> parentPath, final SchemaPath schemaPath,
+ public void addIdentityrefType(final String baseString, final List<String> parentPath, final SchemaPath schemaPath,
final int line) {
final List<String> pathToIdentityref = new ArrayList<String>(parentPath);
- final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
- baseString, schemaPath, line);
+ final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString, schemaPath, line);
if (actualPath.isEmpty()) {
throw new YangParseException(line, "identityref error");
typeParent.setTypedef(identityref);
dirtyNodes.put(pathToIdentityref, typeParent);
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of identityref type.");
+ throw new YangParseException(name, line, "Unresolved parent of identityref type.");
}
}
}
- public DeviationBuilder addDeviation(final String targetPath,
- final List<String> parentPath, final int line) {
- if (!(actualPath.isEmpty())) {
- throw new YangParseException(name, line,
- "deviation can be defined only in module or submodule");
+ public DeviationBuilder addDeviation(final String targetPath, final List<String> parentPath, final int line) {
+ Builder parent = getActualNode();
+ if (parent != null) {
+ throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
}
final List<String> pathToDeviation = new ArrayList<String>(parentPath);
return builder;
}
- public IdentitySchemaNodeBuilder addIdentity(final QName qname,
- final List<String> parentPath, final int line) {
- if (!(actualPath.isEmpty())) {
- throw new YangParseException(name, line,
- "identity can be defined only in module or submodule");
+ public IdentitySchemaNodeBuilder addIdentity(final QName qname, final List<String> parentPath, final int line) {
+ Builder parent = getActualNode();
+ if (parent != null) {
+ throw new YangParseException(name, line, "identity can be defined only in module or submodule");
+ }
+ for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
+ if (idBuilder.getQName().equals(qname)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + idBuilder.getLine());
+ }
}
- final List<String> pathToIdentity = new ArrayList<String>(parentPath);
- final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(
- qname, line);
- pathToIdentity.add(qname.getLocalName());
+ final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(line, qname);
addedIdentities.add(builder);
return builder;
}
- public void addConfiguration(final boolean configuration,
- final List<String> parentPath, final int line) {
- if (actualPath.isEmpty()) {
- throw new YangParseException(name, line,
- "Parent node of config statement not found.");
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder builder) {
+ final List<String> unPath = new ArrayList<String>();
+ for (QName name : builder.getPath().getPath()) {
+ unPath.add(name.getLocalName());
+ }
+ if (addedUnknownNodes.containsKey(unPath)) {
+ addedUnknownNodes.get(unPath).add(builder);
} else {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof DataSchemaNodeBuilder) {
- ((DataSchemaNodeBuilder) parent)
- .setConfiguration(configuration);
- } else if (parent instanceof RefineHolder) {
- ((RefineHolder) parent).setConfig(configuration);
- } else if (parent instanceof DeviationBuilder) {
- // skip: set config to deviation (deviate stmt) not supported by
- // current api
- return;
- } else {
- throw new YangParseException(name, line,
- "Unresolved parent of config statement.");
- }
+ List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ nodes.add(builder);
+ addedUnknownNodes.put(unPath, nodes);
}
}
- public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname,
- final List<String> parentPath, final int line) {
- final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
- qname, line);
+ public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname, final List<String> parentPath,
+ final int line) {
+ final Builder parent = getActualNode();
+ final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(line, qname);
+ builder.setParent(parent);
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
+ if (parent != null) {
if (parent instanceof SchemaNodeBuilder) {
((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
} else if (parent instanceof RefineHolder) {
((RefineHolder) parent).addUnknownSchemaNode(builder);
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of unknown node '"
- + qname.getLocalName() + "'");
+ throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName()
+ + "'");
}
}
+ final List<String> unPath = new ArrayList<String>(parentPath);
+ unPath.add(qname.getLocalName());
- addedUnknownNodes.add(builder);
+ if (addedUnknownNodes.containsKey(unPath)) {
+ addedUnknownNodes.get(unPath).add(builder);
+ } else {
+ List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ nodes.add(builder);
+ addedUnknownNodes.put(unPath, nodes);
+ }
return builder;
}
private Set<ModuleImport> imports = Collections.emptySet();
private Set<FeatureDefinition> features = Collections.emptySet();
private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
- private Set<NotificationDefinition> notifications = Collections
- .emptySet();
+ private Set<NotificationDefinition> notifications = Collections.emptySet();
private Set<AugmentationSchema> augmentations = Collections.emptySet();
private Set<RpcDefinition> rpcs = Collections.emptySet();
private Set<Deviation> deviations = Collections.emptySet();
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<UsesNode> uses = Collections.emptySet();
- private List<ExtensionDefinition> extensionNodes = Collections
- .emptyList();
+ private List<ExtensionDefinition> extensionNodes = Collections.emptyList();
private Set<IdentitySchemaNode> identities = Collections.emptySet();
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private ModuleImpl(String name) {
this.name = name;
@Override
public Set<DataSchemaNode> getChildNodes() {
- return new HashSet<DataSchemaNode>(childNodes.values());
+ return new LinkedHashSet<DataSchemaNode>(childNodes.values());
}
private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
return extensionNodes;
}
- private void setExtensionSchemaNodes(
- List<ExtensionDefinition> extensionNodes) {
+ private void setExtensionSchemaNodes(final List<ExtensionDefinition> extensionNodes) {
if (extensionNodes != null) {
this.extensionNodes = extensionNodes;
}
return identities;
}
- private void setIdentities(Set<IdentitySchemaNode> identities) {
+ private void setIdentities(final Set<IdentitySchemaNode> identities) {
if (identities != null) {
this.identities = identities;
}
}
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
+ if (unknownNodes != null) {
+ this.unknownNodes = unknownNodes;
+ }
+ }
+
@Override
public DataSchemaNode getDataChildByName(QName name) {
return childNodes.get(name);
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((namespace == null) ? 0 : namespace.hashCode());
+ result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((revision == null) ? 0 : revision.hashCode());
- result = prime * result
- + ((prefix == null) ? 0 : prefix.hashCode());
- result = prime * result
- + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+ result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
return result;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ModuleImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
sb.append("[");
sb.append("name=" + name);
sb.append(", namespace=" + namespace);
}
}
- private void updateParent(DataSchemaNodeBuilder nodeBuilder, int line,
- String nodeTypeName) {
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
+ private void addChildToParent(final Builder parent, final DataSchemaNodeBuilder child, final String childLocalName) {
+ final int line = child.getLine();
+ if (parent == null) {
+ // if parent == null => node is defined under module
+ // All leafs, leaf-lists, lists, containers, choices, rpcs,
+ // notifications, and anyxmls defined within a parent node or at the
+ // top level of the module or its submodules share the same
+ // identifier namespace.
+ for (DataSchemaNodeBuilder childNode : childNodes) {
+ if (childNode.getQName().getLocalName().equals(childLocalName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + childNode.getLine());
+ }
+ }
+ for (RpcDefinitionBuilder rpc : addedRpcs) {
+ if (rpc.getQName().getLocalName().equals(childLocalName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + rpc.getLine());
+ }
+ }
+ for (NotificationBuilder notification : addedNotifications) {
+ if (notification.getQName().getLocalName().equals(childLocalName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + notification.getLine());
+ }
+ }
+ childNodes.add(child);
+ } else {
+ // no need for checking rpc and notification because they can be
+ // defined only under module or submodule
if (parent instanceof DataNodeContainerBuilder) {
- if (parent instanceof AugmentationSchemaBuilder) {
- nodeBuilder.setAugmenting(true);
+ DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+ for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) {
+ if (childNode.getQName().getLocalName().equals(childLocalName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line " + childNode.getLine());
+ }
}
- ((DataNodeContainerBuilder) parent).addChildNode(nodeBuilder);
+ parentNode.addChildNode(child);
} else if (parent instanceof ChoiceBuilder) {
- ((ChoiceBuilder) parent).addChildNode(nodeBuilder);
+ ChoiceBuilder parentNode = (ChoiceBuilder) parent;
+ for (ChoiceCaseBuilder caseBuilder : parentNode.getCases()) {
+ if (caseBuilder.getQName().getLocalName().equals(childLocalName)) {
+ throw new YangParseException(name, line, "Duplicate node found at line "
+ + caseBuilder.getLine());
+ }
+ }
+ parentNode.addChildNode(child);
} else {
- throw new YangParseException(name, line,
- "Unresolved parent of " + nodeTypeName + " "
- + nodeBuilder.getQName().getLocalName());
+ throw new YangParseException(name, line, "Unresolved parent of node '" + childLocalName + "'.");
}
}
}
- private ModuleImport createModuleImport(final String moduleName,
- final Date revision, final String prefix) {
- ModuleImport moduleImport = new ModuleImport() {
+ private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) {
+ final ModuleImport moduleImport = new ModuleImport() {
@Override
public String getModuleName() {
return moduleName;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((moduleName == null) ? 0 : moduleName.hashCode());
- result = prime * result
- + ((revision == null) ? 0 : revision.hashCode());
- result = prime * result
- + ((prefix == null) ? 0 : prefix.hashCode());
+ result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
return result;
}
@Override
public String toString() {
- return "ModuleImport[moduleName=" + moduleName + ", revision="
- + revision + ", prefix=" + prefix + "]";
+ return "ModuleImport[moduleName=" + moduleName + ", revision=" + revision + ", prefix=" + prefix + "]";
}
};
return moduleImport;
}
/**
- * Traverse through given addedChilds and add only direct module childs.
- * Direct module child path size is 2 (1. module name, 2. child name).
- *
- * @param addedChilds
- * @return map of children, where key is child QName and value is child
- * itself
- */
- private Map<QName, DataSchemaNode> buildModuleChildNodes(
- Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
- final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
- for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
- .entrySet()) {
- List<String> path = entry.getKey();
- DataSchemaNodeBuilder child = entry.getValue();
- if (path.size() == 2) {
- DataSchemaNode node = child.build();
- QName qname = node.getQName();
- childNodes.put(qname, node);
- }
- }
- return childNodes;
- }
-
- /**
- * Traverse through given addedGroupings and add only direct module
- * groupings. Direct module grouping path size is 2 (1. module name, 2.
- * grouping name).
- *
- * @param addedGroupings
- * @return set of built GroupingDefinition objects
- */
- private Set<GroupingDefinition> buildModuleGroupings(
- Map<List<String>, GroupingBuilder> addedGroupings) {
- final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
- for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- groupings.add(entry.getValue().build());
- }
- }
- return groupings;
- }
-
- /**
- * Traverse through given addedRpcs and build RpcDefinition objects.
- *
- * @param addedRpcs
- * @return set of built RpcDefinition objects
- */
- private Set<RpcDefinition> buildModuleRpcs(
- Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
- final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
- RpcDefinitionBuilder builder;
- for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
- .entrySet()) {
- builder = entry.getValue();
- RpcDefinition rpc = builder.build();
- rpcs.add(rpc);
- }
- return rpcs;
- }
-
- /**
- * Traverse through given addedTypedefs and add only direct module typedef
- * statements. Direct module typedef path size is 2 (1. module name, 2.
- * typedef name).
+ * Traverse through given addedUnknownNodes and add only unknown nodes
+ * defined under module statement.
*
- * @param addedTypedefs
- * @return set of built module typedef statements
+ * @param addedUnknownNodes
+ * unknown node builders
+ * @return list of all unknown nodes defined in module in lexicographical
+ * order
*/
- private Set<TypeDefinition<?>> buildModuleTypedefs(
- Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
- Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
- for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
- .entrySet()) {
- List<String> key = entry.getKey();
- TypeDefinitionBuilder typedefBuilder = entry.getValue();
- if (key.size() == 2) {
- TypeDefinition<? extends TypeDefinition<?>> node = typedefBuilder
- .build();
- typedefs.add(node);
- }
- }
- return typedefs;
- }
-
- /**
- * Traverse through given addedUsesNodes and add only direct module uses
- * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
- * name).
- *
- * @param addedUsesNodes
- * @return set of built module uses nodes
- */
- private Set<UsesNode> buildUsesNodes(
- Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
- final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
- for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- usesNodeDefs.add(entry.getValue().build());
- }
- }
- return usesNodeDefs;
- }
+ private List<UnknownSchemaNode> buildModuleUnknownNodes(
+ final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes) {
+ final List<UnknownSchemaNode> result = new ArrayList<UnknownSchemaNode>();
+ for (Map.Entry<List<String>, List<UnknownSchemaNodeBuilder>> entry : addedUnknownNodes.entrySet()) {
+ final List<String> path = entry.getKey();
+ final List<UnknownSchemaNodeBuilder> child = entry.getValue();
- /**
- * Traverse through given addedFeatures and add only direct module features.
- * Direct module feature path size is 2 (1. module name, 2. feature name).
- *
- * @param addedFeatures
- * @return set of built module features
- */
- private Set<FeatureDefinition> buildModuleFeatures(
- Map<List<String>, FeatureBuilder> addedFeatures) {
- Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
- for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- features.add(entry.getValue().build());
+ if (path.size() == 2) {
+ for (UnknownSchemaNodeBuilder node : child) {
+ result.add(node.build());
+ }
}
}
- return features;
+ Collections.sort(result, Comparators.SCHEMA_NODE_COMP);
+ return result;
}
}
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.NotificationDefinition;
-import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
- implements TypeDefinitionAwareBuilder, SchemaNodeBuilder {
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder implements SchemaNodeBuilder,
+ AugmentationTargetBuilder {
private boolean isBuilt;
private final NotificationDefinitionImpl instance;
private final int line;
private SchemaPath schemaPath;
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+ private Set<AugmentationSchema> augmentations;
+ private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- NotificationBuilder(final QName qname, final int line) {
- super(qname);
+ NotificationBuilder(final int line, final QName qname) {
+ super(line, qname);
this.line = line;
instance = new NotificationDefinitionImpl(qname);
}
@Override
- public SchemaNode build() {
+ public NotificationDefinition build() {
if (!isBuilt) {
instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
// CHILD NODES
- final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- for (DataSchemaNodeBuilder node : childNodes) {
+ final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+ for (DataSchemaNodeBuilder node : addedChildNodes) {
childs.put(node.getQName(), node.build());
}
instance.setChildNodes(childs);
// GROUPINGS
- final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
- for (GroupingBuilder builder : groupings) {
+ final Set<GroupingDefinition> groupingDefs = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+ for (GroupingBuilder builder : addedGroupings) {
groupingDefs.add(builder.build());
}
instance.setGroupings(groupingDefs);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
+ final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
for (TypeDefinitionBuilder entry : addedTypedefs) {
typedefs.add(entry.build());
}
}
instance.setUses(uses);
+ // AUGMENTATIONS
+ if (augmentations == null) {
+ augmentations = new HashSet<AugmentationSchema>();
+ for (AugmentationSchemaBuilder builder : addedAugmentations) {
+ augmentations.add(builder.build());
+ }
+ }
+ instance.setAvailableAugmentations(augmentations);
+
// UNKNOWN NODES
final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
instance.setUnknownSchemaNodes(unknownNodes);
isBuilt = true;
}
@Override
- public int getLine() {
- return line;
+ public void rebuild() {
+ isBuilt = false;
+ build();
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
this.schemaPath = schemaPath;
}
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
@Override
public void setDescription(final String description) {
- instance.setDescription(description);
+ this.description = description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
}
@Override
public void setReference(final String reference) {
- instance.setReference(reference);
+ this.reference = reference;
+ }
+
+ @Override
+ public Status getStatus() {
+ return status;
}
@Override
public void setStatus(final Status status) {
- instance.setStatus(status);
+ if (status != null) {
+ this.status = status;
+ }
+ }
+
+ public Set<AugmentationSchemaBuilder> getAugmentations() {
+ return addedAugmentations;
+ }
+
+ @Override
+ public void addAugmentation(AugmentationSchemaBuilder augment) {
+ addedAugmentations.add(augment);
+ }
+
+ public void setAugmentations(final Set<AugmentationSchema> augmentations) {
+ this.augmentations = augmentations;
}
@Override
return "notification " + getQName().getLocalName();
}
- private final class NotificationDefinitionImpl implements NotificationDefinition {
+ public final class NotificationDefinitionImpl implements NotificationDefinition {
private final QName qname;
private SchemaPath path;
private String description;
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
private Set<UsesNode> uses = Collections.emptySet();
+ private Set<AugmentationSchema> augmentations = Collections.emptySet();
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private NotificationDefinitionImpl(final QName qname) {
return typeDefinitions;
}
- private void setTypeDefinitions(
- final Set<TypeDefinition<?>> typeDefinitions) {
+ private void setTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
if (typeDefinitions != null) {
this.typeDefinitions = typeDefinitions;
}
}
+ @Override
+ public Set<AugmentationSchema> getAvailableAugmentations() {
+ return augmentations;
+ }
+
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
+ if (augmentations != null) {
+ this.augmentations = augmentations;
+ }
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- final List<UnknownSchemaNode> unknownNodes) {
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
return result;
}
+ public NotificationBuilder toBuilder() {
+ return NotificationBuilder.this;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- NotificationDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(NotificationDefinitionImpl.class.getSimpleName());
sb.append("[qname=" + qname + ", path=" + path + "]");
return sb.toString();
}
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefinitionAwareBuilder {
+public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final RpcDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
private ContainerSchemaNodeBuilder inputBuilder;
private ContainerSchemaNodeBuilder outputBuilder;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- RpcDefinitionBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ RpcDefinitionBuilder(final int line, final QName qname) {
+ super(line, qname);
this.instance = new RpcDefinitionImpl(qname);
}
@Override
public RpcDefinition build() {
if (!isBuilt) {
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
+
final ContainerSchemaNode input = inputBuilder == null ? null : inputBuilder.build();
final ContainerSchemaNode output = outputBuilder == null ? null : outputBuilder.build();
instance.setInput(input);
instance.setPath(schemaPath);
// TYPEDEFS
- final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
+ final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
for (TypeDefinitionBuilder entry : addedTypedefs) {
typedefs.add(entry.build());
}
instance.setTypeDefinitions(typedefs);
// GROUPINGS
- final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
+ final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
for (GroupingBuilder entry : addedGroupings) {
groupings.add(entry.build());
}
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
instance.setUnknownSchemaNodes(unknownNodes);
isBuilt = true;
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
this.inputBuilder = inputBuilder;
}
return addedTypedefs;
}
- @Override
public void addTypedef(final TypeDefinitionBuilder type) {
addedTypedefs.add(type);
}
addedGroupings.add(grouping);
}
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public void setDescription(final String description) {
- instance.setDescription(description);
- }
-
- @Override
- public void setReference(final String reference) {
- instance.setReference(reference);
- }
-
- @Override
- public void setStatus(final Status status) {
- instance.setStatus(status);
- }
-
- @Override
- public QName getQName() {
- return null;
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
@Override
public int hashCode() {
- return qname.hashCode();
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
}
@Override
} else if (!other.qname.equals(this.qname)) {
return false;
}
+ if (other.schemaPath == null) {
+ if (this.schemaPath != null) {
+ return false;
+ }
+ } else if (!other.schemaPath.equals(this.schemaPath)) {
+ return false;
+ }
return true;
}
import org.opendaylight.controller.yang.model.util.UnknownType;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
- implements TypeDefinitionBuilder {
- private final int line;
- private final QName qname;
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private SchemaPath schemaPath;
-
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private List<UnknownSchemaNode> unknownNodes;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private List<RangeConstraint> ranges = Collections.emptyList();
private List<LengthConstraint> lengths = Collections.emptyList();
private List<PatternConstraint> patterns = Collections.emptyList();
private Status status = Status.CURRENT;
private String units;
private Object defaultValue;
+ private boolean addedByUses;
public TypeDefinitionBuilderImpl(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(line, qname);
+ }
+
+ public TypeDefinitionBuilderImpl(TypeDefinitionBuilder tdb) {
+ super(tdb.getLine(), tdb.getQName());
+ schemaPath = tdb.getPath();
+
+ type = tdb.getType();
+ typedef = tdb.getTypedef();
+
+ unknownNodes = tdb.getUnknownNodes();
+ for (UnknownSchemaNodeBuilder usnb : tdb.getUnknownNodeBuilders()) {
+ addedUnknownNodes.add(usnb);
+ }
+ ranges = tdb.getRanges();
+ lengths = tdb.getLengths();
+ patterns = tdb.getPatterns();
+ fractionDigits = tdb.getFractionDigits();
+
+ description = tdb.getDescription();
+ reference = tdb.getReference();
+ status = tdb.getStatus();
+ units = tdb.getUnits();
+ defaultValue = tdb.getDefaultValue();
+ addedByUses = tdb.isAddedByUses();
}
@Override
TypeDefinition<?> result = null;
ExtendedType.Builder typeBuilder = null;
if ((type == null || type instanceof UnknownType) && typedef == null) {
- throw new YangParseException("Unresolved type: '"
- + qname.getLocalName() + "'.");
+ throw new YangParseException("Unresolved type: '" + qname.getLocalName() + "'.");
}
if (type == null || type instanceof UnknownType) {
type = typedef.build();
}
- typeBuilder = new ExtendedType.Builder(qname, type, description,
- reference, schemaPath);
+ typeBuilder = new ExtendedType.Builder(qname, type, description, reference, schemaPath);
typeBuilder.status(status);
typeBuilder.units(units);
typeBuilder.defaultValue(defaultValue);
+ typeBuilder.addedByUses(addedByUses);
typeBuilder.ranges(ranges);
typeBuilder.lengths(lengths);
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
typeBuilder.unknownSchemaNodes(unknownNodes);
result = typeBuilder.build();
return result;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
@Override
public SchemaPath getPath() {
return schemaPath;
}
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public String getUnits() {
return units;
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return addedUnknownNodes;
}
@Override
public String toString() {
- final StringBuilder result = new StringBuilder("TypedefBuilder["
- + qname.getLocalName());
+ final StringBuilder result = new StringBuilder("TypedefBuilder[" + qname.getLocalName());
result.append(", type=");
if (type == null) {
result.append(typedef);
import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
* When build is called, types in builder form will be built and add to resolved
* types.
*/
-public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
- TypeDefinitionBuilder {
+public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private final static String NAME = "union";
- private final int line;
private final List<TypeDefinition<?>> types;
private final List<TypeDefinitionBuilder> typedefs;
private UnionType instance;
private SchemaPath path;
public UnionTypeBuilder(final int line) {
- this.line = line;
+ super(line, null);
types = new ArrayList<TypeDefinition<?>>();
typedefs = new ArrayList<TypeDefinitionBuilder>();
}
- @Override
- public int getLine() {
- return line;
- }
public List<TypeDefinition<?>> getTypes() {
return types;
}
@Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new YangParseException(line, "Can not add unknown node to "
- + NAME);
+ public boolean isAddedByUses() {
+ return false;
}
@Override
- public QName getQName() {
- return null;
+ public void setAddedByUses(final boolean addedByUses) {
+ throw new YangParseException(line, "Union type can not be added by uses.");
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
+ // not yet supported
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new YangParseException(line, "Can not set fraction digits to "
- + NAME);
+ throw new YangParseException(line, "Can not set fraction digits to " + NAME);
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return Collections.emptyList();
}
@Override
public void setDefaultValue(Object defaultValue) {
- throw new YangParseException(line, "Can not set default value to "
- + NAME);
+ throw new YangParseException(line, "Can not set default value to " + NAME);
}
@Override
@Override
public String toString() {
- final StringBuilder result = new StringBuilder(
- UnionTypeBuilder.class.getSimpleName() + "[");
+ final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName() + "[");
result.append(", types=" + types);
result.append(", typedefs=" + typedefs);
result.append("]");
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.util.Comparators;
-public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
+public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final UnknownSchemaNodeImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ private boolean addedByUses;
+ private List<UnknownSchemaNode> unknownNodes;
private QName nodeType;
private String nodeParameter;
- UnknownSchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public UnknownSchemaNodeBuilder(final int line, final QName qname) {
+ super(line, qname);
instance = new UnknownSchemaNodeImpl(qname);
}
+ public UnknownSchemaNodeBuilder(UnknownSchemaNodeBuilder b) {
+ super(b.getLine(), b.getQName());
+ instance = new UnknownSchemaNodeImpl(qname);
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ addedByUses = b.isAddedByUses();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.addedUnknownNodes);
+ nodeType = b.getNodeType();
+ nodeParameter = b.getNodeParameter();
+ }
+
@Override
public UnknownSchemaNode build() {
- if(!isBuilt) {
+ if (!isBuilt) {
instance.setPath(schemaPath);
instance.setNodeType(nodeType);
instance.setNodeParameter(nodeParameter);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
+ instance.setAddedByUses(addedByUses);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
}
instance.setUnknownSchemaNodes(unknownNodes);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
+ public boolean isAddedByUses() {
+ return addedByUses;
}
- @Override
- public SchemaPath getPath() {
- return schemaPath;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public void setDescription(final String description) {
- instance.setDescription(description);
- }
-
- @Override
- public void setReference(final String reference) {
- instance.setReference(reference);
- }
-
- @Override
- public void setStatus(final Status status) {
- instance.setStatus(status);
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
+ public void setUnknownNodes(final List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
}
public QName getNodeType() {
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private QName nodeType;
private String nodeParameter;
+ private boolean addedByUses;
private UnknownSchemaNodeImpl(final QName qname) {
this.qname = qname;
}
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- final List<UnknownSchemaNode> unknownNodes) {
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
private void setNodeParameter(final String nodeParameter) {
this.nodeParameter = nodeParameter;
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(UnknownSchemaNodeImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append(qname);
+ sb.append("]");
+ return sb.toString();
+ }
}
}
import org.opendaylight.controller.yang.model.api.AugmentationSchema;\r
import org.opendaylight.controller.yang.model.api.SchemaNode;\r
import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
import org.opendaylight.controller.yang.model.api.UsesNode;\r
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;\r
+import org.opendaylight.controller.yang.parser.builder.api.Builder;\r
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;\r
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;\r
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;\r
import org.opendaylight.controller.yang.parser.util.RefineHolder;\r
+import org.opendaylight.controller.yang.parser.util.YangParseException;\r
\r
public final class UsesNodeBuilderImpl implements UsesNodeBuilder {\r
private boolean isBuilt;\r
private UsesNodeImpl instance;\r
private final int line;\r
- private SchemaPath schemaPath;\r
+ private DataNodeContainerBuilder parent;\r
private final String groupingName;\r
private SchemaPath groupingPath;\r
private boolean augmenting;\r
+ private boolean addedByUses;\r
private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
- private List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
- private List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+ private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
+ private final List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
\r
- public UsesNodeBuilderImpl(final String groupingName, final int line) {\r
+ public UsesNodeBuilderImpl(final int line, final String groupingName) {\r
this.groupingName = groupingName;\r
this.line = line;\r
}\r
\r
+ public UsesNodeBuilderImpl(UsesNodeBuilder b) {\r
+ groupingName = b.getGroupingName();\r
+ line = b.getLine();\r
+ parent = b.getParent();\r
+ groupingPath = b.getGroupingPath();\r
+ augmenting = b.isAugmenting();\r
+ addedByUses = b.isAddedByUses();\r
+ addedAugments.addAll(b.getAugmentations());\r
+ refineBuilders.addAll(b.getRefineNodes());\r
+ refines.addAll(b.getRefines());\r
+ }\r
+\r
@Override\r
public UsesNode build() {\r
if (!isBuilt) {\r
instance = new UsesNodeImpl(groupingPath);\r
instance.setAugmenting(augmenting);\r
+ instance.setAddedByUses(addedByUses);\r
\r
// AUGMENTATIONS\r
final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();\r
}\r
instance.setRefines(refineNodes);\r
\r
+ // UNKNOWN NODES\r
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();\r
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {\r
+ unknownNodes.add(b.build());\r
+ }\r
+ instance.setUnknownSchemaNodes(unknownNodes);\r
+\r
isBuilt = true;\r
}\r
return instance;\r
}\r
\r
@Override\r
- public void setGroupingPath(SchemaPath groupingPath) {\r
- this.groupingPath = groupingPath;\r
+ public DataNodeContainerBuilder getParent() {\r
+ return parent;\r
}\r
\r
@Override\r
- public SchemaPath getPath() {\r
- return schemaPath;\r
+ public void setParent(Builder parent) {\r
+ if (!(parent instanceof DataNodeContainerBuilder)) {\r
+ throw new YangParseException(line, "Unresolved parent of uses '" + groupingName + "'.");\r
+ }\r
+ this.parent = (DataNodeContainerBuilder) parent;\r
}\r
\r
@Override\r
- public void setPath(SchemaPath path) {\r
- this.schemaPath = path;\r
+ public SchemaPath getGroupingPath() {\r
+ return groupingPath;\r
+ }\r
+\r
+ @Override\r
+ public void setGroupingPath(SchemaPath groupingPath) {\r
+ this.groupingPath = groupingPath;\r
}\r
\r
@Override\r
this.augmenting = augmenting;\r
}\r
\r
+ @Override\r
+ public boolean isAddedByUses() {\r
+ return addedByUses;\r
+ }\r
+\r
+ @Override\r
+ public void setAddedByUses(final boolean addedByUses) {\r
+ this.addedByUses = addedByUses;\r
+ }\r
+\r
@Override\r
public List<SchemaNodeBuilder> getRefineNodes() {\r
return refineBuilders;\r
refines.add(refine);\r
}\r
\r
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {\r
+ return addedUnknownNodes;\r
+ }\r
+\r
+ @Override\r
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+ addedUnknownNodes.add(unknownNode);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result + ((groupingName == null) ? 0 : groupingName.hashCode());\r
+ return result;\r
+ }\r
\r
- private final class UsesNodeImpl implements UsesNode {\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ UsesNodeBuilderImpl other = (UsesNodeBuilderImpl) obj;\r
+ if (groupingName == null) {\r
+ if (other.groupingName != null)\r
+ return false;\r
+ } else if (!groupingName.equals(other.groupingName))\r
+ return false;\r
+\r
+ if (parent == null) {\r
+ if (other.parent != null)\r
+ return false;\r
+ } else if (!parent.equals(other.parent))\r
+ return false;\r
+ if (refines == null) {\r
+ if (other.refines != null)\r
+ return false;\r
+ } else if (!refines.equals(other.refines))\r
+ return false;\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "uses '" + groupingName + "'";\r
+ }\r
+\r
+ public final class UsesNodeImpl implements UsesNode {\r
private final SchemaPath groupingPath;\r
private Set<AugmentationSchema> augmentations = Collections.emptySet();\r
private boolean augmenting;\r
+ private boolean addedByUses;\r
private Map<SchemaPath, SchemaNode> refines = Collections.emptyMap();\r
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
\r
private UsesNodeImpl(final SchemaPath groupingPath) {\r
this.groupingPath = groupingPath;\r
return augmentations;\r
}\r
\r
- private void setAugmentations(\r
- final Set<AugmentationSchema> augmentations) {\r
+ private void setAugmentations(final Set<AugmentationSchema> augmentations) {\r
if (augmentations != null) {\r
this.augmentations = augmentations;\r
}\r
this.augmenting = augmenting;\r
}\r
\r
+ @Override\r
+ public boolean isAddedByUses() {\r
+ return addedByUses;\r
+ }\r
+\r
+ private void setAddedByUses(final boolean addedByUses) {\r
+ this.addedByUses = addedByUses;\r
+ }\r
+\r
@Override\r
public Map<SchemaPath, SchemaNode> getRefines() {\r
return refines;\r
}\r
}\r
\r
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
+ return unknownNodes;\r
+ }\r
+\r
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {\r
+ if (unknownSchemaNodes != null) {\r
+ this.unknownNodes = unknownSchemaNodes;\r
+ }\r
+ }\r
+\r
+ public UsesNodeBuilder toBuilder() {\r
+ return UsesNodeBuilderImpl.this;\r
+ }\r
+\r
@Override\r
public int hashCode() {\r
final int prime = 31;\r
int result = 1;\r
- result = prime * result\r
- + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
- result = prime * result\r
- + ((augmentations == null) ? 0 : augmentations.hashCode());\r
+ result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
+ result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
result = prime * result + (augmenting ? 1231 : 1237);\r
return result;\r
}\r
\r
@Override\r
public String toString() {\r
- StringBuilder sb = new StringBuilder(\r
- UsesNodeImpl.class.getSimpleName());\r
+ StringBuilder sb = new StringBuilder(UsesNodeImpl.class.getSimpleName());\r
sb.append("[groupingPath=" + groupingPath + "]");\r
return sb.toString();\r
}\r
}\r
+\r
}\r
if (module.getName().equals(name)) {
return module;
}
- } else if (module.getName().equals(name)
- && module.getRevision().equals(revision)) {
+ } else if (module.getName().equals(name) && module.getRevision().equals(revision)) {
return module;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class YangErrorListener extends BaseErrorListener {
+ private final static Logger logger = LoggerFactory.getLogger(YangErrorListener.class);
+
+ @Override
+ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
+ String msg, RecognitionException e) {
+ logger.warn("line " + line + ":" + charPositionInLine + " " + msg);
+ }
+
+}
*/
package org.opendaylight.controller.yang.parser.impl;
+import static org.opendaylight.controller.yang.parser.util.ParserUtils.*;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.controller.antlrv4.code.gen.YangLexer;
import org.opendaylight.controller.antlrv4.code.gen.YangParser;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
-import org.opendaylight.controller.yang.model.api.ModuleImport;
import org.opendaylight.controller.yang.model.api.SchemaContext;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.DecimalTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.IdentityrefType;
import org.opendaylight.controller.yang.model.util.UnknownType;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.IdentityrefTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl.UsesNodeImpl;
import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
-import org.opendaylight.controller.yang.parser.util.ParserUtils;
import org.opendaylight.controller.yang.parser.util.RefineHolder;
+import org.opendaylight.controller.yang.parser.util.RefineUtils;
import org.opendaylight.controller.yang.parser.util.TypeConstraints;
import org.opendaylight.controller.yang.parser.util.YangParseException;
import org.opendaylight.controller.yang.validator.YangModelBasicValidator;
import com.google.common.collect.Sets;
public final class YangParserImpl implements YangModelParser {
-
private static final Logger logger = LoggerFactory.getLogger(YangParserImpl.class);
@Override
- public Map<File, Module> parseYangModelsMapped(List<File> yangFiles) {
+ public Set<Module> parseYangModels(final List<File> yangFiles) {
+ return Sets.newLinkedHashSet(parseYangModelsMapped(yangFiles).values());
+ }
+
+ @Override
+ public Set<Module> parseYangModels(final List<File> yangFiles, final SchemaContext context) {
if (yangFiles != null) {
final Map<InputStream, File> inputStreams = Maps.newHashMap();
final Map<String, TreeMap<Date, ModuleBuilder>> modules = resolveModuleBuilders(
Lists.newArrayList(inputStreams.keySet()), builderToStreamMap);
- // return new LinkedHashSet<Module>(build(modules).values());
+
+ for (InputStream is : inputStreams.keySet()) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ logger.debug("Failed to close stream.");
+ }
+ }
+
+ return new LinkedHashSet<Module>(buildWithContext(modules, context).values());
+ }
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams) {
+ return Sets.newHashSet(parseYangModelsFromStreamsMapped(yangModelStreams).values());
+ }
+
+ @Override
+ public Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams, SchemaContext context) {
+ if (yangModelStreams != null) {
+ Map<ModuleBuilder, InputStream> builderToStreamMap = Maps.newHashMap();
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules = resolveModuleBuildersWithContext(
+ yangModelStreams, builderToStreamMap, context);
+ return new LinkedHashSet<Module>(buildWithContext(modules, context).values());
+ }
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Map<File, Module> parseYangModelsMapped(List<File> yangFiles) {
+ if (yangFiles != null) {
+ final Map<InputStream, File> inputStreams = Maps.newHashMap();
+
+ for (final File yangFile : yangFiles) {
+ try {
+ inputStreams.put(new FileInputStream(yangFile), yangFile);
+ } catch (FileNotFoundException e) {
+ logger.warn("Exception while reading yang file: " + yangFile.getName(), e);
+ }
+ }
+
+ Map<ModuleBuilder, InputStream> builderToStreamMap = Maps.newHashMap();
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules = resolveModuleBuilders(
+ Lists.newArrayList(inputStreams.keySet()), builderToStreamMap);
+
+ for (InputStream is : inputStreams.keySet()) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ logger.debug("Failed to close stream.");
+ }
+ }
Map<File, Module> retVal = Maps.newLinkedHashMap();
Map<ModuleBuilder, Module> builderToModuleMap = build(modules);
return Collections.emptyMap();
}
- @Override
- public Set<Module> parseYangModels(final List<File> yangFiles) {
- return Sets.newLinkedHashSet(parseYangModelsMapped(yangFiles).values());
- }
-
- @Override
- public Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams) {
- return Sets.newHashSet(parseYangModelsFromStreamsMapped(yangModelStreams).values());
- }
-
@Override
public Map<InputStream, Module> parseYangModelsFromStreamsMapped(final List<InputStream> yangModelStreams) {
Map<ModuleBuilder, InputStream> builderToStreamMap = Maps.newHashMap();
private Map<String, TreeMap<Date, ModuleBuilder>> resolveModuleBuilders(final List<InputStream> yangFileStreams,
Map<ModuleBuilder, InputStream> streamToBuilderMap) {
+ return resolveModuleBuildersWithContext(yangFileStreams, streamToBuilderMap, null);
+ }
+ private Map<String, TreeMap<Date, ModuleBuilder>> resolveModuleBuildersWithContext(
+ final List<InputStream> yangFileStreams, final Map<ModuleBuilder, InputStream> streamToBuilderMap,
+ final SchemaContext context) {
final ModuleBuilder[] builders = parseModuleBuilders(yangFileStreams, streamToBuilderMap);
// Linked Hash Map MUST be used because Linked Hash Map preserves ORDER
final LinkedHashMap<String, TreeMap<Date, ModuleBuilder>> modules = new LinkedHashMap<String, TreeMap<Date, ModuleBuilder>>();
// module dependency graph sorted
- List<ModuleBuilder> sorted = ModuleDependencySort.sort(builders);
+ List<ModuleBuilder> sorted = null;
+ if (context == null) {
+ sorted = ModuleDependencySort.sort(builders);
+ } else {
+ sorted = ModuleDependencySort.sortWithContext(context, builders);
+ }
- for (ModuleBuilder builder : sorted) {
+ for (final ModuleBuilder builder : sorted) {
+ if (builder == null) {
+ continue;
+ }
final String builderName = builder.getName();
Date builderRevision = builder.getRevision();
if (builderRevision == null) {
final YangLexer lexer = new YangLexer(input);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final YangParser parser = new YangParser(tokens);
+ parser.removeErrorListeners();
+ parser.addErrorListener(new YangErrorListener());
result = parser.yang();
} catch (IOException e) {
return result;
}
+ private Map<ModuleBuilder, Module> buildWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ SchemaContext context) {
+ // fix unresolved nodes
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
+ final ModuleBuilder moduleBuilder = childEntry.getValue();
+ fixUnresolvedNodesWithContext(modules, moduleBuilder, context);
+ }
+ }
+ resolveAugmentsWithContext(modules, context);
+
+ // build
+ // LinkedHashMap MUST be used otherwise the values will not maintain
+ // order!
+ // http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashMap.html
+ final Map<ModuleBuilder, Module> result = new LinkedHashMap<ModuleBuilder, Module>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ final Map<Date, Module> modulesByRevision = new HashMap<Date, Module>();
+ for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
+ final ModuleBuilder moduleBuilder = childEntry.getValue();
+ final Module module = moduleBuilder.build();
+ modulesByRevision.put(childEntry.getKey(), module);
+ result.put(moduleBuilder, module);
+ }
+ }
+ return result;
+ }
+
private void fixUnresolvedNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
resolveDirtyNodes(modules, builder);
resolveIdentities(modules, builder);
- resolveUsesRefines(modules, builder);
+ resolveUsesRefine(modules, builder);
resolveUnknownNodes(modules, builder);
}
+ private void fixUnresolvedNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder builder, final SchemaContext context) {
+ resolveDirtyNodesWithContext(modules, builder, context);
+ resolveIdentitiesWithContext(modules, builder, context);
+ resolveUsesRefineWithContext(modules, builder, context);
+ resolveUnknownNodesWithContext(modules, builder, context);
+ }
+
/**
* Search for dirty nodes (node which contains UnknownType) and resolve
* unknown types.
}
}
+ private void resolveDirtyNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, SchemaContext context) {
+ final Map<List<String>, TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
+ if (!dirtyNodes.isEmpty()) {
+ for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
+ final TypeAwareBuilder nodeToResolve = entry.getValue();
+
+ if (nodeToResolve instanceof UnionTypeBuilder) {
+ // special handling for union types
+ resolveTypeUnionWithContext((UnionTypeBuilder) nodeToResolve, modules, module, context);
+ } else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
+ // special handling for identityref types
+ IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve.getTypedef();
+ nodeToResolve.setType(new IdentityrefType(findFullQName(modules, module, idref), idref.getPath()));
+ } else {
+ resolveTypeWithContext(nodeToResolve, modules, module, context);
+ }
+ }
+ }
+ }
+
+ /**
+ * Resolve unknown type of node. It is assumed that type of node is either
+ * UnknownType or ExtendedType with UnknownType as base type.
+ *
+ * @param nodeToResolve
+ * node with type to resolve
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ */
private void resolveType(final TypeAwareBuilder nodeToResolve,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
TypeDefinitionBuilder resolvedType = null;
final int line = nodeToResolve.getLine();
final TypeDefinition<?> nodeToResolveType = nodeToResolve.getType();
final QName unknownTypeQName = nodeToResolveType.getBaseType().getQName();
- final ModuleBuilder dependentModule = findDependentModule(modules, builder, unknownTypeQName.getPrefix(), line);
+ final ModuleBuilder dependentModule = findDependentModuleBuilder(modules, module, unknownTypeQName.getPrefix(),
+ line);
- final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(nodeToResolve.getPath(),
- dependentModule, unknownTypeQName.getLocalName(), builder.getName(), line);
+ final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(nodeToResolve, dependentModule,
+ unknownTypeQName.getLocalName(), module.getName(), line);
if (nodeToResolveType instanceof ExtendedType) {
final ExtendedType extType = (ExtendedType) nodeToResolveType;
- final TypeDefinitionBuilder newType = extendedTypeWithNewBaseType(nodeToResolve, targetTypeBuilder,
- extType, modules, builder);
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseTypeBuilder(targetTypeBuilder, extType,
+ modules, module, nodeToResolve.getLine());
resolvedType = newType;
} else {
resolvedType = targetTypeBuilder;
}
// validate constraints
- final TypeConstraints constraints = findConstraints(nodeToResolve, new TypeConstraints(builder.getName(),
- nodeToResolve.getLine()), modules, builder);
+ final TypeConstraints constraints = findConstraintsFromTypeBuilder(nodeToResolve,
+ new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, null);
constraints.validateConstraints();
nodeToResolve.setTypedef(resolvedType);
}
+ /**
+ * Resolve unknown type of node. It is assumed that type of node is either
+ * UnknownType or ExtendedType with UnknownType as base type.
+ *
+ * @param nodeToResolve
+ * node with type to resolve
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ * @param context
+ * SchemaContext containing already resolved modules
+ */
+ private void resolveTypeWithContext(final TypeAwareBuilder nodeToResolve,
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
+ final SchemaContext context) {
+ TypeDefinitionBuilder resolvedType = null;
+ final int line = nodeToResolve.getLine();
+ final TypeDefinition<?> nodeToResolveType = nodeToResolve.getType();
+ final QName unknownTypeQName = nodeToResolveType.getBaseType().getQName();
+ final ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module,
+ unknownTypeQName.getPrefix(), line);
+
+ if (dependentModuleBuilder == null) {
+ final Module dependentModule = findModuleFromContext(context, module, unknownTypeQName.getPrefix(), line);
+ final Set<TypeDefinition<?>> types = dependentModule.getTypeDefinitions();
+ final TypeDefinition<?> type = findTypeByName(types, unknownTypeQName.getLocalName());
+
+ if (nodeToResolveType instanceof ExtendedType) {
+ final ExtendedType extType = (ExtendedType) nodeToResolveType;
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseType(type, extType, module,
+ nodeToResolve.getLine());
+
+ nodeToResolve.setTypedef(newType);
+ } else {
+ if (nodeToResolve instanceof TypeDefinitionBuilder) {
+ TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) nodeToResolve;
+ TypeConstraints tc = findConstraintsFromTypeBuilder(nodeToResolve,
+ new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, context);
+ tdb.setLengths(tc.getLength());
+ tdb.setPatterns(tc.getPatterns());
+ tdb.setRanges(tc.getRange());
+ tdb.setFractionDigits(tc.getFractionDigits());
+ }
+ nodeToResolve.setType(type);
+ }
+
+ } else {
+ final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(nodeToResolve,
+ dependentModuleBuilder, unknownTypeQName.getLocalName(), module.getName(), line);
+
+ if (nodeToResolveType instanceof ExtendedType) {
+ final ExtendedType extType = (ExtendedType) nodeToResolveType;
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseTypeBuilder(targetTypeBuilder, extType,
+ modules, module, nodeToResolve.getLine());
+ resolvedType = newType;
+ } else {
+ resolvedType = targetTypeBuilder;
+ }
+
+ // validate constraints
+ final TypeConstraints constraints = findConstraintsFromTypeBuilder(nodeToResolve, new TypeConstraints(
+ module.getName(), nodeToResolve.getLine()), modules, module, context);
+ constraints.validateConstraints();
+
+ nodeToResolve.setTypedef(resolvedType);
+ }
+ }
+
private void resolveTypeUnion(final UnionTypeBuilder union,
final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
for (TypeDefinition<?> unionType : unionTypes) {
if (unionType instanceof UnknownType) {
final UnknownType ut = (UnknownType) unionType;
- final ModuleBuilder dependentModule = findDependentModule(modules, builder, ut.getQName().getPrefix(),
- union.getLine());
- final TypeDefinitionBuilder resolvedType = findTypeDefinitionBuilder(union.getPath(), dependentModule,
- ut.getQName().getLocalName(), builder.getName(), union.getLine());
+ final ModuleBuilder dependentModule = findDependentModuleBuilder(modules, builder, ut.getQName()
+ .getPrefix(), union.getLine());
+ final TypeDefinitionBuilder resolvedType = findTypeDefinitionBuilder(union, dependentModule, ut
+ .getQName().getLocalName(), builder.getName(), union.getLine());
union.setTypedef(resolvedType);
toRemove.add(ut);
} else if (unionType instanceof ExtendedType) {
final ExtendedType extType = (ExtendedType) unionType;
- TypeDefinition<?> extTypeBase = extType.getBaseType();
+ final TypeDefinition<?> extTypeBase = extType.getBaseType();
if (extTypeBase instanceof UnknownType) {
final UnknownType ut = (UnknownType) extTypeBase;
- final ModuleBuilder dependentModule = findDependentModule(modules, builder, ut.getQName()
+ final ModuleBuilder dependentModule = findDependentModuleBuilder(modules, builder, ut.getQName()
.getPrefix(), union.getLine());
- final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(union.getPath(),
- dependentModule, ut.getQName().getLocalName(), builder.getName(), union.getLine());
+ final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(union, dependentModule,
+ ut.getQName().getLocalName(), builder.getName(), union.getLine());
- final TypeDefinitionBuilder newType = extendedTypeWithNewBaseType(targetTypeBuilder,
- targetTypeBuilder, extType, modules, builder);
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseTypeBuilder(targetTypeBuilder,
+ extType, modules, builder, union.getLine());
union.setTypedef(newType);
toRemove.add(extType);
unionTypes.removeAll(toRemove);
}
- private TypeDefinitionBuilder extendedTypeWithNewBaseType(final TypeAwareBuilder nodeToResolve,
- final TypeDefinitionBuilder newBaseType, final ExtendedType oldExtendedType,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
- final TypeConstraints constraints = findConstraints(nodeToResolve, new TypeConstraints(builder.getName(),
- nodeToResolve.getLine()), modules, builder);
- final TypeDefinitionBuilderImpl newType = new TypeDefinitionBuilderImpl(oldExtendedType.getQName(),
- nodeToResolve.getLine());
- newType.setTypedef(newBaseType);
- newType.setPath(oldExtendedType.getPath());
- newType.setDescription(oldExtendedType.getDescription());
- newType.setReference(oldExtendedType.getReference());
- newType.setStatus(oldExtendedType.getStatus());
- newType.setLengths(constraints.getLength());
- newType.setPatterns(constraints.getPatterns());
- newType.setRanges(constraints.getRange());
- newType.setFractionDigits(constraints.getFractionDigits());
- newType.setUnits(oldExtendedType.getUnits());
- newType.setDefaultValue(oldExtendedType.getDefaultValue());
- newType.setUnknownNodes(oldExtendedType.getUnknownSchemaNodes());
- return newType;
- }
-
- private TypeConstraints findConstraints(final TypeAwareBuilder nodeToResolve, final TypeConstraints constraints,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
-
- // union type cannot be restricted
- if (nodeToResolve instanceof UnionTypeBuilder) {
- return constraints;
- }
-
- if (nodeToResolve instanceof TypeDefinitionBuilder) {
- TypeDefinitionBuilder typedefToResolve = (TypeDefinitionBuilder) nodeToResolve;
- constraints.addFractionDigits(typedefToResolve.getFractionDigits());
- constraints.addLengths(typedefToResolve.getLengths());
- constraints.addPatterns(typedefToResolve.getPatterns());
- constraints.addRanges(typedefToResolve.getRanges());
- }
+ private void resolveTypeUnionWithContext(final UnionTypeBuilder union,
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder,
+ final SchemaContext context) {
- TypeDefinition<?> type = nodeToResolve.getType();
- if (type == null) {
- return findConstraints(nodeToResolve.getTypedef(), constraints, modules, builder);
- } else {
- if (type instanceof UnknownType) {
- ModuleBuilder dependentModule = findDependentModule(modules, builder, type.getQName().getPrefix(),
- nodeToResolve.getLine());
- TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve.getPath(), dependentModule, type
- .getQName().getLocalName(), builder.getName(), nodeToResolve.getLine());
- return findConstraints(tdb, constraints, modules, dependentModule);
- } else if (type instanceof ExtendedType) {
- ExtendedType extType = (ExtendedType) type;
- constraints.addFractionDigits(extType.getFractionDigits());
- constraints.addLengths(extType.getLengths());
- constraints.addPatterns(extType.getPatterns());
- constraints.addRanges(extType.getRanges());
-
- TypeDefinition<?> base = extType.getBaseType();
- if (base instanceof UnknownType) {
- ModuleBuilder dependentModule = findDependentModule(modules, builder, base.getQName().getPrefix(),
- nodeToResolve.getLine());
- TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve.getPath(), dependentModule,
- base.getQName().getLocalName(), builder.getName(), nodeToResolve.getLine());
- return findConstraints(tdb, constraints, modules, dependentModule);
+ final List<TypeDefinition<?>> unionTypes = union.getTypes();
+ final List<TypeDefinition<?>> toRemove = new ArrayList<TypeDefinition<?>>();
+ for (TypeDefinition<?> unionType : unionTypes) {
+ if (unionType instanceof UnknownType) {
+ final UnknownType ut = (UnknownType) unionType;
+ final QName utQName = ut.getQName();
+ final ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, builder,
+ utQName.getPrefix(), union.getLine());
+
+ if (dependentModuleBuilder == null) {
+ Module dependentModule = findModuleFromContext(context, builder, utQName.getPrefix(),
+ union.getLine());
+ Set<TypeDefinition<?>> types = dependentModule.getTypeDefinitions();
+ TypeDefinition<?> type = findTypeByName(types, utQName.getLocalName());
+ union.setType(type);
+ toRemove.add(ut);
} else {
- // it has to be base yang type
- mergeConstraints(type, constraints);
- return constraints;
+ final TypeDefinitionBuilder resolvedType = findTypeDefinitionBuilder(union, dependentModuleBuilder,
+ utQName.getLocalName(), builder.getName(), union.getLine());
+ union.setTypedef(resolvedType);
+ toRemove.add(ut);
+ }
+
+ } else if (unionType instanceof ExtendedType) {
+ final ExtendedType extType = (ExtendedType) unionType;
+ TypeDefinition<?> extTypeBase = extType.getBaseType();
+ if (extTypeBase instanceof UnknownType) {
+ final UnknownType ut = (UnknownType) extTypeBase;
+ final QName utQName = ut.getQName();
+ final ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, builder,
+ utQName.getPrefix(), union.getLine());
+
+ if (dependentModuleBuilder == null) {
+ final Module dependentModule = findModuleFromContext(context, builder, utQName.getPrefix(),
+ union.getLine());
+ Set<TypeDefinition<?>> types = dependentModule.getTypeDefinitions();
+ TypeDefinition<?> type = findTypeByName(types, utQName.getLocalName());
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseType(type, extType, builder, 0);
+
+ union.setTypedef(newType);
+ toRemove.add(extType);
+ } else {
+ final TypeDefinitionBuilder targetTypeBuilder = findTypeDefinitionBuilder(union,
+ dependentModuleBuilder, utQName.getLocalName(), builder.getName(), union.getLine());
+
+ final TypeDefinitionBuilder newType = extendedTypeWithNewBaseTypeBuilder(targetTypeBuilder,
+ extType, modules, builder, union.getLine());
+
+ union.setTypedef(newType);
+ toRemove.add(extType);
+ }
}
- } else {
- // it is base yang type
- mergeConstraints(type, constraints);
- return constraints;
}
}
+ unionTypes.removeAll(toRemove);
}
/**
- * Search for type definition builder by name.
+ * Go through all augment definitions and resolve them. It is expected that
+ * modules are already sorted by their dependencies. This method also finds
+ * augment target node and add child nodes to it.
*
- * @param dirtyNodeSchemaPath
- * schema path of node which contains unresolved type
- * @param dependentModule
- * module which should contains referenced type
- * @param typeName
- * name of type definition
- * @param currentModuleName
- * name of current module
- * @param line
- * current line in yang model
- * @return
+ * @param modules
+ * all available modules
*/
- private TypeDefinitionBuilder findTypeDefinitionBuilder(SchemaPath dirtyNodeSchemaPath,
- final ModuleBuilder dependentModule, final String typeName, final String currentModuleName, final int line) {
- final List<QName> path = dirtyNodeSchemaPath.getPath();
- TypeDefinitionBuilder result = null;
-
- Set<TypeDefinitionBuilder> typedefs = dependentModule.getModuleTypedefs();
- result = findTdb(typedefs, typeName);
-
- if (result == null) {
- Builder currentNode = null;
- final List<String> currentPath = new ArrayList<String>();
- currentPath.add(dependentModule.getName());
-
- for (int i = 0; i < path.size(); i++) {
- QName qname = path.get(i);
- currentPath.add(qname.getLocalName());
- currentNode = dependentModule.getModuleNode(currentPath);
-
- if (currentNode instanceof RpcDefinitionBuilder) {
- typedefs = ((RpcDefinitionBuilder) currentNode).getTypeDefinitions();
- } else if (currentNode instanceof DataNodeContainerBuilder) {
- typedefs = ((DataNodeContainerBuilder) currentNode).getTypeDefinitions();
- } else {
- typedefs = Collections.emptySet();
- }
-
- result = findTdb(typedefs, typeName);
- if (result != null) {
- break;
- }
+ private void resolveAugments(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+ final List<ModuleBuilder> allModulesList = new ArrayList<ModuleBuilder>();
+ final Set<ModuleBuilder> allModulesSet = new HashSet<ModuleBuilder>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ allModulesList.add(inner.getValue());
+ allModulesSet.add(inner.getValue());
}
}
- if (result != null) {
- return result;
- }
- throw new YangParseException(currentModuleName, line, "Referenced type '" + typeName + "' not found.");
- }
-
- private TypeDefinitionBuilder findTdb(Set<TypeDefinitionBuilder> types, String name) {
- for (TypeDefinitionBuilder td : types) {
- if (td.getQName().getLocalName().equals(name)) {
- return td;
+ for (int i = 0; i < allModulesList.size(); i++) {
+ final ModuleBuilder module = allModulesList.get(i);
+ // try to resolve augments in module
+ resolveAugment(modules, module);
+ // while all augments are not resolved
+ final Iterator<ModuleBuilder> allModulesIterator = allModulesSet.iterator();
+ while (!(module.getAugmentsResolved() == module.getAllAugments().size())) {
+ ModuleBuilder nextModule = null;
+ // try resolve other module augments
+ try {
+ nextModule = allModulesIterator.next();
+ resolveAugment(modules, nextModule);
+ } catch (NoSuchElementException e) {
+ throw new YangParseException("Failed to resolve augments in module '" + module.getName() + "'.", e);
+ }
+ // then try to resolve first module again
+ resolveAugment(modules, module);
}
}
- return null;
}
/**
- * Pull restriction from referenced type and add them to given constraints
+ * Tries to resolve augments in given module. If augment target node is not
+ * found, do nothing.
*
- * @param referencedType
- * @param constraints
+ * @param modules
+ * all available modules
+ * @param module
+ * current module
*/
- private void mergeConstraints(final TypeDefinition<?> referencedType, final TypeConstraints constraints) {
+ private void resolveAugment(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ if (module.getAugmentsResolved() < module.getAllAugments().size()) {
+ for (AugmentationSchemaBuilder augmentBuilder : module.getAllAugments()) {
+
+ if (!augmentBuilder.isResolved()) {
+ final SchemaPath augmentTargetSchemaPath = augmentBuilder.getTargetPath();
+ final List<QName> path = augmentTargetSchemaPath.getPath();
- if (referencedType instanceof DecimalTypeDefinition) {
- constraints.addRanges(((DecimalTypeDefinition) referencedType).getRangeStatements());
- constraints.addFractionDigits(((DecimalTypeDefinition) referencedType).getFractionDigits());
- } else if (referencedType instanceof IntegerTypeDefinition) {
- constraints.addRanges(((IntegerTypeDefinition) referencedType).getRangeStatements());
- } else if (referencedType instanceof StringTypeDefinition) {
- constraints.addPatterns(((StringTypeDefinition) referencedType).getPatterns());
- constraints.addLengths(((StringTypeDefinition) referencedType).getLengthStatements());
- } else if (referencedType instanceof BinaryTypeDefinition) {
- constraints.addLengths(((BinaryTypeDefinition) referencedType).getLengthConstraints());
+ final QName qname = path.get(0);
+ String prefix = qname.getPrefix();
+ if (prefix == null) {
+ prefix = module.getPrefix();
+ }
+
+ final ModuleBuilder dependentModule = findDependentModuleBuilder(modules, module, prefix,
+ augmentBuilder.getLine());
+ processAugmentation(augmentBuilder, path, module, dependentModule);
+ }
+
+ }
}
}
/**
- * Go through all augment definitions and resolve them. This method also
- * finds augment target node and add child nodes to it.
+ * Go through all augment definitions and resolve them. This method works in
+ * same way as {@link #resolveAugments(Map)} except that if target node is
+ * not found in loaded modules, it search for target node in given context.
*
* @param modules
- * all available modules
+ * all loaded modules
+ * @param context
+ * SchemaContext containing already resolved modules
*/
- private void resolveAugments(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveAugmentsWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final SchemaContext context) {
final List<ModuleBuilder> allModulesList = new ArrayList<ModuleBuilder>();
final Set<ModuleBuilder> allModulesSet = new HashSet<ModuleBuilder>();
for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (int i = 0; i < allModulesList.size(); i++) {
final ModuleBuilder module = allModulesList.get(i);
// try to resolve augments in module
- resolveAugment(modules, module);
+ resolveAugmentWithContext(modules, module, context);
// while all augments are not resolved
final Iterator<ModuleBuilder> allModulesIterator = allModulesSet.iterator();
- while (!(module.getAugmentsResolved() == module.getAugments().size())) {
+ while (!(module.getAugmentsResolved() == module.getAllAugments().size())) {
ModuleBuilder nextModule = null;
// try resolve other module augments
try {
nextModule = allModulesIterator.next();
- resolveAugment(modules, nextModule);
+ resolveAugmentWithContext(modules, nextModule, context);
} catch (NoSuchElementException e) {
throw new YangParseException("Failed to resolve augments in module '" + module.getName() + "'.", e);
}
// then try to resolve first module again
- resolveAugment(modules, module);
+ resolveAugmentWithContext(modules, module, context);
}
}
}
/**
+ * Tries to resolve augments in given module. If augment target node is not
+ * found, do nothing.
*
* @param modules
* all available modules
* @param module
* current module
*/
- private void resolveAugment(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- if (module.getAugmentsResolved() < module.getAugments().size()) {
- for (AugmentationSchemaBuilder augmentBuilder : module.getAugments()) {
+ private void resolveAugmentWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final SchemaContext context) {
+ if (module.getAugmentsResolved() < module.getAllAugments().size()) {
- if (!augmentBuilder.isResolved()) {
- final SchemaPath augmentTargetSchemaPath = augmentBuilder.getTargetPath();
- final List<QName> path = augmentTargetSchemaPath.getPath();
+ for (AugmentationSchemaBuilder augmentBuilder : module.getAllAugments()) {
+ final int line = augmentBuilder.getLine();
+ if (!augmentBuilder.isResolved()) {
+ final List<QName> path = augmentBuilder.getTargetPath().getPath();
final QName qname = path.get(0);
String prefix = qname.getPrefix();
if (prefix == null) {
prefix = module.getPrefix();
}
- DataSchemaNodeBuilder currentParent = null;
- final ModuleBuilder dependentModule = findDependentModule(modules, module, prefix,
- augmentBuilder.getLine());
- for (DataSchemaNodeBuilder child : dependentModule.getChildNodes()) {
- final QName childQName = child.getQName();
- if (childQName.getLocalName().equals(qname.getLocalName())) {
- currentParent = child;
- break;
- }
- }
-
- if (currentParent == null) {
+ // try to find augment target module in loaded modules...
+ final ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module, prefix,
+ line);
+ if (dependentModuleBuilder == null) {
+ // perform augmentation on module from context and
+ // continue to next augment
+ processAugmentationOnContext(augmentBuilder, path, module, prefix, line, context);
continue;
- }
-
- for (int i = 1; i < path.size(); i++) {
- final QName currentQName = path.get(i);
- DataSchemaNodeBuilder newParent = null;
- for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodes()) {
- final QName childQName = child.getQName();
- if (childQName.getLocalName().equals(currentQName.getLocalName())) {
- newParent = child;
- break;
- }
- }
- if (newParent == null) {
- break; // node not found, quit search
- } else {
- currentParent = newParent;
- }
- }
-
- final QName currentQName = currentParent.getQName();
- final QName lastAugmentPathElement = path.get(path.size() - 1);
- if (currentQName.getLocalName().equals(lastAugmentPathElement.getLocalName())) {
-
- if (currentParent instanceof ChoiceBuilder) {
- ParserUtils.fillAugmentTarget(augmentBuilder, (ChoiceBuilder) currentParent);
- } else {
- ParserUtils.fillAugmentTarget(augmentBuilder, (DataNodeContainerBuilder) currentParent);
- }
- ((AugmentationTargetBuilder) currentParent).addAugmentation(augmentBuilder);
- SchemaPath oldPath = currentParent.getPath();
- augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
- augmentBuilder.setResolved(true);
- module.augmentResolved();
+ } else {
+ processAugmentation(augmentBuilder, path, module, dependentModuleBuilder);
}
}
baseIdentityPrefix = module.getPrefix();
baseIdentityLocalName = baseIdentityName;
}
- final ModuleBuilder dependentModule = findDependentModule(modules, module, baseIdentityPrefix,
+ final ModuleBuilder dependentModule = findDependentModuleBuilder(modules, module, baseIdentityPrefix,
identity.getLine());
final Set<IdentitySchemaNodeBuilder> dependentModuleIdentities = dependentModule.getIdentities();
}
}
+ /**
+ * Go through identity statements defined in current module and resolve
+ * their 'base' statement. Method tries to find base identity in given
+ * modules. If base identity is not found, method will search it in context.
+ *
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ * @param context
+ * SchemaContext containing already resolved modules
+ */
+ private void resolveIdentitiesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final SchemaContext context) {
+ final Set<IdentitySchemaNodeBuilder> identities = module.getIdentities();
+ for (IdentitySchemaNodeBuilder identity : identities) {
+ final String baseIdentityName = identity.getBaseIdentityName();
+ if (baseIdentityName != null) {
+ String baseIdentityPrefix = null;
+ String baseIdentityLocalName = null;
+ if (baseIdentityName.contains(":")) {
+ final String[] splitted = baseIdentityName.split(":");
+ baseIdentityPrefix = splitted[0];
+ baseIdentityLocalName = splitted[1];
+ } else {
+ baseIdentityPrefix = module.getPrefix();
+ baseIdentityLocalName = baseIdentityName;
+ }
+ final ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module,
+ baseIdentityPrefix, identity.getLine());
+
+ if (dependentModuleBuilder == null) {
+ final Module dependentModule = findModuleFromContext(context, module, baseIdentityPrefix,
+ identity.getLine());
+ final Set<IdentitySchemaNode> dependentModuleIdentities = dependentModule.getIdentities();
+ for (IdentitySchemaNode idNode : dependentModuleIdentities) {
+ if (idNode.getQName().getLocalName().equals(baseIdentityLocalName)) {
+ identity.setBaseIdentity(idNode);
+ }
+ }
+ } else {
+ final Set<IdentitySchemaNodeBuilder> dependentModuleIdentities = dependentModuleBuilder
+ .getIdentities();
+ for (IdentitySchemaNodeBuilder idBuilder : dependentModuleIdentities) {
+ if (idBuilder.getQName().getLocalName().equals(baseIdentityLocalName)) {
+ identity.setBaseIdentity(idBuilder);
+ }
+ }
+ }
+ }
+ }
+ }
+
/**
* Go through uses statements defined in current module and resolve their
* refine statements.
* @param module
* module being resolved
*/
- private void resolveUsesRefines(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- final Map<List<String>, UsesNodeBuilder> moduleUses = module.getUsesNodes();
- for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses.entrySet()) {
- final UsesNodeBuilder usesNode = entry.getValue();
+ private void resolveUsesRefine(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ final List<UsesNodeBuilder> allModuleUses = module.getAllUsesNodes();
+ for (UsesNodeBuilder usesNode : allModuleUses) {
+ // refine
final int line = usesNode.getLine();
-
- GroupingBuilder targetGrouping = getTargetGrouping(usesNode, modules, module);
+ final GroupingBuilder targetGrouping = getTargetGroupingFromModules(usesNode, modules, module);
usesNode.setGroupingPath(targetGrouping.getPath());
-
for (RefineHolder refine : usesNode.getRefines()) {
- SchemaNodeBuilder refineTarget = getRefineNodeBuilderCopy(targetGrouping, refine, modules, module);
- ParserUtils.checkRefine(refineTarget, refine);
- ParserUtils.refineDefault(refineTarget, refine, line);
- if (refineTarget instanceof LeafSchemaNodeBuilder) {
- final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget;
- ParserUtils.refineLeaf(leaf, refine, line);
- usesNode.addRefineNode(leaf);
- } else if (refineTarget instanceof ContainerSchemaNodeBuilder) {
- final ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) refineTarget;
- ParserUtils.refineContainer(container, refine, line);
- usesNode.addRefineNode(container);
- } else if (refineTarget instanceof ListSchemaNodeBuilder) {
- final ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) refineTarget;
- ParserUtils.refineList(list, refine, line);
- usesNode.addRefineNode(list);
- } else if (refineTarget instanceof LeafListSchemaNodeBuilder) {
- final LeafListSchemaNodeBuilder leafList = (LeafListSchemaNodeBuilder) refineTarget;
- ParserUtils.refineLeafList(leafList, refine, line);
- usesNode.addRefineNode(leafList);
- } else if (refineTarget instanceof ChoiceBuilder) {
- final ChoiceBuilder choice = (ChoiceBuilder) refineTarget;
- ParserUtils.refineChoice(choice, refine, line);
- usesNode.addRefineNode(choice);
- } else if (refineTarget instanceof AnyXmlBuilder) {
- final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget;
- ParserUtils.refineAnyxml(anyXml, refine, line);
- usesNode.addRefineNode(anyXml);
- } else if (refineTarget instanceof GroupingBuilder) {
- usesNode.addRefineNode(refineTarget);
- } else if (refineTarget instanceof TypeDefinitionBuilder) {
- usesNode.addRefineNode(refineTarget);
+ final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(targetGrouping,
+ refine, module.getName());
+ if (nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember) nodeToRefine).setAddedByUses(true);
+ }
+ RefineUtils.performRefine(nodeToRefine, refine, line);
+ usesNode.addRefineNode(nodeToRefine);
+ }
+
+ // child nodes
+ processUsesNode(usesNode, targetGrouping);
+ }
+ }
+
+ /**
+ * Tries to search target grouping in given modules and resolve refine
+ * nodes. If grouping is not found in modules, method tries to find it in
+ * modules from context.
+ *
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ * @param context
+ * SchemaContext containing already resolved modules
+ */
+ private void resolveUsesRefineWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final SchemaContext context) {
+ final List<UsesNodeBuilder> moduleUses = module.getAllUsesNodes();
+ for (UsesNodeBuilder usesNode : moduleUses) {
+ final int line = usesNode.getLine();
+
+ final GroupingBuilder targetGroupingBuilder = getTargetGroupingFromModules(usesNode, modules, module);
+ if (targetGroupingBuilder == null) {
+ final GroupingDefinition targetGrouping = getTargetGroupingFromContext(usesNode, module, context);
+ usesNode.setGroupingPath(targetGrouping.getPath());
+ for (RefineHolder refine : usesNode.getRefines()) {
+ final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingDefinition(
+ targetGrouping, refine, module.getName());
+ if (nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember) nodeToRefine).setAddedByUses(true);
+ }
+ RefineUtils.performRefine(nodeToRefine, refine, line);
+ usesNode.addRefineNode(nodeToRefine);
+ }
+
+ processUsesNode(usesNode, targetGrouping);
+ } else {
+ usesNode.setGroupingPath(targetGroupingBuilder.getPath());
+ for (RefineHolder refine : usesNode.getRefines()) {
+ final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(
+ targetGroupingBuilder, refine, module.getName());
+ if (nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember) nodeToRefine).setAddedByUses(true);
+ }
+ RefineUtils.performRefine(nodeToRefine, refine, line);
+ usesNode.addRefineNode(nodeToRefine);
}
+
+ processUsesNode(usesNode, targetGroupingBuilder);
}
}
}
- private GroupingBuilder getTargetGrouping(final UsesNodeBuilder usesBuilder,
+ /**
+ * Search given modules for grouping by name defined in uses node.
+ *
+ * @param usesBuilder
+ * builder of uses statement
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ * @return grouping with given name if found, null otherwise
+ */
+ private GroupingBuilder getTargetGroupingFromModules(final UsesNodeBuilder usesBuilder,
final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
final int line = usesBuilder.getLine();
- String groupingString = usesBuilder.getGroupingName();
+ final String groupingString = usesBuilder.getGroupingName();
String groupingPrefix;
String groupingName;
if (groupingPrefix.equals(module.getPrefix())) {
dependentModule = module;
} else {
- dependentModule = findDependentModule(modules, module, groupingPrefix, line);
+ dependentModule = findDependentModuleBuilder(modules, module, groupingPrefix, line);
}
- List<QName> path = usesBuilder.getPath().getPath();
- GroupingBuilder result = null;
- Set<GroupingBuilder> groupings = dependentModule.getModuleGroupings();
- result = findGrouping(groupings, groupingName);
-
- if (result == null) {
- Builder currentNode = null;
- final List<String> currentPath = new ArrayList<String>();
- currentPath.add(dependentModule.getName());
-
- for (int i = 0; i < path.size(); i++) {
- QName qname = path.get(i);
- currentPath.add(qname.getLocalName());
- currentNode = dependentModule.getModuleNode(currentPath);
-
- if (currentNode instanceof RpcDefinitionBuilder) {
- groupings = ((RpcDefinitionBuilder) currentNode).getGroupings();
- } else if (currentNode instanceof DataNodeContainerBuilder) {
- groupings = ((DataNodeContainerBuilder) currentNode).getGroupings();
- } else {
- groupings = Collections.emptySet();
- }
-
- result = findGrouping(groupings, groupingName);
- if (result != null) {
- break;
- }
- }
+ if (dependentModule == null) {
+ return null;
}
+ GroupingBuilder result = null;
+ Set<GroupingBuilder> groupings = dependentModule.getGroupingBuilders();
+ result = findGroupingBuilder(groupings, groupingName);
if (result != null) {
return result;
}
- throw new YangParseException(module.getName(), line, "Referenced grouping '" + groupingName + "' not found.");
- }
- private GroupingBuilder findGrouping(Set<GroupingBuilder> groupings, String name) {
- for (GroupingBuilder grouping : groupings) {
- if (grouping.getQName().getLocalName().equals(name)) {
- return grouping;
+ Builder parent = usesBuilder.getParent();
+
+ while (parent != null) {
+ if (parent instanceof DataNodeContainerBuilder) {
+ groupings = ((DataNodeContainerBuilder) parent).getGroupingBuilders();
+ } else if (parent instanceof RpcDefinitionBuilder) {
+ groupings = ((RpcDefinitionBuilder) parent).getGroupings();
+ }
+ result = findGroupingBuilder(groupings, groupingName);
+ if (result == null) {
+ parent = parent.getParent();
+ } else {
+ break;
}
}
- return null;
+
+ if (result == null) {
+ throw new YangParseException(module.getName(), line, "Referenced grouping '" + groupingName
+ + "' not found.");
+ }
+ return result;
}
/**
- * Find original builder of node to refine and return copy of this builder.
- * <p>
- * We must create and use a copy of builder to preserve original builder
- * state, because this object will be refined (modified) and later added to
- * {@link UsesNodeBuilder}.
- * </p>
+ * Search context for grouping by name defined in uses node.
*
- * @param groupingPath
- * path to grouping which contains node to refine
- * @param refine
- * refine object containing informations about refine
- * @param modules
- * all loaded modules
+ * @param usesBuilder
+ * builder of uses statement
* @param module
* current module
- * @return copy of node to be refined if it is present in grouping, null
- * otherwise
+ * @param context
+ * SchemaContext containing already resolved modules
+ * @return grouping with given name if found, null otherwise
*/
- private SchemaNodeBuilder getRefineNodeBuilderCopy(final GroupingBuilder targetGrouping, final RefineHolder refine,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- Builder result = null;
- final Builder lookedUpBuilder = findRefineTargetBuilder(targetGrouping, refine, modules, module);
- if (lookedUpBuilder instanceof LeafSchemaNodeBuilder) {
- result = ParserUtils.copyLeafBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof ContainerSchemaNodeBuilder) {
- result = ParserUtils.copyContainerBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof ListSchemaNodeBuilder) {
- result = ParserUtils.copyListBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof LeafListSchemaNodeBuilder) {
- result = ParserUtils.copyLeafListBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof ChoiceBuilder) {
- result = ParserUtils.copyChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof AnyXmlBuilder) {
- result = ParserUtils.copyAnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof GroupingBuilder) {
- result = ParserUtils.copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
- } else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
- result = ParserUtils.copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
+ private GroupingDefinition getTargetGroupingFromContext(final UsesNodeBuilder usesBuilder,
+ final ModuleBuilder module, final SchemaContext context) {
+ final int line = usesBuilder.getLine();
+ String groupingString = usesBuilder.getGroupingName();
+ String groupingPrefix;
+ String groupingName;
+
+ if (groupingString.contains(":")) {
+ String[] splitted = groupingString.split(":");
+ if (splitted.length != 2 || groupingString.contains("/")) {
+ throw new YangParseException(module.getName(), line, "Invalid name of target grouping");
+ }
+ groupingPrefix = splitted[0];
+ groupingName = splitted[1];
} else {
- throw new YangParseException(module.getName(), refine.getLine(), "Target '" + refine.getName()
- + "' can not be refined");
+ groupingPrefix = module.getPrefix();
+ groupingName = groupingString;
}
- return (SchemaNodeBuilder) result;
+
+ Module dependentModule = findModuleFromContext(context, module, groupingPrefix, line);
+ return findGroupingDefinition(dependentModule.getGroupings(), groupingName);
}
/**
- * Find builder of refine node.
+ * Add nodes defined in target grouping to current context.
*
- * @param groupingPath
- * path to grouping which contains node to refine
- * @param refine
- * object containing refine information
- * @param modules
- * all loaded modules
- * @param module
- * current module
- * @return Builder object of refine node if it is present in grouping, null
- * otherwise
+ * @param usesNode
+ * @param targetGrouping
*/
- private Builder findRefineTargetBuilder(final GroupingBuilder builder, final RefineHolder refine,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- final String refineNodeName = refine.getName();
- Builder result = builder.getChildNode(refineNodeName);
- if (result == null) {
- Set<GroupingBuilder> grps = builder.getGroupings();
- for (GroupingBuilder gr : grps) {
- if (gr.getQName().getLocalName().equals(refineNodeName)) {
- result = gr;
- break;
- }
+ private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
+ List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+ DataNodeContainerBuilder parent = usesNode.getParent();
+ SchemaPath parentPath = parent.getPath();
+ for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if (refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder) refined);
+ continue;
+ }
+
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlBuilder) {
+ newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
+ } else if (child instanceof ChoiceBuilder) {
+ newChild = new ChoiceBuilder((ChoiceBuilder) child);
+ } else if (child instanceof ContainerSchemaNodeBuilder) {
+ newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
+ } else if (child instanceof LeafListSchemaNodeBuilder) {
+ newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
+ } else if (child instanceof LeafSchemaNodeBuilder) {
+ newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
+ } else if (child instanceof ListSchemaNodeBuilder) {
+ newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
}
+
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
}
- if (result == null) {
- Set<TypeDefinitionBuilder> typedefs = builder.getTypeDefinitions();
- for (TypeDefinitionBuilder typedef : typedefs) {
- if (typedef.getQName().getLocalName().equals(refineNodeName)) {
- result = typedef;
- break;
- }
+ for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
+ GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
+ newGrouping.setAddedByUses(true);
+ newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+ parent.addGrouping(newGrouping);
+ }
+ for (TypeDefinitionBuilder td : targetGrouping.getTypeDefinitionBuilders()) {
+ TypeDefinitionBuilder newType = new TypeDefinitionBuilderImpl(td);
+ newType.setAddedByUses(true);
+ newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+ parent.addTypedef(newType);
+ }
+ for (UsesNodeBuilder un : targetGrouping.getUses()) {
+ UsesNodeBuilder newUses = new UsesNodeBuilderImpl(un);
+ newUses.setAddedByUses(true);
+ // uses has not path
+ parent.addUsesNode(newUses);
+ }
+ for (UnknownSchemaNodeBuilder un : targetGrouping.getUnknownNodes()) {
+ UnknownSchemaNodeBuilder newUn = new UnknownSchemaNodeBuilder(un);
+ newUn.setAddedByUses(true);
+ newUn.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+ parent.addUnknownSchemaNode(newUn);
+ }
+ }
+
+ private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingDefinition targetGrouping) {
+ final int line = usesNode.getLine();
+ List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+ DataNodeContainerBuilder parent = usesNode.getParent();
+ SchemaPath parentPath = parent.getPath();
+ for (DataSchemaNode child : targetGrouping.getChildNodes()) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if (refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder) refined);
+ continue;
+ }
+
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlSchemaNode) {
+ newChild = createAnyXml((AnyXmlSchemaNode) child, line);
+ } else if (child instanceof ChoiceNode) {
+ newChild = createChoice((ChoiceNode) child, line);
+ } else if (child instanceof ContainerSchemaNode) {
+ newChild = createContainer((ContainerSchemaNode) child, line);
+ } else if (child instanceof LeafListSchemaNode) {
+ newChild = createLeafList((LeafListSchemaNode) child, line);
+ } else if (child instanceof LeafSchemaNode) {
+ newChild = createLeafBuilder((LeafSchemaNode) child, line);
+ } else if (child instanceof ListSchemaNode) {
+ newChild = createList((ListSchemaNode) child, line);
}
+
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
+ }
+ for (GroupingDefinition g : targetGrouping.getGroupings()) {
+ GroupingBuilder newGrouping = createGrouping(g, line);
+ newGrouping.setAddedByUses(true);
+ newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+ parent.addGrouping(newGrouping);
+ }
+ for (TypeDefinition<?> td : targetGrouping.getTypeDefinitions()) {
+ TypeDefinitionBuilder newType = createTypedef((ExtendedType) td, line);
+ newType.setAddedByUses(true);
+ newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+ parent.addTypedef(newType);
+ }
+ for (UsesNode un : targetGrouping.getUses()) {
+ if (un instanceof UsesNodeImpl) {
+ UsesNodeBuilder newUses = new UsesNodeBuilderImpl(((UsesNodeImpl) un).toBuilder());
+ newUses.setAddedByUses(true);
+ // uses has not path
+ parent.addUsesNode(newUses);
+ }
+ }
+ for (UnknownSchemaNode un : targetGrouping.getUnknownSchemaNodes()) {
+ UnknownSchemaNodeBuilder newNode = createUnknownSchemaNode(un, line);
+ newNode.setAddedByUses(true);
+ newNode.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+ parent.addUnknownSchemaNode(newNode);
}
- return result;
}
private QName findFullQName(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
}
String prefix = splittedBase[0];
String name = splittedBase[1];
- ModuleBuilder dependentModule = findDependentModule(modules, module, prefix, idref.getLine());
+ ModuleBuilder dependentModule = findDependentModuleBuilder(modules, module, prefix, idref.getLine());
result = new QName(dependentModule.getNamespace(), dependentModule.getRevision(), prefix, name);
} else {
result = new QName(module.getNamespace(), module.getRevision(), module.getPrefix(), baseString);
QName nodeType = usnb.getNodeType();
if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
try {
- ModuleBuilder dependentModule = findDependentModule(modules, module, nodeType.getPrefix(),
+ ModuleBuilder dependentModule = findDependentModuleBuilder(modules, module, nodeType.getPrefix(),
usnb.getLine());
QName newNodeType = new QName(dependentModule.getNamespace(), dependentModule.getRevision(),
nodeType.getPrefix(), nodeType.getLocalName());
}
}
- /**
- * Find dependent module based on given prefix
- *
- * @param modules
- * all available modules
- * @param module
- * current module
- * @param prefix
- * target module prefix
- * @param line
- * current line in yang model
- * @return
- */
- private ModuleBuilder findDependentModule(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder module, final String prefix, final int line) {
- ModuleBuilder dependentModule = null;
- Date dependentModuleRevision = null;
-
- if (prefix.equals(module.getPrefix())) {
- dependentModule = module;
- } else {
- final ModuleImport dependentModuleImport = ParserUtils.getModuleImport(module, prefix);
- if (dependentModuleImport == null) {
- throw new YangParseException(module.getName(), line, "No import found with prefix '" + prefix + "'.");
- }
- final String dependentModuleName = dependentModuleImport.getModuleName();
- dependentModuleRevision = dependentModuleImport.getRevision();
+ private void resolveUnknownNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, SchemaContext context) {
+ for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getUnknownNodes()) {
+ QName nodeType = unknownNodeBuilder.getNodeType();
+ if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
+ try {
+ ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module,
+ nodeType.getPrefix(), unknownNodeBuilder.getLine());
+
+ QName newNodeType = null;
+ if (dependentModuleBuilder == null) {
+ Module dependentModule = findModuleFromContext(context, module, nodeType.getPrefix(),
+ unknownNodeBuilder.getLine());
+ newNodeType = new QName(dependentModule.getNamespace(), dependentModule.getRevision(),
+ nodeType.getPrefix(), nodeType.getLocalName());
+ } else {
+ newNodeType = new QName(dependentModuleBuilder.getNamespace(),
+ dependentModuleBuilder.getRevision(), nodeType.getPrefix(), nodeType.getLocalName());
+ }
- final TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
- if (moduleBuildersByRevision == null) {
- throw new YangParseException(module.getName(), line, "Failed to find dependent module '"
- + dependentModuleName + "'.");
- }
- if (dependentModuleRevision == null) {
- dependentModule = moduleBuildersByRevision.lastEntry().getValue();
- } else {
- dependentModule = moduleBuildersByRevision.get(dependentModuleRevision);
+ unknownNodeBuilder.setNodeType(newNodeType);
+ } catch (YangParseException e) {
+ logger.debug(module.getName(), unknownNodeBuilder.getLine(), "Failed to find unknown node type: "
+ + nodeType);
+ }
}
}
-
- if (dependentModule == null) {
- throw new YangParseException(module.getName(), line, "Failed to find dependent module with prefix '"
- + prefix + "' and revision '" + dependentModuleRevision + "'.");
- }
- return dependentModule;
}
}
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Stack;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
-import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.util.YangTypesConverter;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
@Override
public void enterModule_stmt(YangParser.Module_stmtContext ctx) {
moduleName = stringFromNode(ctx);
+ logger.debug("enter module " + moduleName);
actualPath.push(moduleName);
moduleBuilder = new ModuleBuilder(moduleName);
@Override
public void exitModule_stmt(YangParser.Module_stmtContext ctx) {
- final String moduleName = actualPath.pop();
- logger.debug("Exiting module " + moduleName);
+ exitLog("module", actualPath.pop());
}
@Override
- public void enterModule_header_stmts(final Module_header_stmtsContext ctx) {
- super.enterModule_header_stmts(ctx);
-
+ public void enterModule_header_stmts(Module_header_stmtsContext ctx) {
+ enterLog("module_header", "", ctx.getStart().getLine());
String yangVersion = null;
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree treeNode = ctx.getChild(i);
final String namespaceStr = stringFromNode(treeNode);
namespace = URI.create(namespaceStr);
moduleBuilder.setNamespace(namespace);
+ setLog("namespace", namespaceStr);
} else if (treeNode instanceof Prefix_stmtContext) {
yangModelPrefix = stringFromNode(treeNode);
moduleBuilder.setPrefix(yangModelPrefix);
+ setLog("prefix", yangModelPrefix);
} else if (treeNode instanceof Yang_version_stmtContext) {
yangVersion = stringFromNode(treeNode);
+ setLog("yang-version", yangVersion);
}
}
moduleBuilder.setYangVersion(yangVersion);
}
+ @Override
+ public void exitModule_header_stmts(Module_header_stmtsContext ctx) {
+ exitLog("module_header", "");
+ }
+
@Override
public void enterMeta_stmts(YangParser.Meta_stmtsContext ctx) {
+ enterLog("meta_stmt", "", ctx.getStart().getLine());
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof Organization_stmtContext) {
final String organization = stringFromNode(child);
moduleBuilder.setOrganization(organization);
+ setLog("organization", organization);
} else if (child instanceof Contact_stmtContext) {
final String contact = stringFromNode(child);
moduleBuilder.setContact(contact);
+ setLog("contact", contact);
} else if (child instanceof Description_stmtContext) {
final String description = stringFromNode(child);
moduleBuilder.setDescription(description);
+ setLog("description", description);
} else if (child instanceof Reference_stmtContext) {
final String reference = stringFromNode(child);
moduleBuilder.setReference(reference);
+ setLog("reference", reference);
}
}
}
@Override
- public void exitSubmodule_header_stmts(YangParser.Submodule_header_stmtsContext ctx) {
- final String submodule = actualPath.pop();
- logger.debug("exiting submodule " + submodule);
+ public void exitMeta_stmts(YangParser.Meta_stmtsContext ctx) {
+ exitLog("meta_stmt", "");
}
@Override
public void enterRevision_stmts(Revision_stmtsContext ctx) {
+ enterLog("revisions", "", ctx.getStart().getLine());
if (ctx != null) {
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree treeNode = ctx.getChild(i);
}
}
+ @Override
+ public void exitRevision_stmts(Revision_stmtsContext ctx) {
+ exitLog("revisions", "");
+ }
+
private void updateRevisionForRevisionStatement(final ParseTree treeNode) {
final String revisionDateStr = stringFromNode(treeNode);
try {
if ((revision != null) && (this.revision.compareTo(revision) < 0)) {
this.revision = revision;
moduleBuilder.setRevision(this.revision);
+ setLog("revision", this.revision.toString());
for (int i = 0; i < treeNode.getChildCount(); ++i) {
ParseTree child = treeNode.getChild(i);
if (child instanceof Reference_stmtContext) {
@Override
public void enterImport_stmt(Import_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String importName = stringFromNode(ctx);
+ enterLog("import", importName, line);
+
String importPrefix = null;
Date importRevision = null;
try {
importRevision = simpleDateFormat.parse(importRevisionStr);
} catch (ParseException e) {
- logger.warn("Failed to parse import revision-date: " + importRevisionStr);
+ logger.warn("Failed to parse import revision-date at line " + line + ": " + importRevisionStr);
}
}
}
moduleBuilder.addModuleImport(importName, importRevision, importPrefix);
+ setLog("import", "(" + importName + "; " + importRevision + "; " + importPrefix + ")");
+ }
+
+ @Override
+ public void exitImport_stmt(Import_stmtContext ctx) {
+ exitLog("import", "");
}
@Override
public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String augmentPath = stringFromNode(ctx);
- AugmentationSchemaBuilder builder = moduleBuilder.addAugment(augmentPath, actualPath, ctx.getStart().getLine());
- moduleBuilder.enterNode(builder);
- updatePath(augmentPath);
+ enterLog("augment", augmentPath, line);
+
+ AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof Description_stmtContext) {
- String desc = stringFromNode(child);
- builder.setDescription(desc);
+ builder.setDescription(stringFromNode(child));
} else if (child instanceof Reference_stmtContext) {
- String ref = stringFromNode(child);
- builder.setReference(ref);
+ builder.setReference(stringFromNode(child));
} else if (child instanceof Status_stmtContext) {
- Status status = parseStatus((Status_stmtContext) child);
- builder.setStatus(status);
+ builder.setStatus(parseStatus((Status_stmtContext) child));
} else if (child instanceof When_stmtContext) {
- String when = stringFromNode(child);
- builder.addWhenCondition(when);
+ builder.addWhenCondition(stringFromNode(child));
}
}
+
+ moduleBuilder.enterNode(builder);
+ actualPath.push(augmentPath);
}
@Override
public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
- final String augment = actualPath.pop();
- logger.debug("exiting augment " + augment);
moduleBuilder.exitNode();
+ exitLog("augment", actualPath.pop());
}
@Override
public void enterExtension_stmt(YangParser.Extension_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String extName = stringFromNode(ctx);
+ enterLog("extension", extName, line);
+
QName qname = new QName(namespace, revision, yangModelPrefix, extName);
- ExtensionBuilder builder = moduleBuilder.addExtension(qname, ctx.getStart().getLine());
+ ExtensionBuilder builder = moduleBuilder.addExtension(qname, line);
parseSchemaNodeArgs(ctx, builder);
String argument = null;
}
builder.setArgument(argument);
builder.setYinElement(yin);
+
+ moduleBuilder.enterNode(builder);
+ actualPath.push(extName);
+ }
+
+ @Override
+ public void exitExtension_stmt(YangParser.Extension_stmtContext ctx) {
+ moduleBuilder.exitNode();
+ exitLog("extension", actualPath.pop());
}
@Override
public void enterTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String typedefName = stringFromNode(ctx);
+ enterLog("typedef", typedefName, line);
+
QName typedefQName = new QName(namespace, revision, yangModelPrefix, typedefName);
- TypeDefinitionBuilder builder = moduleBuilder.addTypedef(typedefQName, actualPath, ctx.getStart().getLine());
+ TypeDefinitionBuilder builder = moduleBuilder.addTypedef(line, typedefQName);
moduleBuilder.enterNode(builder);
- updatePath(typedefName);
+ actualPath.push(typedefName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
@Override
public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("typedef", actualPath.pop());
}
@Override
public void enterType_stmt(YangParser.Type_stmtContext ctx) {
- final String typeName = stringFromNode(ctx);
final int line = ctx.getStart().getLine();
+ final String typeName = stringFromNode(ctx);
+ enterLog("type", typeName, line);
+
final QName typeQName = parseQName(typeName);
TypeDefinition<?> type = null;
checkMissingBody(typeName, moduleName, line);
// if there are no constraints, just grab default base yang type
type = YangTypesConverter.javaTypeForBaseYangType(actualPath, namespace, revision, typeName);
- moduleBuilder.setType(type, actualPath);
+ moduleBuilder.setType(type);
} else {
if ("union".equals(typeName)) {
- List<String> typePath = new ArrayList<String>(actualPath);
- typePath.add(typeName);
- SchemaPath p = createActualSchemaPath(typePath, namespace, revision, yangModelPrefix);
+ SchemaPath p = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(actualPath, namespace, revision, line);
moduleBuilder.enterNode(unionBuilder);
unionBuilder.setPath(p);
} else if ("identityref".equals(typeName)) {
- SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix);
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path, line);
} else {
- type = parseTypeBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
+ type = parseTypeWithBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
yangModelPrefix, moduleBuilder.getActualNode());
- moduleBuilder.setType(type, actualPath);
+ moduleBuilder.setType(type);
}
}
} else {
- type = parseUnknownTypeBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
- moduleBuilder.getActualNode(), moduleBuilder);
- // mark parent node of this type statement as dirty
+ type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
+ moduleBuilder.getActualNode());
+ // add parent node of this type statement to dirty nodes
moduleBuilder.addDirtyNode(actualPath);
- moduleBuilder.setType(type, actualPath);
+ moduleBuilder.setType(type);
}
- updatePath(typeName);
+ actualPath.push(typeName);
}
private QName parseQName(String typeName) {
@Override
public void exitType_stmt(YangParser.Type_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
-
final String typeName = stringFromNode(ctx);
if ("union".equals(typeName)) {
moduleBuilder.exitNode();
}
+ exitLog("type", actualPath.pop());
}
@Override
public void enterGrouping_stmt(YangParser.Grouping_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String groupName = stringFromNode(ctx);
+ enterLog("grouping", groupName, line);
+
QName groupQName = new QName(namespace, revision, yangModelPrefix, groupName);
- GroupingBuilder builder = moduleBuilder.addGrouping(groupQName, actualPath, ctx.getStart().getLine());
+ GroupingBuilder builder = moduleBuilder.addGrouping(ctx.getStart().getLine(), groupQName);
moduleBuilder.enterNode(builder);
- updatePath(groupName);
+ actualPath.push(groupName);
+
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
}
@Override
public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) {
- String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("grouping", actualPath.pop());
}
@Override
public void enterContainer_stmt(Container_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String containerName = stringFromNode(ctx);
+ enterLog("container", containerName, line);
+
QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(containerQName, actualPath, ctx.getStart()
- .getLine());
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, containerName);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(line, containerQName, path);
moduleBuilder.enterNode(builder);
- updatePath(containerName);
+ actualPath.push(containerName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
@Override
public void exitContainer_stmt(Container_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("container", actualPath.pop());
}
@Override
public void enterLeaf_stmt(Leaf_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String leafName = stringFromNode(ctx);
+ enterLog("leaf", leafName, line);
+
QName leafQName = new QName(namespace, revision, yangModelPrefix, leafName);
- LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName, actualPath, ctx.getStart().getLine());
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafName);
+
+ LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(line, leafQName, schemaPath);
moduleBuilder.enterNode(builder);
- updatePath(leafName);
+ actualPath.push(leafName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
String defaultStr = null;
String unitsStr = null;
@Override
public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) {
- final String actLeaf = actualPath.pop();
- logger.debug("exiting " + actLeaf);
moduleBuilder.exitNode();
+ exitLog("leaf", actualPath.pop());
}
@Override
public void enterUses_stmt(YangParser.Uses_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String groupingPathStr = stringFromNode(ctx);
- UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr, actualPath, ctx.getStart().getLine());
+ enterLog("uses", groupingPathStr, line);
+
+ UsesNodeBuilder builder = moduleBuilder.addUsesNode(line, groupingPathStr);
moduleBuilder.enterNode(builder);
- updatePath(groupingPathStr);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
+ actualPath.push(groupingPathStr);
}
@Override
public void exitUses_stmt(YangParser.Uses_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("uses", actualPath.pop());
}
@Override
public void enterRefine_stmt(YangParser.Refine_stmtContext ctx) {
- String refineString = stringFromNode(ctx);
+ final String refineString = stringFromNode(ctx);
+ enterLog("refine", refineString, ctx.getStart().getLine());
+
RefineHolder refine = parseRefine(ctx);
moduleBuilder.addRefine(refine, actualPath);
moduleBuilder.enterNode(refine);
- updatePath(refineString);
+ actualPath.push(refineString);
}
@Override
public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("refine", actualPath.pop());
}
@Override
public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String leafListName = stringFromNode(ctx);
+ enterLog("leaf-list", leafListName, line);
+
QName leafListQName = new QName(namespace, revision, yangModelPrefix, leafListName);
- LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(leafListQName, actualPath, ctx.getStart()
- .getLine());
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafListName);
+
+ LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(line, leafListQName, schemaPath);
moduleBuilder.enterNode(builder);
- updatePath(leafListName);
+ actualPath.push(leafListName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
@Override
public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("leaf-list", actualPath.pop());
}
@Override
public void enterList_stmt(List_stmtContext ctx) {
- final String containerName = stringFromNode(ctx);
- QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
- ListSchemaNodeBuilder builder = moduleBuilder.addListNode(containerQName, actualPath, ctx.getStart().getLine());
+ final int line = ctx.getStart().getLine();
+ final String listName = stringFromNode(ctx);
+ enterLog("list", listName, line);
+
+ QName listQName = new QName(namespace, revision, yangModelPrefix, listName);
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, listName);
+
+ ListSchemaNodeBuilder builder = moduleBuilder.addListNode(line, listQName, schemaPath);
moduleBuilder.enterNode(builder);
- updatePath(containerName);
+ actualPath.push(listName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
String keyDefinition = "";
for (int i = 0; i < ctx.getChildCount(); ++i) {
@Override
public void exitList_stmt(List_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("list", actualPath.pop());
}
@Override
public void enterAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String anyXmlName = stringFromNode(ctx);
+ enterLog("anyxml", anyXmlName, line);
+
QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, anyXmlName);
- AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName, actualPath, ctx.getStart().getLine());
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, anyXmlName);
+
+ AnyXmlBuilder builder = moduleBuilder.addAnyXml(line, anyXmlQName, schemaPath);
moduleBuilder.enterNode(builder);
- updatePath(anyXmlName);
+ actualPath.push(anyXmlName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
}
@Override
public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("anyxml", actualPath.pop());
}
@Override
public void enterChoice_stmt(YangParser.Choice_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String choiceName = stringFromNode(ctx);
+ enterLog("choice", choiceName, line);
+
QName choiceQName = new QName(namespace, revision, yangModelPrefix, choiceName);
- ChoiceBuilder builder = moduleBuilder.addChoice(choiceQName, actualPath, ctx.getStart().getLine());
+
+ ChoiceBuilder builder = moduleBuilder.addChoice(line, choiceQName);
moduleBuilder.enterNode(builder);
+ actualPath.push(choiceName);
- updatePath(choiceName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
// set 'default' case
for (int i = 0; i < ctx.getChildCount(); i++) {
@Override
public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("choice", actualPath.pop());
}
@Override
public void enterCase_stmt(YangParser.Case_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String caseName = stringFromNode(ctx);
- QName choiceQName = new QName(namespace, revision, yangModelPrefix, caseName);
- ChoiceCaseBuilder builder = moduleBuilder.addCase(choiceQName, actualPath, ctx.getStart().getLine());
+ enterLog("case", caseName, line);
+
+ QName caseQName = new QName(namespace, revision, yangModelPrefix, caseName);
+ ChoiceCaseBuilder builder = moduleBuilder.addCase(line, caseQName);
moduleBuilder.enterNode(builder);
+ actualPath.push(caseName);
- updatePath(caseName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitCase_stmt(YangParser.Case_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("case", actualPath.pop());
}
@Override
public void enterNotification_stmt(YangParser.Notification_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String notificationName = stringFromNode(ctx);
+ enterLog("notification", notificationName, line);
+
QName notificationQName = new QName(namespace, revision, yangModelPrefix, notificationName);
- NotificationBuilder builder = moduleBuilder.addNotification(notificationQName, actualPath, ctx.getStart()
- .getLine());
+ NotificationBuilder builder = moduleBuilder.addNotification(notificationQName, actualPath, line);
moduleBuilder.enterNode(builder);
- updatePath(notificationName);
+ actualPath.push(notificationName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
@Override
public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("notification", actualPath.pop());
}
- // Unknown types
+ // Unknown nodes
@Override
public void enterIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String nodeParameter = stringFromNode(ctx);
+ enterLog("unknown-node", nodeParameter, line);
+
QName nodeType = null;
final String nodeTypeStr = ctx.getChild(0).getText();
qname = new QName(namespace, revision, yangModelPrefix, nodeParameter);
}
- UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(qname, actualPath, ctx.getStart()
- .getLine());
+ UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(qname, actualPath, line);
builder.setNodeType(nodeType);
builder.setNodeParameter(nodeParameter);
- updatePath(nodeParameter);
+ actualPath.push(nodeParameter);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
moduleBuilder.enterNode(builder);
@Override
public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("unknown-node", actualPath.pop());
}
@Override
public void enterRpc_stmt(YangParser.Rpc_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String rpcName = stringFromNode(ctx);
+ enterLog("rpc", rpcName, line);
+
QName rpcQName = new QName(namespace, revision, yangModelPrefix, rpcName);
- RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, actualPath, ctx.getStart().getLine());
+ RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(line, rpcQName);
moduleBuilder.enterNode(rpcBuilder);
- updatePath(rpcName);
+ actualPath.push(rpcName);
rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, rpcBuilder);
@Override
public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("rpc", actualPath.pop());
}
@Override
public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String input = "input";
+ enterLog(input, input, line);
+
QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(rpcQName, ctx.getStart().getLine());
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, input);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(path, rpcQName, line);
moduleBuilder.enterNode(builder);
- updatePath(input);
+ actualPath.push(input);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitInput_stmt(YangParser.Input_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("input", actualPath.pop());
}
@Override
public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String output = "output";
+ enterLog(output, output, line);
+
QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(rpcQName, ctx.getStart().getLine());
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, output);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(path, rpcQName, line);
moduleBuilder.enterNode(builder);
- updatePath(output);
+ actualPath.push(output);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitOutput_stmt(YangParser.Output_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("output", actualPath.pop());
}
@Override
public void enterFeature_stmt(YangParser.Feature_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String featureName = stringFromNode(ctx);
+ enterLog("feature", featureName, line);
+
QName featureQName = new QName(namespace, revision, yangModelPrefix, featureName);
- FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, actualPath, ctx.getStart().getLine());
+ FeatureBuilder featureBuilder = moduleBuilder.addFeature(line, featureQName);
moduleBuilder.enterNode(featureBuilder);
- updatePath(featureName);
+ actualPath.push(featureName);
featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, featureBuilder);
@Override
public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("feature", actualPath.pop());
}
@Override
public void enterDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String targetPath = stringFromNode(ctx);
+ enterLog("deviation", targetPath, line);
+
String reference = null;
String deviate = null;
- DeviationBuilder builder = moduleBuilder.addDeviation(targetPath, actualPath, ctx.getStart().getLine());
+ DeviationBuilder builder = moduleBuilder.addDeviation(targetPath, actualPath, line);
moduleBuilder.enterNode(builder);
- updatePath(targetPath);
+ actualPath.push(targetPath);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
@Override
public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
- }
-
- @Override
- public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
- boolean configuration = parseConfig(ctx);
- moduleBuilder.addConfiguration(configuration, actualPath, ctx.getStart().getLine());
+ exitLog("deviation", actualPath.pop());
}
@Override
public void enterIdentity_stmt(YangParser.Identity_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String identityName = stringFromNode(ctx);
+ enterLog("identity", identityName, line);
+
final QName identityQName = new QName(namespace, revision, yangModelPrefix, identityName);
- IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName, actualPath, ctx.getStart()
- .getLine());
+ IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName, actualPath, line);
moduleBuilder.enterNode(builder);
- updatePath(identityName);
+ actualPath.push(identityName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
@Override
public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) {
- final String actContainer = actualPath.pop();
- logger.debug("exiting " + actContainer);
moduleBuilder.exitNode();
+ exitLog("identity", actualPath.pop());
}
public ModuleBuilder getModuleBuilder() {
return moduleBuilder;
}
- private void updatePath(String containerName) {
- actualPath.push(containerName);
+ private void enterLog(String p1, String p2, int line) {
+ logger.debug("entering " + p1 + " " + p2 + " (" + line + ")");
+ }
+
+ private void exitLog(String p1, String p2) {
+ logger.debug("exiting " + p1 + " " + p2);
+ }
+
+ private void setLog(String p1, String p2) {
+ logger.debug("setting " + p1 + " " + p2);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.util;
+
+import java.util.Comparator;
+
+import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+
+public class Comparators {
+
+ public static final QNameComparator QNAME_COMP = new QNameComparator();
+ public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
+
+ private Comparators() {
+ }
+
+ private static final class QNameComparator implements Comparator<QName> {
+ @Override
+ public int compare(QName o1, QName o2) {
+ return o1.getLocalName().compareTo(o2.getLocalName());
+ }
+ }
+
+ private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
+ @Override
+ public int compare(SchemaNode o1, SchemaNode o2) {
+ return o1.getQName().getLocalName().compareTo(o2.getQName().getLocalName());
+ }
+ }
+
+}
*/
package org.opendaylight.controller.yang.parser.util;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.controller.yang.parser.impl.YangParserListenerImpl;
import org.opendaylight.controller.yang.parser.util.TopologicalSort.Node;
public final class ModuleDependencySort {
private static final Date DEFAULT_REVISION = new Date(0);
- private static final Logger logger = LoggerFactory
- .getLogger(ModuleDependencySort.class);
+ private static final Logger logger = LoggerFactory.getLogger(ModuleDependencySort.class);
/**
* Topological sort of module builder dependency graph.
});
}
+ public static List<ModuleBuilder> sortWithContext(SchemaContext context, ModuleBuilder... builders) {
+ List<Object> modules = new ArrayList<Object>();
+ Collections.addAll(modules, builders);
+ modules.addAll(context.getModules());
+
+ List<Node> sorted = sortInternal(modules);
+ // Cast to ModuleBuilder from Node if possible and return
+ return Lists.transform(sorted, new Function<Node, ModuleBuilder>() {
+
+ @Override
+ public ModuleBuilder apply(Node input) {
+ if (((ModuleNodeImpl) input).getReference() instanceof ModuleBuilder) {
+ return (ModuleBuilder) ((ModuleNodeImpl) input).getReference();
+ } else {
+ return null;
+ }
+ }
+ });
+ }
+
/**
* Topological sort of module dependency graph.
*
}
@VisibleForTesting
- static Map<String, Map<Date, ModuleNodeImpl>> createModuleGraph(
- List<?> builders) {
+ static Map<String, Map<Date, ModuleNodeImpl>> createModuleGraph(List<?> builders) {
Map<String, Map<Date, ModuleNodeImpl>> moduleGraph = Maps.newHashMap();
processModules(moduleGraph, builders);
/**
* Extract module:revision from module builders
*/
- private static void processDependencies(
- Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, List<?> builders) {
+ private static void processDependencies(Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, List<?> builders) {
Map<String, Date> imported = Maps.newHashMap();
// Create edges in graph
for (ModuleImport imprt : imports) {
String toName = imprt.getModuleName();
- Date toRevision = imprt.getRevision() == null ? DEFAULT_REVISION
- : imprt.getRevision();
+ Date toRevision = imprt.getRevision() == null ? DEFAULT_REVISION : imprt.getRevision();
- ModuleNodeImpl from = moduleGraph.get(fromName).get(
- fromRevision);
+ ModuleNodeImpl from = moduleGraph.get(fromName).get(fromRevision);
- ModuleNodeImpl to = getModuleByNameAndRevision(moduleGraph,
- fromName, fromRevision, toName, toRevision);
+ ModuleNodeImpl to = getModuleByNameAndRevision(moduleGraph, fromName, fromRevision, toName, toRevision);
/*
* Check imports: If module is imported twice with different
* revisions then throw exception
*/
- if (imported.get(toName) != null
- && !imported.get(toName).equals(toRevision))
- ex(String
- .format("Module:%s imported twice with different revisions:%s, %s",
- toName,
- formatRevDate(imported.get(toName)),
- formatRevDate(toRevision)));
+ if (imported.get(toName) != null && !imported.get(toName).equals(toRevision)) {
+ if (!imported.get(toName).equals(DEFAULT_REVISION) && !toRevision.equals(DEFAULT_REVISION)) {
+ ex(String.format("Module:%s imported twice with different revisions:%s, %s", toName,
+ formatRevDate(imported.get(toName)), formatRevDate(toRevision)));
+ }
+
+ }
+
imported.put(toName, toRevision);
from.addEdge(to);
/**
* Get imported module by its name and revision from moduleGraph
*/
- private static ModuleNodeImpl getModuleByNameAndRevision(
- Map<String, Map<Date, ModuleNodeImpl>> moduleGraph,
+ private static ModuleNodeImpl getModuleByNameAndRevision(Map<String, Map<Date, ModuleNodeImpl>> moduleGraph,
String fromName, Date fromRevision, String toName, Date toRevision) {
ModuleNodeImpl to = null;
- if (moduleGraph.get(toName) == null
- || !moduleGraph.get(toName).containsKey(toRevision)) {
+ if (moduleGraph.get(toName) == null || !moduleGraph.get(toName).containsKey(toRevision)) {
// If revision is not specified in import, but module exists
// with different revisions, take first
- if (moduleGraph.get(toName) != null
- && !moduleGraph.get(toName).isEmpty()
+ if (moduleGraph.get(toName) != null && !moduleGraph.get(toName).isEmpty()
&& toRevision.equals(DEFAULT_REVISION)) {
to = moduleGraph.get(toName).values().iterator().next();
logger.warn(String
.format("Import:%s:%s by module:%s:%s does not specify revision, using:%s:%s for module dependency sort",
- toName, formatRevDate(toRevision), fromName,
- formatRevDate(fromRevision), to.getName(),
+ toName, formatRevDate(toRevision), fromName, formatRevDate(fromRevision), to.getName(),
formatRevDate(to.getRevision())));
} else
- ex(String.format("Not existing module imported:%s:%s by:%s:%s",
- toName, formatRevDate(toRevision), fromName,
- formatRevDate(fromRevision)));
+ ex(String.format("Not existing module imported:%s:%s by:%s:%s", toName, formatRevDate(toRevision),
+ fromName, formatRevDate(fromRevision)));
} else {
to = moduleGraph.get(toName).get(toRevision);
}
* Extract dependencies from module builders or modules to fill dependency
* graph
*/
- private static void processModules(
- Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, List<?> builders) {
+ private static void processModules(Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, List<?> builders) {
// Process nodes
for (Object mb : builders) {
name = ((ModuleBuilder) mb).getName();
rev = ((ModuleBuilder) mb).getRevision();
} else {
- throw new IllegalStateException(
- String.format(
- "Unexpected type of node for sort, expected only:%s, %s, got:%s",
- Module.class, ModuleBuilder.class,
- mb.getClass()));
+ throw new IllegalStateException(String.format(
+ "Unexpected type of node for sort, expected only:%s, %s, got:%s", Module.class,
+ ModuleBuilder.class, mb.getClass()));
}
if (rev == null)
moduleGraph.put(name, Maps.<Date, ModuleNodeImpl> newHashMap());
if (moduleGraph.get(name).get(rev) != null)
- ex(String.format("Module:%s with revision:%s declared twice",
- name, formatRevDate(rev)));
+ ex(String.format("Module:%s with revision:%s declared twice", name, formatRevDate(rev)));
moduleGraph.get(name).put(rev, new ModuleNodeImpl(name, rev, mb));
}
}
private static String formatRevDate(Date rev) {
- return rev == DEFAULT_REVISION ? "default"
- : YangParserListenerImpl.simpleDateFormat.format(rev);
+ return rev == DEFAULT_REVISION ? "default" : YangParserListenerImpl.simpleDateFormat.format(rev);
}
@VisibleForTesting
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
return result;
}
@Override
public String toString() {
- return "Module [name=" + name + ", revision="
- + formatRevDate(revision) + "]";
+ return "Module [name=" + name + ", revision=" + formatRevDate(revision) + "]";
}
public Object getReference() {
*/
package org.opendaylight.controller.yang.parser.util;
-import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataNodeContainer;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.NotificationDefinition;
+import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.controller.yang.model.util.Int8;
import org.opendaylight.controller.yang.model.util.Leafref;
import org.opendaylight.controller.yang.model.util.StringType;
+import org.opendaylight.controller.yang.model.util.Uint16;
+import org.opendaylight.controller.yang.model.util.Uint32;
+import org.opendaylight.controller.yang.model.util.Uint64;
+import org.opendaylight.controller.yang.model.util.Uint8;
import org.opendaylight.controller.yang.model.util.UnionType;
+import org.opendaylight.controller.yang.model.util.UnknownType;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder.ChoiceNodeImpl;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder.ChoiceCaseNodeImpl;
import org.opendaylight.controller.yang.parser.builder.impl.ConstraintsBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder.ContainerSchemaNodeImpl;
import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder.ListSchemaNodeImpl;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.NotificationBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.NotificationBuilder.NotificationDefinitionImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
public final class ParserUtils {
private ParserUtils() {
}
+ /**
+ * Create new SchemaPath from given path and name.
+ *
+ * Append new qname to schema path created from name argument. New QName
+ * gets namespace, revision and prefix same as last qname in current schema
+ * path.
+ *
+ * @param schemaPath
+ * @param name
+ * @return
+ */
+ public static SchemaPath createSchemaPath(SchemaPath schemaPath, String name) {
+ List<QName> path = new ArrayList<QName>(schemaPath.getPath());
+ QName last = path.get(path.size() - 1);
+ QName newQName = new QName(last.getNamespace(), last.getRevision(), last.getPrefix(), name);
+ path.add(newQName);
+ return new SchemaPath(path, schemaPath.isAbsolute());
+ }
+
/**
* Get module import referenced by given prefix.
- *
+ *
* @param builder
* module to search
* @param prefix
* prefix associated with import
* @return ModuleImport based on given prefix
*/
- public static ModuleImport getModuleImport(final ModuleBuilder builder,
- final String prefix) {
+ public static ModuleImport getModuleImport(final ModuleBuilder builder, final String prefix) {
ModuleImport moduleImport = null;
for (ModuleImport mi : builder.getModuleImports()) {
if (mi.getPrefix().equals(prefix)) {
return moduleImport;
}
+ /**
+ * Find dependent module based on given prefix
+ *
+ * @param modules
+ * all available modules
+ * @param module
+ * current module
+ * @param prefix
+ * target module prefix
+ * @param line
+ * current line in yang model
+ * @return
+ */
+ public static ModuleBuilder findDependentModuleBuilder(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final String prefix, final int line) {
+ ModuleBuilder dependentModule = null;
+ Date dependentModuleRevision = null;
+
+ if (prefix.equals(module.getPrefix())) {
+ dependentModule = module;
+ } else {
+ final ModuleImport dependentModuleImport = getModuleImport(module, prefix);
+ if (dependentModuleImport == null) {
+ throw new YangParseException(module.getName(), line, "No import found with prefix '" + prefix + "'.");
+ }
+ final String dependentModuleName = dependentModuleImport.getModuleName();
+ dependentModuleRevision = dependentModuleImport.getRevision();
+
+ final TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
+ if (moduleBuildersByRevision == null) {
+ return null;
+ }
+ if (dependentModuleRevision == null) {
+ dependentModule = moduleBuildersByRevision.lastEntry().getValue();
+ } else {
+ dependentModule = moduleBuildersByRevision.get(dependentModuleRevision);
+ }
+ }
+ return dependentModule;
+ }
+
+ /**
+ * Find module from context based on prefix.
+ *
+ * @param context
+ * schema context
+ * @param currentModule
+ * current module
+ * @param prefix
+ * current prefix used to reference dependent module
+ * @param line
+ * current line in yang model
+ * @return module based on given prefix if found in context, null otherwise
+ */
+ public static Module findModuleFromContext(final SchemaContext context, final ModuleBuilder currentModule,
+ final String prefix, final int line) {
+ TreeMap<Date, Module> modulesByRevision = new TreeMap<Date, Module>();
+
+ Date dependentModuleRevision = null;
+
+ final ModuleImport dependentModuleImport = ParserUtils.getModuleImport(currentModule, prefix);
+ if (dependentModuleImport == null) {
+ throw new YangParseException(currentModule.getName(), line, "No import found with prefix '" + prefix + "'.");
+ }
+ final String dependentModuleName = dependentModuleImport.getModuleName();
+ dependentModuleRevision = dependentModuleImport.getRevision();
+
+ for (Module contextModule : context.getModules()) {
+ if (contextModule.getName().equals(dependentModuleName)) {
+ Date revision = contextModule.getRevision();
+ if (revision == null) {
+ revision = new Date(0L);
+ }
+ modulesByRevision.put(revision, contextModule);
+ break;
+ }
+ }
+
+ Module result = null;
+ if (dependentModuleRevision == null) {
+ result = modulesByRevision.get(modulesByRevision.firstKey());
+ } else {
+ result = modulesByRevision.get(dependentModuleRevision);
+ }
+
+ return result;
+ }
+
+ /**
+ * Find grouping by name.
+ *
+ * @param groupings
+ * collection of grouping builders to search
+ * @param name
+ * name of grouping
+ * @return grouping with given name if present in collection, null otherwise
+ */
+ public static GroupingBuilder findGroupingBuilder(Set<GroupingBuilder> groupings, String name) {
+ for (GroupingBuilder grouping : groupings) {
+ if (grouping.getQName().getLocalName().equals(name)) {
+ return grouping;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find grouping by name.
+ *
+ * @param groupings
+ * collection of grouping definitions to search
+ * @param name
+ * name of grouping
+ * @return grouping with given name if present in collection, null otherwise
+ */
+ public static GroupingDefinition findGroupingDefinition(Set<GroupingDefinition> groupings, String name) {
+ for (GroupingDefinition grouping : groupings) {
+ if (grouping.getQName().getLocalName().equals(name)) {
+ return grouping;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Search types for type with given name.
+ *
+ * @param types
+ * types to search
+ * @param name
+ * name of type
+ * @return type with given name if present in collection, null otherwise
+ */
+ public static TypeDefinitionBuilder findTypedefBuilderByName(Set<TypeDefinitionBuilder> types, String name) {
+ for (TypeDefinitionBuilder td : types) {
+ if (td.getQName().getLocalName().equals(name)) {
+ return td;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find type by name.
+ *
+ * @param types
+ * collection of types
+ * @param typeName
+ * type name
+ * @return type with given name if it is present in collection, null
+ * otherwise
+ */
+ public static TypeDefinition<?> findTypeByName(Set<TypeDefinition<?>> types, String typeName) {
+ for (TypeDefinition<?> type : types) {
+ if (type.getQName().getLocalName().equals(typeName)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
/**
* Parse uses path.
- *
+ *
* @param usesPath
* as String
* @return SchemaPath from given String
if (splittedElement.length == 1) {
name = new QName(null, null, null, splittedElement[0]);
} else {
- name = new QName(null, null, splittedElement[0],
- splittedElement[1]);
+ name = new QName(null, null, splittedElement[0], splittedElement[1]);
}
path.add(name);
}
return new SchemaPath(path, absolute);
}
+ /**
+ * Check if node is present in refine nodes.
+ *
+ * @param nodeQName
+ * qname of node
+ * @param refineNodes
+ * collections of refined nodes
+ * @return true, if node with given qname was found, false otherwise
+ */
+ public static SchemaNodeBuilder getRefined(QName nodeQName, List<SchemaNodeBuilder> refineNodes) {
+ for (SchemaNodeBuilder rn : refineNodes) {
+ if (rn.getQName().equals(nodeQName)) {
+ return rn;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Pull restriction from type and add them to constraints.
+ *
+ * @param type
+ * @param constraints
+ */
+ public static void mergeConstraints(final TypeDefinition<?> type, final TypeConstraints constraints) {
+ if (type instanceof DecimalTypeDefinition) {
+ constraints.addRanges(((DecimalTypeDefinition) type).getRangeStatements());
+ constraints.addFractionDigits(((DecimalTypeDefinition) type).getFractionDigits());
+ } else if (type instanceof IntegerTypeDefinition) {
+ constraints.addRanges(((IntegerTypeDefinition) type).getRangeStatements());
+ } else if (type instanceof StringTypeDefinition) {
+ constraints.addPatterns(((StringTypeDefinition) type).getPatterns());
+ constraints.addLengths(((StringTypeDefinition) type).getLengthStatements());
+ } else if (type instanceof BinaryTypeDefinition) {
+ constraints.addLengths(((BinaryTypeDefinition) type).getLengthConstraints());
+ }
+ }
+
+ /**
+ * Find node in grouping by name.
+ *
+ * @param grouping
+ * grouping to search
+ * @param refineNodeName
+ * name of node
+ * @return builder of node with given name if present in grouping, null
+ * otherwise
+ */
+ public static Builder findRefineTargetBuilder(final GroupingBuilder grouping, final String refineNodeName) {
+ // search child nodes
+ Builder result = grouping.getChildNode(refineNodeName);
+ // search groupings
+ if (result == null) {
+ Set<GroupingBuilder> grps = grouping.getGroupingBuilders();
+ for (GroupingBuilder gr : grps) {
+ if (gr.getQName().getLocalName().equals(refineNodeName)) {
+ result = gr;
+ break;
+ }
+ }
+ }
+ // search typedefs
+ if (result == null) {
+ Set<TypeDefinitionBuilder> typedefs = grouping.getTypeDefinitionBuilders();
+ for (TypeDefinitionBuilder typedef : typedefs) {
+ if (typedef.getQName().getLocalName().equals(refineNodeName)) {
+ result = typedef;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Find node in grouping by name.
+ *
+ * @param builder
+ * grouping to search
+ * @param refineNodeName
+ * name of node
+ * @return node with given name if present in grouping, null otherwise
+ */
+ public static Object findRefineTargetNode(final GroupingDefinition builder, final String refineNodeName) {
+ Object result = builder.getDataChildByName(refineNodeName);
+ if (result == null) {
+ Set<GroupingDefinition> grps = builder.getGroupings();
+ for (GroupingDefinition gr : grps) {
+ if (gr.getQName().getLocalName().equals(refineNodeName)) {
+ result = gr;
+ break;
+ }
+ }
+ }
+ if (result == null) {
+ Set<TypeDefinition<?>> typedefs = builder.getTypeDefinitions();
+ for (TypeDefinition<?> typedef : typedefs) {
+ if (typedef.getQName().getLocalName().equals(refineNodeName)) {
+ result = typedef;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
/**
* Add all augment's child nodes to given target.
- *
+ *
* @param augment
+ * builder of augment statement
* @param target
+ * augmentation target node
*/
- public static void fillAugmentTarget(
- final AugmentationSchemaBuilder augment,
- final DataNodeContainerBuilder target) {
- for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+ public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final DataNodeContainerBuilder target) {
+ boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+ for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
builder.setAugmenting(true);
+ if (usesAugment) {
+ if (builder instanceof GroupingMember) {
+ ((GroupingMember) builder).setAddedByUses(true);
+ }
+ }
correctAugmentChildPath(builder, target.getPath());
target.addChildNode(builder);
}
}
- public static void fillAugmentTarget(
- final AugmentationSchemaBuilder augment, final ChoiceBuilder target) {
- for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+ /**
+ * Add all augment's child nodes to given target.
+ *
+ * @param augment
+ * builder of augment statement
+ * @param target
+ * augmentation target choice node
+ */
+ public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final ChoiceBuilder target) {
+ boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+ for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
builder.setAugmenting(true);
+ if (usesAugment) {
+ if (builder instanceof GroupingMember) {
+ ((GroupingMember) builder).setAddedByUses(true);
+ }
+ }
correctAugmentChildPath(builder, target.getPath());
target.addChildNode(builder);
}
}
- private static void correctAugmentChildPath(
- final DataSchemaNodeBuilder childNode,
- final SchemaPath parentSchemaPath) {
-
+ private static void correctAugmentChildPath(final DataSchemaNodeBuilder childNode, final SchemaPath parentSchemaPath) {
// set correct path
- List<QName> targetNodePath = new ArrayList<QName>(
- parentSchemaPath.getPath());
+ List<QName> targetNodePath = new ArrayList<QName>(parentSchemaPath.getPath());
targetNodePath.add(childNode.getQName());
childNode.setPath(new SchemaPath(targetNodePath, true));
// set correct path for all child nodes
if (childNode instanceof DataNodeContainerBuilder) {
DataNodeContainerBuilder dataNodeContainer = (DataNodeContainerBuilder) childNode;
- for (DataSchemaNodeBuilder child : dataNodeContainer
- .getChildNodes()) {
+ for (DataSchemaNodeBuilder child : dataNodeContainer.getChildNodeBuilders()) {
correctAugmentChildPath(child, childNode.getPath());
}
}
+ // set correct path for all cases
+ if(childNode instanceof ChoiceBuilder) {
+ ChoiceBuilder choiceBuilder = (ChoiceBuilder) childNode;
+ for (ChoiceCaseBuilder choiceCaseBuilder : choiceBuilder.getCases()) {
+ correctAugmentChildPath(choiceCaseBuilder, childNode.getPath());
+ }
+ }
+
// if node can contains type, correct path for this type too
if (childNode instanceof TypeAwareBuilder) {
TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) childNode;
/**
* Repair schema path of node type.
- *
+ *
* @param node
* node which contains type statement
* @param parentSchemaPath
* schema path of parent node
*/
- private static void correctTypeAwareNodePath(
- TypeAwareBuilder node, SchemaPath parentSchemaPath) {
+ private static void correctTypeAwareNodePath(final TypeAwareBuilder node, final SchemaPath parentSchemaPath) {
final QName nodeBuilderQName = node.getQName();
final TypeDefinition<?> nodeType = node.getType();
if (nodeType != null) {
if (nodeType instanceof ExtendedType) {
ExtendedType et = (ExtendedType) nodeType;
- if (nodeType
- .getQName()
- .getLocalName()
- .equals(nodeType.getBaseType().getQName()
- .getLocalName())) {
+ if (nodeType.getQName().getLocalName().equals(nodeType.getBaseType().getQName().getLocalName())) {
fd = et.getFractionDigits();
lengths = et.getLengths();
patterns = et.getPatterns();
}
}
}
- TypeDefinition<?> newType = createCorrectTypeDefinition(
- parentSchemaPath, nodeBuilderQName, nodeType);
+ TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeBuilderQName, nodeType);
node.setType(newType);
} else {
TypeDefinitionBuilder nodeBuilderTypedef = node.getTypedef();
String tdbTypeName = nodeBuilderTypedef.getQName().getLocalName();
String baseTypeName = null;
if (nodeBuilderTypedef.getType() == null) {
- baseTypeName = nodeBuilderTypedef.getTypedef().getQName()
- .getLocalName();
+ baseTypeName = nodeBuilderTypedef.getTypedef().getQName().getLocalName();
} else {
- baseTypeName = nodeBuilderTypedef.getType().getQName()
- .getLocalName();
+ baseTypeName = nodeBuilderTypedef.getType().getQName().getLocalName();
}
if (!(tdbTypeName.equals(baseTypeName))) {
return;
return;
}
- SchemaPath newSchemaPath = createNewSchemaPath(
- nodeBuilderTypedef.getPath(), nodeBuilderQName,
+ SchemaPath newSchemaPath = createNewSchemaPath(nodeBuilderTypedef.getPath(), nodeBuilderQName,
nodeBuilderTypedef.getQName());
nodeBuilderTypedef.setPath(newSchemaPath);
}
/**
* Check if there are some constraints.
- *
+ *
* @param fd
* fraction digits
* @param lengths
* range constraints
* @return true, if any of constraints are present, false otherwise
*/
- private static boolean hasConstraints(final Integer fd,
- final List<LengthConstraint> lengths,
- final List<PatternConstraint> patterns,
- final List<RangeConstraint> ranges) {
- if (fd == null && (lengths == null || lengths.isEmpty())
- && (patterns == null || patterns.isEmpty())
+ private static boolean hasConstraints(final Integer fd, final List<LengthConstraint> lengths,
+ final List<PatternConstraint> patterns, final List<RangeConstraint> ranges) {
+ if (fd == null && (lengths == null || lengths.isEmpty()) && (patterns == null || patterns.isEmpty())
&& (ranges == null || ranges.isEmpty())) {
return false;
} else {
}
}
- private static TypeDefinition<?> createCorrectTypeDefinition(
- SchemaPath parentSchemaPath, QName nodeQName,
+ private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName,
TypeDefinition<?> nodeType) {
+ QName nodeTypeQName = nodeType.getQName();
+ SchemaPath newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeTypeQName);
TypeDefinition<?> result = null;
- SchemaPath newSchemaPath = null;
+
if (nodeType != null) {
if (nodeType instanceof BinaryTypeDefinition) {
BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, binType.getQName());
- List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+
+ // List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+ // workaround to get rid of 'Unchecked cast' warning
+ List<Byte> bytes = new ArrayList<Byte>();
+ Object defaultValue = binType.getDefaultValue();
+ if (defaultValue instanceof List) {
+ for (Object o : List.class.cast(defaultValue)) {
+ if (o instanceof Byte) {
+ bytes.add((Byte) o);
+ }
+ }
+ }
result = new BinaryType(newSchemaPath, bytes);
} else if (nodeType instanceof BitsTypeDefinition) {
BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, nodeType.getQName());
result = new BitsType(newSchemaPath, bitsType.getBits());
} else if (nodeType instanceof BooleanTypeDefinition) {
- BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, booleanType.getQName());
result = new BooleanType(newSchemaPath);
} else if (nodeType instanceof DecimalTypeDefinition) {
DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, decimalType.getQName());
- result = new Decimal64(newSchemaPath,
- decimalType.getFractionDigits());
+ result = new Decimal64(newSchemaPath, decimalType.getFractionDigits());
} else if (nodeType instanceof EmptyTypeDefinition) {
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, nodeType.getQName());
result = new EmptyType(newSchemaPath);
} else if (nodeType instanceof EnumTypeDefinition) {
EnumTypeDefinition enumType = (EnumTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, enumType.getQName());
- result = new EnumerationType(newSchemaPath,
- (EnumPair) enumType.getDefaultValue(),
- enumType.getValues());
+ result = new EnumerationType(newSchemaPath, (EnumPair) enumType.getDefaultValue(), enumType.getValues());
} else if (nodeType instanceof IdentityrefTypeDefinition) {
IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, idrefType.getQName());
- result = new IdentityrefType(idrefType.getIdentity(),
- newSchemaPath);
+ result = new IdentityrefType(idrefType.getIdentity(), newSchemaPath);
} else if (nodeType instanceof InstanceIdentifierTypeDefinition) {
InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, instIdType.getQName());
- return new InstanceIdentifier(newSchemaPath,
- instIdType.getPathStatement(),
+ return new InstanceIdentifier(newSchemaPath, instIdType.getPathStatement(),
instIdType.requireInstance());
} else if (nodeType instanceof StringTypeDefinition) {
- result = createNewStringType(parentSchemaPath, nodeQName,
- (StringTypeDefinition) nodeType);
+ result = createNewStringType(parentSchemaPath, nodeQName, (StringTypeDefinition) nodeType);
} else if (nodeType instanceof IntegerTypeDefinition) {
- result = createNewIntType(parentSchemaPath, nodeQName,
- (IntegerTypeDefinition) nodeType);
+ result = createNewIntType(parentSchemaPath, nodeQName, (IntegerTypeDefinition) nodeType);
} else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
- result = createNewUintType(parentSchemaPath, nodeQName,
- (UnsignedIntegerTypeDefinition) nodeType);
+ result = createNewUintType(parentSchemaPath, nodeQName, (UnsignedIntegerTypeDefinition) nodeType);
} else if (nodeType instanceof LeafrefTypeDefinition) {
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, nodeType.getQName());
- result = new Leafref(newSchemaPath,
- ((LeafrefTypeDefinition) nodeType).getPathStatement());
+ result = new Leafref(newSchemaPath, ((LeafrefTypeDefinition) nodeType).getPathStatement());
} else if (nodeType instanceof UnionTypeDefinition) {
UnionTypeDefinition unionType = (UnionTypeDefinition) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, unionType.getQName());
return new UnionType(newSchemaPath, unionType.getTypes());
} else if (nodeType instanceof ExtendedType) {
ExtendedType extType = (ExtendedType) nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath,
- nodeQName, extType.getQName());
- result = createNewExtendedType(newSchemaPath, extType);
+ result = createNewExtendedType(extType, newSchemaPath);
}
}
return result;
}
- private static TypeDefinition<?> createNewExtendedType(
- SchemaPath newSchemaPath, ExtendedType oldExtendedType) {
- QName qname = oldExtendedType.getQName();
- TypeDefinition<?> baseType = oldExtendedType.getBaseType();
- String desc = oldExtendedType.getDescription();
- String ref = oldExtendedType.getReference();
- ExtendedType.Builder builder = new ExtendedType.Builder(qname,
- baseType, desc, ref, newSchemaPath);
- builder.status(oldExtendedType.getStatus());
- builder.lengths(oldExtendedType.getLengths());
- builder.patterns(oldExtendedType.getPatterns());
- builder.ranges(oldExtendedType.getRanges());
- builder.fractionDigits(oldExtendedType.getFractionDigits());
- builder.unknownSchemaNodes(oldExtendedType.getUnknownSchemaNodes());
+ /**
+ * Create new ExtendedType based on given type and with schema path.
+ *
+ * @param newPath
+ * schema path for new type
+ * @param oldType
+ * type based
+ * @return
+ */
+ private static ExtendedType createNewExtendedType(final ExtendedType oldType, final SchemaPath newPath) {
+ QName qname = oldType.getQName();
+ TypeDefinition<?> baseType = oldType.getBaseType();
+ String desc = oldType.getDescription();
+ String ref = oldType.getReference();
+ ExtendedType.Builder builder = new ExtendedType.Builder(qname, baseType, desc, ref, newPath);
+ builder.status(oldType.getStatus());
+ builder.lengths(oldType.getLengths());
+ builder.patterns(oldType.getPatterns());
+ builder.ranges(oldType.getRanges());
+ builder.fractionDigits(oldType.getFractionDigits());
+ builder.unknownSchemaNodes(oldType.getUnknownSchemaNodes());
return builder.build();
}
- private static TypeDefinition<?> createNewStringType(SchemaPath schemaPath,
- QName nodeQName, StringTypeDefinition nodeType) {
- List<QName> path = schemaPath.getPath();
- List<QName> newPath = new ArrayList<QName>(path);
+ private static StringTypeDefinition createNewStringType(final SchemaPath schemaPath, final QName nodeQName,
+ final StringTypeDefinition nodeType) {
+ final List<QName> path = schemaPath.getPath();
+ final List<QName> newPath = new ArrayList<QName>(path);
newPath.add(nodeQName);
newPath.add(nodeType.getQName());
- SchemaPath newSchemaPath = new SchemaPath(newPath,
- schemaPath.isAbsolute());
-
+ final SchemaPath newSchemaPath = new SchemaPath(newPath, schemaPath.isAbsolute());
return new StringType(newSchemaPath);
}
- private static TypeDefinition<?> createNewIntType(SchemaPath schemaPath,
- QName nodeQName, IntegerTypeDefinition type) {
- QName typeQName = type.getQName();
- SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
- typeQName);
- String localName = typeQName.getLocalName();
+ private static IntegerTypeDefinition createNewIntType(final SchemaPath schemaPath, final QName nodeQName,
+ final IntegerTypeDefinition type) {
+ final QName typeQName = type.getQName();
+ final SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+ final String localName = typeQName.getLocalName();
if ("int8".equals(localName)) {
return new Int8(newSchemaPath);
}
}
- private static TypeDefinition<?> createNewUintType(SchemaPath schemaPath,
- QName nodeQName, UnsignedIntegerTypeDefinition type) {
- QName typeQName = type.getQName();
- SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
- typeQName);
- String localName = typeQName.getLocalName();
+ private static UnsignedIntegerTypeDefinition createNewUintType(final SchemaPath schemaPath, final QName nodeQName,
+ final UnsignedIntegerTypeDefinition type) {
+ final QName typeQName = type.getQName();
+ final SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+ final String localName = typeQName.getLocalName();
if ("uint8".equals(localName)) {
- return new Int8(newSchemaPath);
+ return new Uint8(newSchemaPath);
} else if ("uint16".equals(localName)) {
- return new Int16(newSchemaPath);
+ return new Uint16(newSchemaPath);
} else if ("uint32".equals(localName)) {
- return new Int32(newSchemaPath);
+ return new Uint32(newSchemaPath);
} else if ("uint64".equals(localName)) {
- return new Int64(newSchemaPath);
+ return new Uint64(newSchemaPath);
} else {
return null;
}
}
- private static SchemaPath createNewSchemaPath(SchemaPath schemaPath,
- QName currentQName, QName qname) {
+ private static SchemaPath createNewSchemaPath(final SchemaPath schemaPath, final QName currentQName,
+ final QName qname) {
List<QName> newPath = new ArrayList<QName>(schemaPath.getPath());
newPath.add(currentQName);
newPath.add(qname);
return new SchemaPath(newPath, schemaPath.isAbsolute());
}
- public static void refineLeaf(LeafSchemaNodeBuilder leaf,
- RefineHolder refine, int line) {
- String defaultStr = refine.getDefaultStr();
- Boolean mandatory = refine.isMandatory();
- MustDefinition must = refine.getMust();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+ /**
+ * Create LeafSchemaNodeBuilder from given LeafSchemaNode.
+ *
+ * @param leaf
+ * leaf from which to create builder
+ * @param line
+ * line in module
+ * @return builder object from leaf
+ */
+ public static LeafSchemaNodeBuilder createLeafBuilder(LeafSchemaNode leaf, int line) {
+ final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leaf.getQName(), leaf.getPath(), line);
+ convertDataSchemaNode(leaf, builder);
+ builder.setConfiguration(leaf.isConfiguration());
+ final TypeDefinition<?> type = leaf.getType();
+ builder.setType(type);
+ builder.setPath(leaf.getPath());
+ builder.setUnknownNodes(leaf.getUnknownSchemaNodes());
+ builder.setDefaultStr(leaf.getDefault());
+ builder.setUnits(leaf.getUnits());
+ return builder;
+ }
- if (defaultStr != null && !("".equals(defaultStr))) {
- leaf.setDefaultStr(defaultStr);
- }
- if (mandatory != null) {
- leaf.getConstraints().setMandatory(mandatory);
- }
- if (must != null) {
- leaf.getConstraints().addMustDefinition(must);
- }
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- leaf.addUnknownSchemaNode(unknown);
- }
- }
+ public static ContainerSchemaNodeBuilder createContainer(ContainerSchemaNode container, int line) {
+ final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(line, container.getQName(),
+ container.getPath());
+ convertDataSchemaNode(container, builder);
+ builder.setConfiguration(container.isConfiguration());
+ builder.setUnknownNodes(container.getUnknownSchemaNodes());
+ builder.setChildNodes(container.getChildNodes());
+ builder.setGroupings(container.getGroupings());
+ builder.setTypedefs(container.getTypeDefinitions());
+ builder.setAugmentations(container.getAvailableAugmentations());
+ builder.setUsesnodes(container.getUses());
+ builder.setPresence(container.isPresenceContainer());
+ return builder;
}
- public static void refineContainer(ContainerSchemaNodeBuilder container,
- RefineHolder refine, int line) {
- Boolean presence = refine.isPresence();
- MustDefinition must = refine.getMust();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+ public static ListSchemaNodeBuilder createList(ListSchemaNode list, int line) {
+ ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(line, list.getQName(), list.getPath());
+ convertDataSchemaNode(list, builder);
+ builder.setConfiguration(list.isConfiguration());
+ builder.setUnknownNodes(list.getUnknownSchemaNodes());
+ builder.setTypedefs(list.getTypeDefinitions());
+ builder.setChildNodes(list.getChildNodes());
+ builder.setGroupings(list.getGroupings());
+ builder.setAugmentations(list.getAvailableAugmentations());
+ builder.setUsesnodes(list.getUses());
+ builder.setUserOrdered(builder.isUserOrdered());
+ return builder;
+ }
- if (presence != null) {
- container.setPresence(presence);
- }
- if (must != null) {
- container.getConstraints().addMustDefinition(must);
- }
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- container.addUnknownSchemaNode(unknown);
- }
- }
+ public static LeafListSchemaNodeBuilder createLeafList(LeafListSchemaNode leafList, int line) {
+ final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(line, leafList.getQName(),
+ leafList.getPath());
+ convertDataSchemaNode(leafList, builder);
+ builder.setConfiguration(leafList.isConfiguration());
+ builder.setType(leafList.getType());
+ builder.setUnknownNodes(leafList.getUnknownSchemaNodes());
+ builder.setUserOrdered(leafList.isUserOrdered());
+ return builder;
}
- public static void refineList(ListSchemaNodeBuilder list,
- RefineHolder refine, int line) {
- MustDefinition must = refine.getMust();
- Integer min = refine.getMinElements();
- Integer max = refine.getMaxElements();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+ public static ChoiceBuilder createChoice(ChoiceNode choice, int line) {
+ final ChoiceBuilder builder = new ChoiceBuilder(line, choice.getQName());
+ convertDataSchemaNode(choice, builder);
+ builder.setConfiguration(choice.isConfiguration());
+ builder.setCases(choice.getCases());
+ builder.setUnknownNodes(choice.getUnknownSchemaNodes());
+ builder.setDefaultCase(choice.getDefaultCase());
+ return builder;
+ }
- if (must != null) {
- list.getConstraints().addMustDefinition(must);
- }
- if (min != null) {
- list.getConstraints().setMinElements(min);
- }
- if (max != null) {
- list.getConstraints().setMaxElements(max);
- }
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- list.addUnknownSchemaNode(unknown);
- }
- }
+ public static AnyXmlBuilder createAnyXml(AnyXmlSchemaNode anyxml, int line) {
+ final AnyXmlBuilder builder = new AnyXmlBuilder(line, anyxml.getQName(), anyxml.getPath());
+ convertDataSchemaNode(anyxml, builder);
+ builder.setConfiguration(anyxml.isConfiguration());
+ builder.setUnknownNodes(anyxml.getUnknownSchemaNodes());
+ return builder;
+ }
+
+ public static GroupingBuilder createGrouping(GroupingDefinition grouping, int line) {
+ final GroupingBuilderImpl builder = new GroupingBuilderImpl(grouping.getQName(), line);
+ builder.setPath(grouping.getPath());
+ builder.setChildNodes(grouping.getChildNodes());
+ builder.setGroupings(grouping.getGroupings());
+ builder.setTypedefs(grouping.getTypeDefinitions());
+ builder.setUsesnodes(grouping.getUses());
+ builder.setUnknownNodes(grouping.getUnknownSchemaNodes());
+ builder.setDescription(grouping.getDescription());
+ builder.setReference(grouping.getReference());
+ builder.setStatus(grouping.getStatus());
+ return builder;
+ }
+
+ public static TypeDefinitionBuilder createTypedef(ExtendedType typedef, int line) {
+ final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typedef.getQName(), line);
+ builder.setPath(typedef.getPath());
+ builder.setDefaultValue(typedef.getDefaultValue());
+ builder.setUnits(typedef.getUnits());
+ builder.setDescription(typedef.getDescription());
+ builder.setReference(typedef.getReference());
+ builder.setStatus(typedef.getStatus());
+ builder.setRanges(typedef.getRanges());
+ builder.setLengths(typedef.getLengths());
+ builder.setPatterns(typedef.getPatterns());
+ builder.setFractionDigits(typedef.getFractionDigits());
+ final TypeDefinition<?> type = typedef.getBaseType();
+ builder.setType(type);
+ builder.setUnits(typedef.getUnits());
+ builder.setUnknownNodes(typedef.getUnknownSchemaNodes());
+ return builder;
+ }
+
+ public static UnknownSchemaNodeBuilder createUnknownSchemaNode(UnknownSchemaNode unknownNode, int line) {
+ final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(line, unknownNode.getQName());
+ builder.setPath(unknownNode.getPath());
+ builder.setUnknownNodes(unknownNode.getUnknownSchemaNodes());
+ builder.setDescription(unknownNode.getDescription());
+ builder.setReference(unknownNode.getReference());
+ builder.setStatus(unknownNode.getStatus());
+ builder.setAddedByUses(unknownNode.isAddedByUses());
+ builder.setNodeType(unknownNode.getNodeType());
+ builder.setNodeParameter(unknownNode.getNodeParameter());
+ return builder;
}
- public static void refineLeafList(LeafListSchemaNodeBuilder leafList,
- RefineHolder refine, int line) {
- MustDefinition must = refine.getMust();
- Integer min = refine.getMinElements();
- Integer max = refine.getMaxElements();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+ /**
+ * Set DataSchemaNode arguments to builder object
+ *
+ * @param node
+ * node from which arguments should be read
+ * @param builder
+ * builder to which arguments should be set
+ */
+ private static void convertDataSchemaNode(DataSchemaNode node, DataSchemaNodeBuilder builder) {
+ builder.setPath(node.getPath());
+ builder.setDescription(node.getDescription());
+ builder.setReference(node.getReference());
+ builder.setStatus(node.getStatus());
+ builder.setAugmenting(node.isAugmenting());
+ copyConstraintsFromDefinition(node.getConstraints(), builder.getConstraints());
+ }
+
+ /**
+ * Copy constraints from constraints definition to constraints builder.
+ *
+ * @param nodeConstraints
+ * definition from which constraints will be copied
+ * @param constraints
+ * builder to which constraints will be added
+ */
+ private static void copyConstraintsFromDefinition(final ConstraintDefinition nodeConstraints,
+ final ConstraintsBuilder constraints) {
+ final RevisionAwareXPath when = nodeConstraints.getWhenCondition();
+ final Set<MustDefinition> must = nodeConstraints.getMustConstraints();
+ if (when != null) {
+ constraints.addWhenCondition(when.toString());
+ }
if (must != null) {
- leafList.getConstraints().addMustDefinition(must);
+ for (MustDefinition md : must) {
+ constraints.addMustDefinition(md);
+ }
}
- if (min != null) {
- leafList.getConstraints().setMinElements(min);
+ constraints.setMandatory(nodeConstraints.isMandatory());
+ constraints.setMinElements(nodeConstraints.getMinElements());
+ constraints.setMaxElements(nodeConstraints.getMaxElements());
+ }
+
+ public static void processAugmentationOnContext(final AugmentationSchemaBuilder augmentBuilder,
+ final List<QName> path, final ModuleBuilder module, final String prefix, final int line,
+ final SchemaContext context) {
+ final Module dependentModule = findModuleFromContext(context, module, prefix, line);
+ if (dependentModule == null) {
+ throw new YangParseException(module.getName(), line, "Failed to find referenced module with prefix "
+ + prefix + ".");
+ }
+ SchemaNode node = dependentModule.getDataChildByName(path.get(0).getLocalName());
+ if (node == null) {
+ Set<NotificationDefinition> notifications = dependentModule.getNotifications();
+ for (NotificationDefinition ntf : notifications) {
+ if (ntf.getQName().getLocalName().equals(path.get(0).getLocalName())) {
+ node = ntf;
+ break;
+ }
+ }
}
- if (max != null) {
- leafList.getConstraints().setMaxElements(max);
+ if (node == null) {
+ return;
}
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- leafList.addUnknownSchemaNode(unknown);
+
+ for (int i = 1; i < path.size(); i++) {
+ if (node instanceof DataNodeContainer) {
+ DataNodeContainer ref = (DataNodeContainer) node;
+ node = ref.getDataChildByName(path.get(i).getLocalName());
}
}
+ if (node == null) {
+ return;
+ }
+
+ if (node instanceof ContainerSchemaNodeImpl) {
+ // includes container, input and output statement
+ ContainerSchemaNodeImpl c = (ContainerSchemaNodeImpl) node;
+ ContainerSchemaNodeBuilder cb = c.toBuilder();
+ fillAugmentTarget(augmentBuilder, cb);
+ ((AugmentationTargetBuilder) cb).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = cb.getPath();
+ cb.rebuild();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
+ } else if (node instanceof ListSchemaNodeImpl) {
+ ListSchemaNodeImpl l = (ListSchemaNodeImpl) node;
+ ListSchemaNodeBuilder lb = l.toBuilder();
+ fillAugmentTarget(augmentBuilder, lb);
+ ((AugmentationTargetBuilder) lb).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = lb.getPath();
+ lb.rebuild();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
+ } else if (node instanceof ChoiceNodeImpl) {
+ ChoiceNodeImpl ch = (ChoiceNodeImpl) node;
+ ChoiceBuilder chb = ch.toBuilder();
+ fillAugmentTarget(augmentBuilder, chb);
+ ((AugmentationTargetBuilder) chb).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = chb.getPath();
+ chb.rebuild();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
+ } else if (node instanceof ChoiceCaseNodeImpl) {
+ ChoiceCaseNodeImpl chc = (ChoiceCaseNodeImpl) node;
+ ChoiceCaseBuilder chcb = chc.toBuilder();
+ fillAugmentTarget(augmentBuilder, chcb);
+ ((AugmentationTargetBuilder) chcb).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = chcb.getPath();
+ chcb.rebuild();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
+ } else if (node instanceof NotificationDefinitionImpl) {
+ NotificationDefinitionImpl nd = (NotificationDefinitionImpl) node;
+ NotificationBuilder nb = nd.toBuilder();
+ fillAugmentTarget(augmentBuilder, nb);
+ ((AugmentationTargetBuilder) nb).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = nb.getPath();
+ nb.rebuild();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
+ } else {
+ throw new YangParseException(module.getName(), line, "Target of type " + node.getClass()
+ + " can not be augmented.");
+ }
}
- public static void refineChoice(ChoiceBuilder choice, RefineHolder refine,
- int line) {
- String defaultStr = refine.getDefaultStr();
- Boolean mandatory = refine.isMandatory();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
-
- if (defaultStr != null) {
- choice.setDefaultCase(defaultStr);
+ public static void processAugmentation(final AugmentationSchemaBuilder augmentBuilder, final List<QName> path,
+ final ModuleBuilder module, final ModuleBuilder dependentModuleBuilder) {
+ DataSchemaNodeBuilder currentParent = null;
+ for (DataSchemaNodeBuilder child : dependentModuleBuilder.getChildNodeBuilders()) {
+ final QName childQName = child.getQName();
+ if (childQName.getLocalName().equals(path.get(0).getLocalName())) {
+ currentParent = child;
+ break;
+ }
}
- if (mandatory != null) {
- choice.getConstraints().setMandatory(mandatory);
+
+ if (currentParent == null) {
+ return;
}
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- choice.addUnknownSchemaNode(unknown);
+
+ for (int i = 1; i < path.size(); i++) {
+ final QName currentQName = path.get(i);
+ DataSchemaNodeBuilder newParent = null;
+ if (currentParent instanceof DataNodeContainerBuilder) {
+ for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodeBuilders()) {
+ final QName childQName = child.getQName();
+ if (childQName.getLocalName().equals(currentQName.getLocalName())) {
+ newParent = child;
+ break;
+ }
+ }
+ } else if (currentParent instanceof ChoiceBuilder) {
+ for (ChoiceCaseBuilder caseBuilder : ((ChoiceBuilder) currentParent).getCases()) {
+ final QName caseQName = caseBuilder.getQName();
+ if (caseQName.getLocalName().equals(currentQName.getLocalName())) {
+ newParent = caseBuilder;
+ break;
+ }
+ }
+ }
+
+ if (newParent == null) {
+ break; // node not found, quit search
+ } else {
+ currentParent = newParent;
}
}
- }
- public static void refineAnyxml(AnyXmlBuilder anyXml, RefineHolder refine,
- int line) {
- Boolean mandatory = refine.isMandatory();
- MustDefinition must = refine.getMust();
- List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+ final String currentName = currentParent.getQName().getLocalName();
+ final String lastAugmentPathElementName = path.get(path.size() - 1).getLocalName();
+ if (currentName.equals(lastAugmentPathElementName)) {
- if (mandatory != null) {
- anyXml.getConstraints().setMandatory(mandatory);
- }
- if (must != null) {
- anyXml.getConstraints().addMustDefinition(must);
- }
- if (unknownNodes != null) {
- for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
- anyXml.addUnknownSchemaNode(unknown);
- }
- }
- }
-
- public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
- String name = node.getQName().getLocalName();
- int line = refine.getLine();
-
- String defaultStr = refine.getDefaultStr();
- Boolean mandatory = refine.isMandatory();
- Boolean presence = refine.isPresence();
- MustDefinition must = refine.getMust();
- Integer min = refine.getMinElements();
- Integer max = refine.getMaxElements();
-
- if (node instanceof AnyXmlBuilder) {
- checkRefineDefault(node, defaultStr, line);
- checkRefinePresence(node, presence, line);
- checkRefineMinMax(name, line, min, max);
- } else if (node instanceof ChoiceBuilder) {
- checkRefinePresence(node, presence, line);
- checkRefineMust(node, must, line);
- checkRefineMinMax(name, line, min, max);
- } else if (node instanceof ContainerSchemaNodeBuilder) {
- checkRefineDefault(node, defaultStr, line);
- checkRefineMandatory(node, mandatory, line);
- checkRefineMust(node, must, line);
- checkRefineMinMax(name, line, min, max);
- } else if (node instanceof LeafSchemaNodeBuilder) {
- checkRefinePresence(node, presence, line);
- checkRefineMinMax(name, line, min, max);
- } else if (node instanceof LeafListSchemaNodeBuilder
- || node instanceof ListSchemaNodeBuilder) {
- checkRefineDefault(node, defaultStr, line);
- checkRefinePresence(node, presence, line);
- checkRefineMandatory(node, mandatory, line);
- } else if (node instanceof GroupingBuilder
- || node instanceof TypeDefinitionBuilder
- || node instanceof UsesNodeBuilder) {
- checkRefineDefault(node, defaultStr, line);
- checkRefinePresence(node, presence, line);
- checkRefineMandatory(node, mandatory, line);
- checkRefineMust(node, must, line);
- checkRefineMinMax(name, line, min, max);
- }
- }
-
- private static void checkRefineDefault(SchemaNodeBuilder node,
- String defaultStr, int line) {
- if (defaultStr != null) {
- throw new YangParseException(line, "Can not refine 'default' for '"
- + node.getQName().getLocalName() + "'.");
- }
- }
-
- private static void checkRefineMandatory(SchemaNodeBuilder node,
- Boolean mandatory, int line) {
- if (mandatory != null) {
- throw new YangParseException(line,
- "Can not refine 'mandatory' for '"
- + node.getQName().getLocalName() + "'.");
- }
- }
-
- private static void checkRefinePresence(SchemaNodeBuilder node,
- Boolean presence, int line) {
- if (presence != null) {
- throw new YangParseException(line,
- "Can not refine 'presence' for '"
- + node.getQName().getLocalName() + "'.");
- }
- }
-
- private static void checkRefineMust(SchemaNodeBuilder node,
- MustDefinition must, int line) {
- if (must != null) {
- throw new YangParseException(line, "Can not refine 'must' for '"
- + node.getQName().getLocalName() + "'.");
+ if (currentParent instanceof ChoiceBuilder) {
+ fillAugmentTarget(augmentBuilder, (ChoiceBuilder) currentParent);
+ } else {
+ fillAugmentTarget(augmentBuilder, (DataNodeContainerBuilder) currentParent);
+ }
+ ((AugmentationTargetBuilder) currentParent).addAugmentation(augmentBuilder);
+ SchemaPath oldPath = currentParent.getPath();
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setResolved(true);
+ module.augmentResolved();
}
}
- private static void checkRefineMinMax(String refineTargetName,
- int refineLine, Integer min, Integer max) {
- if (min != null || max != null) {
- throw new YangParseException(refineLine,
- "Can not refine 'min-elements' or 'max-elements' for '"
- + refineTargetName + "'.");
- }
+ /**
+ * Create new type builder based on old type with new base type.
+ *
+ * @param newBaseType
+ * new base type builder
+ * @param oldExtendedType
+ * old type
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
+ * @param line
+ * current line in module
+ * @return new type builder based on old type with new base type
+ */
+ public static TypeDefinitionBuilder extendedTypeWithNewBaseTypeBuilder(final TypeDefinitionBuilder newBaseType,
+ final ExtendedType oldExtendedType, final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final int line) {
+ final TypeConstraints tc = new TypeConstraints(module.getName(), line);
+ tc.addFractionDigits(oldExtendedType.getFractionDigits());
+ tc.addLengths(oldExtendedType.getLengths());
+ tc.addPatterns(oldExtendedType.getPatterns());
+ tc.addRanges(oldExtendedType.getRanges());
+
+ final TypeConstraints constraints = findConstraintsFromTypeBuilder(newBaseType, tc, modules, module, null);
+ final TypeDefinitionBuilderImpl newType = new TypeDefinitionBuilderImpl(oldExtendedType.getQName(), line);
+ newType.setTypedef(newBaseType);
+ newType.setPath(oldExtendedType.getPath());
+ newType.setDescription(oldExtendedType.getDescription());
+ newType.setReference(oldExtendedType.getReference());
+ newType.setStatus(oldExtendedType.getStatus());
+ newType.setLengths(constraints.getLength());
+ newType.setPatterns(constraints.getPatterns());
+ newType.setRanges(constraints.getRange());
+ newType.setFractionDigits(constraints.getFractionDigits());
+ newType.setUnits(oldExtendedType.getUnits());
+ newType.setDefaultValue(oldExtendedType.getDefaultValue());
+ newType.setUnknownNodes(oldExtendedType.getUnknownSchemaNodes());
+ return newType;
}
/**
- * Perform refine operation of following parameters:
- * <ul>
- * <li>description</li>
- * <li>reference</li>
- * <li>config</li>
- * </ul>
- *
- * These parameters may be refined for any node.
- *
- * @param node
- * node to refine
- * @param refine
- * refine holder containing values to refine
+ * Create new type builder based on old type with new base type.
+ *
+ * @param newBaseType
+ * new base type
+ * @param oldExtendedType
+ * old type
+ * @param modules
+ * all loaded modules
+ * @param module
+ * current module
* @param line
- * current line in yang model
+ * current line in module
+ * @return new type builder based on old type with new base type
*/
- public static void refineDefault(Builder node, RefineHolder refine, int line) {
- Class<? extends Builder> cls = node.getClass();
+ public static TypeDefinitionBuilder extendedTypeWithNewBaseType(final TypeDefinition<?> newBaseType,
+ final ExtendedType oldExtendedType, final ModuleBuilder module, final int line) {
+ final TypeConstraints tc = new TypeConstraints(module.getName(), line);
+
+ final TypeConstraints constraints = findConstraintsFromTypeDefinition(newBaseType, tc);
+ final TypeDefinitionBuilderImpl newType = new TypeDefinitionBuilderImpl(oldExtendedType.getQName(), line);
+ newType.setType(newBaseType);
+ newType.setPath(oldExtendedType.getPath());
+ newType.setDescription(oldExtendedType.getDescription());
+ newType.setReference(oldExtendedType.getReference());
+ newType.setStatus(oldExtendedType.getStatus());
+ newType.setLengths(constraints.getLength());
+ newType.setPatterns(constraints.getPatterns());
+ newType.setRanges(constraints.getRange());
+ newType.setFractionDigits(constraints.getFractionDigits());
+ newType.setUnits(oldExtendedType.getUnits());
+ newType.setDefaultValue(oldExtendedType.getDefaultValue());
+ newType.setUnknownNodes(oldExtendedType.getUnknownSchemaNodes());
+ return newType;
+ }
- String description = refine.getDescription();
- if (description != null) {
- try {
- Method method = cls.getDeclaredMethod("setDescription",
- String.class);
- method.invoke(node, description);
- } catch (Exception e) {
- throw new YangParseException(line,
- "Cannot refine description in " + cls.getName(), e);
- }
+ /**
+ * Pull restrictions from type and add them to constraints.
+ *
+ * @param typeToResolve
+ * type from which constraints will be read
+ * @param constraints
+ * constraints object to which constraints will be added
+ * @return constraints contstraints object containing constraints from given
+ * type
+ */
+ private static TypeConstraints findConstraintsFromTypeDefinition(final TypeDefinition<?> typeToResolve,
+ final TypeConstraints constraints) {
+ // union type cannot be restricted
+ if (typeToResolve instanceof UnionTypeDefinition) {
+ return constraints;
+ }
+ if (typeToResolve instanceof ExtendedType) {
+ ExtendedType extType = (ExtendedType) typeToResolve;
+ constraints.addFractionDigits(extType.getFractionDigits());
+ constraints.addLengths(extType.getLengths());
+ constraints.addPatterns(extType.getPatterns());
+ constraints.addRanges(extType.getRanges());
+ return findConstraintsFromTypeDefinition(extType.getBaseType(), constraints);
+ } else {
+ mergeConstraints(typeToResolve, constraints);
+ return constraints;
}
+ }
- String reference = refine.getReference();
- if (reference != null) {
- try {
- Method method = cls.getDeclaredMethod("setReference",
- String.class);
- method.invoke(node, reference);
- } catch (Exception e) {
- throw new YangParseException(line,
- "Cannot refine reference in " + cls.getName(), e);
- }
- }
+ public static TypeConstraints findConstraintsFromTypeBuilder(final TypeAwareBuilder nodeToResolve,
+ final TypeConstraints constraints, final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder builder, final SchemaContext context) {
- Boolean config = refine.isConfig();
- if (config != null) {
- try {
- Method method = cls.getDeclaredMethod("setConfiguration",
- Boolean.TYPE);
- method.invoke(node, config);
- } catch (Exception e) {
- throw new YangParseException(line, "Cannot refine config in "
- + cls.getName(), e);
- }
+ // union type cannot be restricted
+ if (nodeToResolve instanceof UnionTypeBuilder) {
+ return constraints;
}
- }
- public static LeafSchemaNodeBuilder copyLeafBuilder(
- final LeafSchemaNodeBuilder old) {
- final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(
- old.getQName(), old.getLine());
- final TypeDefinition<?> type = old.getType();
+ if (nodeToResolve instanceof TypeDefinitionBuilder) {
+ TypeDefinitionBuilder typedefToResolve = (TypeDefinitionBuilder) nodeToResolve;
+ constraints.addFractionDigits(typedefToResolve.getFractionDigits());
+ constraints.addLengths(typedefToResolve.getLengths());
+ constraints.addPatterns(typedefToResolve.getPatterns());
+ constraints.addRanges(typedefToResolve.getRanges());
+ }
+ TypeDefinition<?> type = nodeToResolve.getType();
if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(type);
- }
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setDefaultStr(old.getDefaultStr());
- copy.setUnits(old.getUnits());
- return copy;
- }
-
- public static ContainerSchemaNodeBuilder copyContainerBuilder(
- final ContainerSchemaNodeBuilder old) {
- final ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setPresence(old.isPresence());
- return copy;
- }
-
- public static ListSchemaNodeBuilder copyListBuilder(
- final ListSchemaNodeBuilder old) {
- final ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static LeafListSchemaNodeBuilder copyLeafListBuilder(
- final LeafListSchemaNodeBuilder old) {
- final LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- final TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
+ return findConstraintsFromTypeBuilder(nodeToResolve.getTypedef(), constraints, modules, builder, context);
} else {
- copy.setType(type);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static ChoiceBuilder copyChoiceBuilder(final ChoiceBuilder old) {
- final ChoiceBuilder copy = new ChoiceBuilder(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (ChoiceCaseBuilder caseBuilder : old.getCases()) {
- copy.addChildNode(caseBuilder);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDefaultCase(old.getDefaultCase());
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- return copy;
- }
-
- public static AnyXmlBuilder copyAnyXmlBuilder(final AnyXmlBuilder old) {
- final AnyXmlBuilder copy = new AnyXmlBuilder(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setConfiguration(old.isConfiguration());
- return copy;
- }
-
- public static GroupingBuilder copyGroupingBuilder(final GroupingBuilder old) {
- final GroupingBuilder copy = new GroupingBuilderImpl(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (UsesNodeBuilder use : old.getUses()) {
- copy.addUsesNode(use);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- return copy;
- }
-
- public static TypeDefinitionBuilderImpl copyTypedefBuilder(
- TypeDefinitionBuilderImpl old) {
- final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copy.setDefaultValue(old.getDefaultValue());
- copy.setUnits(old.getUnits());
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
-
- copy.setRanges(old.getRanges());
- copy.setLengths(old.getLengths());
- copy.setPatterns(old.getPatterns());
- copy.setFractionDigits(old.getFractionDigits());
-
- TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(old.getType());
- }
- copy.setUnits(old.getUnits());
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
+ QName qname = type.getQName();
+ if (type instanceof UnknownType) {
+ ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, builder, qname.getPrefix(),
+ nodeToResolve.getLine());
+ if (dependentModuleBuilder == null) {
+ if (context == null) {
+ throw new YangParseException(builder.getName(), nodeToResolve.getLine(),
+ "Failed to resolved type constraints.");
+ }
+ Module dm = findModuleFromContext(context, builder, qname.getPrefix(), nodeToResolve.getLine());
+ TypeDefinition<?> t = findTypeByName(dm.getTypeDefinitions(), qname.getLocalName());
+ if (t instanceof ExtendedType) {
+ ExtendedType extType = (ExtendedType) t;
+ constraints.addFractionDigits(extType.getFractionDigits());
+ constraints.addLengths(extType.getLengths());
+ constraints.addPatterns(extType.getPatterns());
+ constraints.addRanges(extType.getRanges());
+ return constraints;
+ } else {
+ mergeConstraints(t, constraints);
+ return constraints;
+ }
+ } else {
+ TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve, dependentModuleBuilder,
+ qname.getLocalName(), builder.getName(), nodeToResolve.getLine());
+ return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModuleBuilder, context);
+ }
+ } else if (type instanceof ExtendedType) {
+ ExtendedType extType = (ExtendedType) type;
+ constraints.addFractionDigits(extType.getFractionDigits());
+ constraints.addLengths(extType.getLengths());
+ constraints.addPatterns(extType.getPatterns());
+ constraints.addRanges(extType.getRanges());
+
+ TypeDefinition<?> base = extType.getBaseType();
+ if (base instanceof UnknownType) {
+ ModuleBuilder dependentModule = findDependentModuleBuilder(modules, builder, base.getQName()
+ .getPrefix(), nodeToResolve.getLine());
+ TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve, dependentModule, base
+ .getQName().getLocalName(), builder.getName(), nodeToResolve.getLine());
+ return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModule, context);
+ } else {
+ // it has to be base yang type
+ mergeConstraints(type, constraints);
+ return constraints;
+ }
+ } else {
+ // it is base yang type
+ mergeConstraints(type, constraints);
+ return constraints;
+ }
}
- return copy;
}
- public static UsesNodeBuilder copyUsesNodeBuilder(UsesNodeBuilder old) {
- final UsesNodeBuilder copy = new UsesNodeBuilderImpl(
- old.getGroupingName(), old.getLine());
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugment(augment);
+ /**
+ * Search for type definition builder by name.
+ *
+ * @param dirtyNodeSchemaPath
+ * schema path of node which contains unresolved type
+ * @param dependentModule
+ * module which should contains referenced type
+ * @param typeName
+ * name of type definition
+ * @param currentModuleName
+ * name of current module
+ * @param line
+ * current line in yang model
+ * @return
+ */
+ public static TypeDefinitionBuilder findTypeDefinitionBuilder(final TypeAwareBuilder nodeToResolve,
+ final ModuleBuilder dependentModule, final String typeName, final String currentModuleName, final int line) {
+
+ TypeDefinitionBuilder result = null;
+
+ Set<TypeDefinitionBuilder> typedefs = dependentModule.getTypeDefinitionBuilders();
+ result = findTypedefBuilderByName(typedefs, typeName);
+ if (result != null) {
+ return result;
}
- copy.setAugmenting(old.isAugmenting());
- for (SchemaNodeBuilder refineNode : old.getRefineNodes()) {
- copy.addRefineNode(refineNode);
+
+ Builder parent = nodeToResolve.getParent();
+ while (parent != null) {
+ if (parent instanceof DataNodeContainerBuilder) {
+ typedefs = ((DataNodeContainerBuilder) parent).getTypeDefinitionBuilders();
+ } else if (parent instanceof RpcDefinitionBuilder) {
+ typedefs = ((RpcDefinitionBuilder) parent).getTypeDefinitions();
+ }
+ result = findTypedefBuilderByName(typedefs, typeName);
+ if (result == null) {
+ parent = parent.getParent();
+ } else {
+ break;
+ }
}
- return copy;
- }
- private static void copyConstraints(final DataSchemaNodeBuilder oldBuilder,
- final DataSchemaNodeBuilder newBuilder) {
- final ConstraintsBuilder oldConstraints = oldBuilder.getConstraints();
- final ConstraintsBuilder newConstraints = newBuilder.getConstraints();
- newConstraints.addWhenCondition(oldConstraints.getWhenCondition());
- for (MustDefinition must : oldConstraints.getMustDefinitions()) {
- newConstraints.addMustDefinition(must);
+ if (result == null) {
+ throw new YangParseException(currentModuleName, line, "Referenced type '" + typeName + "' not found.");
}
- newConstraints.setMandatory(oldConstraints.isMandatory());
- newConstraints.setMinElements(oldConstraints.getMinElements());
- newConstraints.setMaxElements(oldConstraints.getMaxElements());
+ return result;
}
}
import org.opendaylight.controller.yang.model.api.MustDefinition;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-public final class RefineHolder implements Builder {
- private final String name;
+public final class RefineHolder implements Builder, ConfigNode {
+ private Builder parent;
private final int line;
+ private final String name;
private String defaultStr;
private String description;
private String reference;
private Integer maxElements;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- public RefineHolder(final String name, final int line) {
+ public RefineHolder(final int line, final String name) {
this.name = name;
this.line = line;
}
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(final Builder parent) {
+ this.parent = parent;
+ }
+
public String getDefaultStr() {
return defaultStr;
}
this.reference = reference;
}
- public Boolean isConfig() {
+ @Override
+ public Boolean isConfiguration() {
return config;
}
- public void setConfig(final Boolean config) {
+ @Override
+ public void setConfiguration(final Boolean config) {
this.config = config;
}
return null;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((addedUnknownNodes == null) ? 0 : addedUnknownNodes.hashCode());
+ result = prime * result + ((config == null) ? 0 : config.hashCode());
+ result = prime * result + ((defaultStr == null) ? 0 : defaultStr.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((mandatory == null) ? 0 : mandatory.hashCode());
+ result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
+ result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
+ result = prime * result + ((must == null) ? 0 : must.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ result = prime * result + ((presence == null) ? 0 : presence.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RefineHolder other = (RefineHolder) obj;
+ if (addedUnknownNodes == null) {
+ if (other.addedUnknownNodes != null)
+ return false;
+ } else if (!addedUnknownNodes.equals(other.addedUnknownNodes))
+ return false;
+ if (config == null) {
+ if (other.config != null)
+ return false;
+ } else if (!config.equals(other.config))
+ return false;
+ if (defaultStr == null) {
+ if (other.defaultStr != null)
+ return false;
+ } else if (!defaultStr.equals(other.defaultStr))
+ return false;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (mandatory == null) {
+ if (other.mandatory != null)
+ return false;
+ } else if (!mandatory.equals(other.mandatory))
+ return false;
+ if (maxElements == null) {
+ if (other.maxElements != null)
+ return false;
+ } else if (!maxElements.equals(other.maxElements))
+ return false;
+ if (minElements == null) {
+ if (other.minElements != null)
+ return false;
+ } else if (!minElements.equals(other.minElements))
+ return false;
+ if (must == null) {
+ if (other.must != null)
+ return false;
+ } else if (!must.equals(other.must))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (parent == null) {
+ if (other.parent != null)
+ return false;
+ } else if (!parent.equals(other.parent))
+ return false;
+ if (presence == null) {
+ if (other.presence != null)
+ return false;
+ } else if (!presence.equals(other.presence))
+ return false;
+ if (reference == null) {
+ if (other.reference != null)
+ return false;
+ } else if (!reference.equals(other.reference))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "revine " + name;
+ }
+
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.util;
+
+import static org.opendaylight.controller.yang.parser.util.ParserUtils.*;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
+/**
+ * Utility class with helper methods to perform operations tied to refine
+ * process.
+ */
+public class RefineUtils {
+
+ private RefineUtils() {
+ }
+
+ /**
+ * Find original builder of node to refine and return copy of this builder.
+ * <p>
+ * We must create and use a copy of builder to preserve original builder
+ * state, because this object will be refined (modified) and later added to
+ * {@link UsesNodeBuilder}.
+ * </p>
+ *
+ * @param targetGrouping
+ * builder of grouping which should contains node to refine
+ * @param refine
+ * refine object containing informations about refine
+ * @param moduleName
+ * current module name
+ * @return
+ */
+ public static SchemaNodeBuilder getRefineNodeFromGroupingBuilder(final GroupingBuilder targetGrouping,
+ final RefineHolder refine, final String moduleName) {
+ Builder result = null;
+ final Builder lookedUpBuilder = findRefineTargetBuilder(targetGrouping, refine.getName());
+ if (lookedUpBuilder instanceof LeafSchemaNodeBuilder) {
+ result = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof ContainerSchemaNodeBuilder) {
+ result = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof ListSchemaNodeBuilder) {
+ result = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof LeafListSchemaNodeBuilder) {
+ result = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof ChoiceBuilder) {
+ result = new ChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof AnyXmlBuilder) {
+ result = new AnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof GroupingBuilder) {
+ result = new GroupingBuilderImpl((GroupingBuilder) lookedUpBuilder);
+ } else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
+ result = new TypeDefinitionBuilderImpl((TypeDefinitionBuilder) lookedUpBuilder);
+ } else {
+ throw new YangParseException(moduleName, refine.getLine(), "Target '" + refine.getName()
+ + "' can not be refined");
+ }
+ return (SchemaNodeBuilder) result;
+ }
+
+ /**
+ * Create builder object from refine target node.
+ *
+ * @param grouping
+ * grouping which should contains node to refine
+ * @param refine
+ * refine object containing informations about refine
+ * @param moduleName
+ * current module name
+ * @return
+ */
+ public static SchemaNodeBuilder getRefineNodeFromGroupingDefinition(final GroupingDefinition grouping,
+ final RefineHolder refine, final String moduleName) {
+ SchemaNodeBuilder result = null;
+ final int line = refine.getLine();
+ final Object lookedUpNode = findRefineTargetNode(grouping, refine.getName());
+ if (lookedUpNode instanceof LeafSchemaNode) {
+ result = createLeafBuilder((LeafSchemaNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof ContainerSchemaNode) {
+ result = createContainer((ContainerSchemaNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof ListSchemaNode) {
+ result = createList((ListSchemaNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof LeafListSchemaNode) {
+ result = createLeafList((LeafListSchemaNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof ChoiceNode) {
+ result = createChoice((ChoiceNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof AnyXmlSchemaNode) {
+ result = createAnyXml((AnyXmlSchemaNode) lookedUpNode, line);
+ } else if (lookedUpNode instanceof GroupingDefinition) {
+ result = createGrouping((GroupingDefinition) lookedUpNode, line);
+ } else if (lookedUpNode instanceof TypeDefinition) {
+ result = createTypedef((ExtendedType) lookedUpNode, line);
+ } else {
+ throw new YangParseException(moduleName, line, "Target '" + refine.getName() + "' can not be refined");
+ }
+ return result;
+ }
+
+ public static void refineLeaf(LeafSchemaNodeBuilder leaf, RefineHolder refine, int line) {
+ String defaultStr = refine.getDefaultStr();
+ Boolean mandatory = refine.isMandatory();
+ MustDefinition must = refine.getMust();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (defaultStr != null && !("".equals(defaultStr))) {
+ leaf.setDefaultStr(defaultStr);
+ }
+ if (mandatory != null) {
+ leaf.getConstraints().setMandatory(mandatory);
+ }
+ if (must != null) {
+ leaf.getConstraints().addMustDefinition(must);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ leaf.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ public static void refineContainer(ContainerSchemaNodeBuilder container, RefineHolder refine, int line) {
+ Boolean presence = refine.isPresence();
+ MustDefinition must = refine.getMust();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (presence != null) {
+ container.setPresence(presence);
+ }
+ if (must != null) {
+ container.getConstraints().addMustDefinition(must);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ container.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ public static void refineList(ListSchemaNodeBuilder list, RefineHolder refine, int line) {
+ MustDefinition must = refine.getMust();
+ Integer min = refine.getMinElements();
+ Integer max = refine.getMaxElements();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (must != null) {
+ list.getConstraints().addMustDefinition(must);
+ }
+ if (min != null) {
+ list.getConstraints().setMinElements(min);
+ }
+ if (max != null) {
+ list.getConstraints().setMaxElements(max);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ list.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ public static void refineLeafList(LeafListSchemaNodeBuilder leafList, RefineHolder refine, int line) {
+ MustDefinition must = refine.getMust();
+ Integer min = refine.getMinElements();
+ Integer max = refine.getMaxElements();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (must != null) {
+ leafList.getConstraints().addMustDefinition(must);
+ }
+ if (min != null) {
+ leafList.getConstraints().setMinElements(min);
+ }
+ if (max != null) {
+ leafList.getConstraints().setMaxElements(max);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ leafList.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ public static void refineChoice(ChoiceBuilder choice, RefineHolder refine, int line) {
+ String defaultStr = refine.getDefaultStr();
+ Boolean mandatory = refine.isMandatory();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (defaultStr != null) {
+ choice.setDefaultCase(defaultStr);
+ }
+ if (mandatory != null) {
+ choice.getConstraints().setMandatory(mandatory);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ choice.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ public static void refineAnyxml(AnyXmlBuilder anyXml, RefineHolder refine, int line) {
+ Boolean mandatory = refine.isMandatory();
+ MustDefinition must = refine.getMust();
+ List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodes();
+
+ if (mandatory != null) {
+ anyXml.getConstraints().setMandatory(mandatory);
+ }
+ if (must != null) {
+ anyXml.getConstraints().addMustDefinition(must);
+ }
+ if (unknownNodes != null) {
+ for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+ anyXml.addUnknownSchemaNode(unknown);
+ }
+ }
+ }
+
+ /**
+ * Check if refine can be performed on given node.
+ *
+ * @param node
+ * node to refine
+ * @param refine
+ * refine object containing information about refine process
+ */
+ public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
+ String name = node.getQName().getLocalName();
+ int line = refine.getLine();
+
+ String defaultStr = refine.getDefaultStr();
+ Boolean mandatory = refine.isMandatory();
+ Boolean presence = refine.isPresence();
+ MustDefinition must = refine.getMust();
+ Integer min = refine.getMinElements();
+ Integer max = refine.getMaxElements();
+
+ if (node instanceof AnyXmlBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof ChoiceBuilder) {
+ checkRefinePresence(node, presence, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof ContainerSchemaNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefineMandatory(node, mandatory, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof LeafSchemaNodeBuilder) {
+ checkRefinePresence(node, presence, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof LeafListSchemaNodeBuilder || node instanceof ListSchemaNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMandatory(node, mandatory, line);
+ } else if (node instanceof GroupingBuilder || node instanceof TypeDefinitionBuilder
+ || node instanceof UsesNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMandatory(node, mandatory, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ }
+ }
+
+ private static void checkRefineDefault(SchemaNodeBuilder node, String defaultStr, int line) {
+ if (defaultStr != null) {
+ throw new YangParseException(line, "Can not refine 'default' for '" + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefineMandatory(SchemaNodeBuilder node, Boolean mandatory, int line) {
+ if (mandatory != null) {
+ throw new YangParseException(line, "Can not refine 'mandatory' for '" + node.getQName().getLocalName()
+ + "'.");
+ }
+ }
+
+ private static void checkRefinePresence(SchemaNodeBuilder node, Boolean presence, int line) {
+ if (presence != null) {
+ throw new YangParseException(line, "Can not refine 'presence' for '" + node.getQName().getLocalName()
+ + "'.");
+ }
+ }
+
+ private static void checkRefineMust(SchemaNodeBuilder node, MustDefinition must, int line) {
+ if (must != null) {
+ throw new YangParseException(line, "Can not refine 'must' for '" + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefineMinMax(String refineTargetName, int refineLine, Integer min, Integer max) {
+ if (min != null || max != null) {
+ throw new YangParseException(refineLine, "Can not refine 'min-elements' or 'max-elements' for '"
+ + refineTargetName + "'.");
+ }
+ }
+
+ /**
+ * Perform refine operation of following parameters:
+ * <ul>
+ * <li>description</li>
+ * <li>reference</li>
+ * <li>config</li>
+ * </ul>
+ *
+ * These parameters may be refined for any node.
+ *
+ * @param node
+ * node to refine
+ * @param refine
+ * refine object containing information about refine process
+ * @param line
+ * current line in yang model
+ */
+ public static void refineDefault(final Builder node, final RefineHolder refine, final int line) {
+ Class<? extends Builder> cls = node.getClass();
+
+ String description = refine.getDescription();
+ if (description != null) {
+ try {
+ Method method = cls.getDeclaredMethod("setDescription", String.class);
+ method.invoke(node, description);
+ } catch (Exception e) {
+ throw new YangParseException(line, "Cannot refine description in " + cls.getName(), e);
+ }
+ }
+
+ String reference = refine.getReference();
+ if (reference != null) {
+ try {
+ Method method = cls.getDeclaredMethod("setReference", String.class);
+ method.invoke(node, reference);
+ } catch (Exception e) {
+ throw new YangParseException(line, "Cannot refine reference in " + cls.getName(), e);
+ }
+ }
+
+ Boolean config = refine.isConfiguration();
+ if (config != null) {
+ try {
+ Method method = cls.getDeclaredMethod("setConfiguration", Boolean.class);
+ method.invoke(node, config);
+ } catch (Exception e) {
+ throw new YangParseException(line, "Cannot refine config in " + cls.getName(), e);
+ }
+ }
+ }
+
+ /**
+ * Perform refine operation on given node.
+ *
+ * @param nodeToRefine
+ * builder of node to refine
+ * @param refine
+ * refine object containing information about refine process
+ * @param line
+ * current line in yang model
+ */
+ public static void performRefine(SchemaNodeBuilder nodeToRefine, RefineHolder refine, int line) {
+ checkRefine(nodeToRefine, refine);
+ refineDefault(nodeToRefine, refine, line);
+ if (nodeToRefine instanceof LeafSchemaNodeBuilder) {
+ refineLeaf((LeafSchemaNodeBuilder) nodeToRefine, refine, line);
+ } else if (nodeToRefine instanceof ContainerSchemaNodeBuilder) {
+ refineContainer((ContainerSchemaNodeBuilder) nodeToRefine, refine, line);
+ } else if (nodeToRefine instanceof ListSchemaNodeBuilder) {
+ refineList((ListSchemaNodeBuilder) nodeToRefine, refine, line);
+ } else if (nodeToRefine instanceof LeafListSchemaNodeBuilder) {
+ refineLeafList((LeafListSchemaNodeBuilder) nodeToRefine, refine, line);
+ } else if (nodeToRefine instanceof ChoiceBuilder) {
+ refineChoice((ChoiceBuilder) nodeToRefine, refine, line);
+ } else if (nodeToRefine instanceof AnyXmlBuilder) {
+ refineAnyxml((AnyXmlBuilder) nodeToRefine, refine, line);
+ }
+ }
+
+}
import java.util.Stack;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext;
import org.opendaylight.controller.yang.model.util.Uint8;
import org.opendaylight.controller.yang.model.util.UnknownType;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ConstraintsBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class YangModelBuilderUtil {
-
private static final Logger logger = LoggerFactory.getLogger(YangModelBuilderUtil.class);
private YangModelBuilderUtil() {
}
/**
- * Create SchemaPath object from given path list with namespace, revision
- * and prefix based on given values.
+ * Create SchemaPath from actualPath and names.
*
* @param actualPath
* current position in model
* @param namespace
* @param revision
* @param prefix
+ * @param names
* @return SchemaPath object.
*/
public static SchemaPath createActualSchemaPath(final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix) {
+ final Date revision, final String prefix, final String... names) {
final List<QName> path = new ArrayList<QName>();
QName qname;
// start from index 1 - module name omited
qname = new QName(namespace, revision, prefix, actualPath.get(i));
path.add(qname);
}
+ for (String name : names) {
+ qname = new QName(namespace, revision, prefix, name);
+ path.add(qname);
+ }
return new SchemaPath(path, true);
}
private static List<PatternConstraint> getPatternConstraint(final Type_body_stmtsContext ctx) {
List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
- outer: for (int j = 0; j < ctx.getChildCount(); j++) {
+ for (int j = 0; j < ctx.getChildCount(); j++) {
ParseTree stringRestrChild = ctx.getChild(j);
if (stringRestrChild instanceof String_restrictionsContext) {
for (int k = 0; k < stringRestrChild.getChildCount(); k++) {
ParseTree lengthChild = stringRestrChild.getChild(k);
if (lengthChild instanceof Pattern_stmtContext) {
patterns.add(parsePatternConstraint((Pattern_stmtContext) lengthChild));
- if (k == lengthChild.getChildCount() - 1) {
- break outer;
- }
}
}
}
}
/**
- * Parse orderedby statement.
+ * Parse 'ordered-by' statement.
+ *
+ * The 'ordered-by' statement defines whether the order of entries within a
+ * list are determined by the user or the system. The argument is one of the
+ * strings "system" or "user". If not present, order defaults to "system".
*
* @param childNode
* Ordered_by_stmtContext
- * @return true, if orderedby contains value 'user' or false otherwise
+ * @return true, if ordered-by contains value 'user', false otherwise
*/
public static boolean parseUserOrdered(Ordered_by_stmtContext childNode) {
boolean result = false;
return result;
}
+ public static Boolean getConfig(final ParseTree ctx, final Builder parent, final String moduleName, final int line) {
+ Boolean result = null;
+ // parse configuration statement
+ Boolean configuration = null;
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ ParseTree child = ctx.getChild(i);
+ if (child instanceof Config_stmtContext) {
+ configuration = parseConfig((Config_stmtContext) child);
+ break;
+ }
+ }
+
+ // If 'config' is not specified, the default is the same as the parent
+ // schema node's 'config' value
+ if (configuration == null) {
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ // If the parent node is a rpc input or output, it can has
+ // config set to null
+ result = parentConfig == null ? true : parentConfig;
+ } else if (parent instanceof ChoiceCaseBuilder) {
+ // If the parent node is a 'case' node, the value is the same as
+ // the 'case' node's parent 'choice' node
+ ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
+ Builder choice = choiceCase.getParent();
+ Boolean parentConfig = null;
+ if(choice instanceof ChoiceBuilder) {
+ parentConfig = ((ChoiceBuilder)choice).isConfiguration();
+ } else {
+ parentConfig = true;
+ }
+ result = parentConfig;
+ } else {
+ result = true;
+ }
+ } else {
+ // Check first: if a node has 'config' set to 'false', no node
+ // underneath it can have 'config' set to 'true'
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ if (parentConfig == false && configuration == true) {
+ throw new YangParseException(moduleName, line,
+ "Can not set 'config' to 'true' if parent node has 'config' set to 'false'");
+ }
+ }
+ result = configuration;
+ }
+
+ return result;
+ }
+
/**
- * Parse given config context and return true if it contains string 'true',
- * false otherwise.
+ * Parse config statement.
*
* @param ctx
* config context to parse.
* @return true if given context contains string 'true', false otherwise
*/
- public static boolean parseConfig(final Config_stmtContext ctx) {
- boolean result = false;
+ private static Boolean parseConfig(final Config_stmtContext ctx) {
+ Boolean result = null;
if (ctx != null) {
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree configContext = ctx.getChild(i);
if ("true".equals(value)) {
result = true;
break;
+ } else if ("false".equals(value)) {
+ result = false;
+ break;
+ } else {
+ throw new YangParseException(ctx.getStart().getLine(),
+ "Failed to parse 'config' statement value: '" + value + "'.");
}
}
}
}
/**
- * Parse given type body and creates UnknownType definition.
+ * Parse type body and create UnknownType definition.
*
* @param typedefQName
* qname of current type
* @param ctx
* type body
+ * @param actualPath
+ * @param namespace
+ * @param revision
+ * @param prefix
+ * @param parent
* @return UnknownType object with constraints from parsed type body
*/
- public static TypeDefinition<?> parseUnknownTypeBody(QName typedefQName, Type_body_stmtsContext ctx,
- final List<String> actualPath, final URI namespace, final Date revision, final String prefix,
- Builder parent, ModuleBuilder moduleBuilder) {
+ public static TypeDefinition<?> parseUnknownTypeWithBody(final QName typedefQName,
+ final Type_body_stmtsContext ctx, final List<String> actualPath, final URI namespace, final Date revision,
+ final String prefix, final Builder parent) {
String typeName = typedefQName.getLocalName();
UnknownType.Builder unknownType = new UnknownType.Builder(typedefQName);
/**
* Create TypeDefinition object based on given type name and type body.
*
+ * @param moduleName
+ * current module name
* @param typeName
* name of type
* @param typeBody
- * type body
+ * type body context
* @param actualPath
* current path in schema
* @param namespace
* current revision
* @param prefix
* current prefix
+ * @param parent
+ * parent builder
* @return TypeDefinition object based on parsed values.
*/
- public static TypeDefinition<?> parseTypeBody(final String moduleName, final String typeName,
+ public static TypeDefinition<?> parseTypeWithBody(final String moduleName, final String typeName,
final Type_body_stmtsContext typeBody, final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix, Builder parent) {
+ final Date revision, final String prefix, final Builder parent) {
TypeDefinition<?> baseType = null;
- List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
Integer fractionDigits = getFractionDigits(typeBody);
List<LengthConstraint> lengthStatements = getLengthConstraints(typeBody);
List<PatternConstraint> patternStatements = getPatternConstraint(typeBody);
- List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace, revision,
- prefix);
+ List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
TypeConstraints constraints = new TypeConstraints(moduleName, typeBody.getStart().getLine());
constraints.addFractionDigits(fractionDigits);
constraints.addRanges(uintType.getRangeStatements());
baseType = uintType;
} else if ("enumeration".equals(typeName)) {
+ List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace,
+ revision, prefix);
return new EnumerationType(baseTypePathFinal, enumConstants);
} else if ("string".equals(typeName)) {
StringTypeDefinition stringType = new StringType(baseTypePath);
}
/**
- * Parse given context and find require-instance value.
+ * Parse type body statement and find require-instance value.
*
* @param ctx
- * type body
+ * type body context
* @return require-instance value
*/
private static boolean isRequireInstance(Type_body_stmtsContext ctx) {
}
/**
- * Parse given context and find leafref path.
+ * Parse type body statement and find leafref path.
*
* @param ctx
- * type body
+ * type body context
* @return leafref path as String
*/
private static String parseLeafrefPath(Type_body_stmtsContext ctx) {
}
/**
- * Internal helper method for parsing Must_stmtContext.
+ * Internal helper method for parsing must statement.
*
* @param ctx
* Must_stmtContext
}
/**
- * Parse given tree and set constraints to given builder.
+ * Parse given context and set constraints to constraints builder.
*
* @param ctx
- * context to search
+ * context to parse
* @param constraints
* ConstraintsBuilder to fill
*/
*/
public static RefineHolder parseRefine(Refine_stmtContext refineCtx) {
final String refineTarget = stringFromNode(refineCtx);
- final RefineHolder refine = new RefineHolder(refineTarget, refineCtx.getStart().getLine());
+ final RefineHolder refine = new RefineHolder(refineCtx.getStart().getLine(), refineTarget);
for (int j = 0; j < refineCtx.getChildCount(); j++) {
ParseTree refinePom = refineCtx.getChild(j);
if (refinePom instanceof Refine_pomContext) {
String reference = stringFromNode(refineArg);
refine.setReference(reference);
} else if (refineArg instanceof Config_stmtContext) {
- boolean config = parseConfig((Config_stmtContext) refineArg);
- refine.setConfig(config);
+ Boolean config = parseConfig((Config_stmtContext) refineArg);
+ refine.setConfiguration(config);
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+
+public class GroupingTest {
+ private Set<Module> modules;
+
+ @Before
+ public void init() throws FileNotFoundException {
+ modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+ assertEquals(3, modules.size());
+ }
+
+ @Test
+ public void testRefine() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+
+ ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+ Set<UsesNode> usesNodes = destination.getUses();
+ assertEquals(1, usesNodes.size());
+ UsesNode usesNode = usesNodes.iterator().next();
+ Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+ assertEquals(5, refines.size());
+
+ LeafSchemaNode refineLeaf = null;
+ ContainerSchemaNode refineContainer = null;
+ ListSchemaNode refineList = null;
+ GroupingDefinition refineGrouping = null;
+ TypeDefinition<?> typedef = null;
+ for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
+ SchemaNode value = entry.getValue();
+ if (value instanceof LeafSchemaNode) {
+ refineLeaf = (LeafSchemaNode) value;
+ } else if (value instanceof ContainerSchemaNode) {
+ refineContainer = (ContainerSchemaNode) value;
+ } else if (value instanceof ListSchemaNode) {
+ refineList = (ListSchemaNode) value;
+ } else if (value instanceof GroupingDefinition) {
+ refineGrouping = (GroupingDefinition) value;
+ } else if (value instanceof TypeDefinition<?>) {
+ typedef = (TypeDefinition<?>) value;
+ }
+ }
+
+ // leaf address
+ assertNotNull(refineLeaf);
+ assertEquals("address", refineLeaf.getQName().getLocalName());
+ assertEquals("IP address of target node", refineLeaf.getDescription());
+ assertEquals("address reference added by refine", refineLeaf.getReference());
+ assertFalse(refineLeaf.isConfiguration());
+ assertTrue(refineLeaf.getConstraints().isMandatory());
+ Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+ assertEquals(1, leafMustConstraints.size());
+ MustDefinition leafMust = leafMustConstraints.iterator().next();
+ assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
+
+ // container port
+ assertNotNull(refineContainer);
+ Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+ assertTrue(mustConstraints.isEmpty());
+ assertEquals("description of port defined by refine", refineContainer.getDescription());
+ assertEquals("port reference added by refine", refineContainer.getReference());
+ assertFalse(refineContainer.isConfiguration());
+ assertTrue(refineContainer.isPresenceContainer());
+
+ // list addresses
+ assertNotNull(refineList);
+ assertEquals("description of addresses defined by refine", refineList.getDescription());
+ assertEquals("addresses reference added by refine", refineList.getReference());
+ assertFalse(refineList.isConfiguration());
+ assertEquals(2, (int) refineList.getConstraints().getMinElements());
+ assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+
+ // grouping target-inner
+ assertNotNull(refineGrouping);
+ Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
+ assertEquals(1, refineGroupingChildren.size());
+ LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
+ assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
+ assertEquals("new target-inner grouping description", refineGrouping.getDescription());
+
+ // typedef group-type
+ assertNotNull(typedef);
+ assertEquals("new group-type description", typedef.getDescription());
+ assertEquals("new group-type reference", typedef.getReference());
+ assertTrue(typedef.getBaseType() instanceof ExtendedType);
+ }
+
+ @Test
+ public void testGrouping() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+ Set<DataSchemaNode> children = grouping.getChildNodes();
+ assertEquals(5, children.size());
+ }
+
+ @Test
+ public void testUses() {
+ // suffix _u = added by uses
+ // suffix _g = defined in grouping
+
+ Module testModule = TestUtils.findModule(modules, "types2");
+
+ // get grouping
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+
+ // get node containing uses
+ ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+
+ // check uses
+ Set<UsesNode> uses = destination.getUses();
+ assertEquals(1, uses.size());
+
+ // check uses process
+ AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data");
+ assertNotNull(data_u);
+ assertTrue(data_u.isAddedByUses());
+
+ AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data");
+ assertNotNull(data_g);
+ assertFalse(data_g.isAddedByUses());
+ assertFalse(data_u.equals(data_g));
+
+ ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
+ assertNotNull(how_u);
+ assertTrue(how_u.isAddedByUses());
+
+ ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
+ assertNotNull(how_g);
+ assertFalse(how_g.isAddedByUses());
+ assertFalse(how_u.equals(how_g));
+
+ LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
+ assertNotNull(address_u);
+ assertEquals("1.2.3.4", address_u.getDefault());
+ assertEquals("IP address of target node", address_u.getDescription());
+ assertEquals("address reference added by refine", address_u.getReference());
+ assertFalse(address_u.isConfiguration());
+ assertTrue(address_u.isAddedByUses());
+
+ LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address");
+ assertNotNull(address_g);
+ assertFalse(address_g.isAddedByUses());
+ assertNull(address_g.getDefault());
+ assertEquals("Target IP address", address_g.getDescription());
+ assertNull(address_g.getReference());
+ assertTrue(address_g.isConfiguration());
+ assertFalse(address_u.equals(address_g));
+
+ ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
+ assertNotNull(port_u);
+ assertTrue(port_u.isAddedByUses());
+
+ ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
+ assertNotNull(port_g);
+ assertFalse(port_g.isAddedByUses());
+ assertFalse(port_u.equals(port_g));
+
+ ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
+ assertNotNull(addresses_u);
+ assertTrue(addresses_u.isAddedByUses());
+
+ ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
+ assertNotNull(addresses_g);
+ assertFalse(addresses_g.isAddedByUses());
+ assertFalse(addresses_u.equals(addresses_g));
+
+ // grouping defined by 'uses'
+ Set<GroupingDefinition> groupings_u = destination.getGroupings();
+ assertEquals(1, groupings_u.size());
+ GroupingDefinition grouping_u = groupings_u.iterator().next();
+ assertTrue(grouping_u.isAddedByUses());
+
+ // grouping defined in 'grouping' node
+ Set<GroupingDefinition> groupings_g = grouping.getGroupings();
+ assertEquals(1, groupings_g.size());
+ GroupingDefinition grouping_g = groupings_g.iterator().next();
+ assertFalse(grouping_g.isAddedByUses());
+ assertFalse(grouping_u.equals(grouping_g));
+
+ List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+ assertEquals(1, nodes_u.size());
+ UnknownSchemaNode node_u = nodes_u.get(0);
+ assertTrue(node_u.isAddedByUses());
+
+ List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
+ assertEquals(1, nodes_g.size());
+ UnknownSchemaNode node_g = nodes_g.get(0);
+ assertFalse(node_g.isAddedByUses());
+ assertFalse(node_u.equals(node_g));
+ }
+
+}
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
return modules.iterator().next();
}
+ public static Module loadModuleWithContext(final InputStream stream, final SchemaContext context) throws IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final List<InputStream> input = Collections.singletonList(stream);
+ final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+ stream.close();
+ return modules.iterator().next();
+ }
+
+ public static Set<Module> loadModulesWithContext(final List<InputStream> input, final SchemaContext context) throws IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+ for(InputStream is : input) {
+ if(is != null) {
+ is.close();
+ }
+ }
+ return modules;
+ }
+
public static Module findModule(Set<Module> modules, String moduleName) {
Module result = null;
for (Module module : modules) {
} catch (YangParseException e) {
assertTrue(e.getMessage().contains("Invalid length constraint: <4, 10>"));
}
-
}
@Test
} catch (YangParseException e) {
assertTrue(e.getMessage().contains("Invalid range constraint: <5, 20>"));
}
+ }
+
+ @Test
+ public void testDuplicateContainer() throws IOException {
+ try {
+ try (InputStream stream = new FileInputStream(getClass().getResource(
+ "/negative-scenario/duplicity/container.yang").getPath())) {
+ TestUtils.loadModule(stream);
+ fail("YangParseException should by thrown");
+ }
+ } catch (YangParseException e) {
+ assertTrue(e.getMessage()
+ .contains("Error in module 'container' on line 10: Duplicate node found at line 6"));
+ }
+ }
+
+ @Test
+ public void testDuplicateContainerList() throws IOException {
+ try {
+ try (InputStream stream = new FileInputStream(getClass().getResource(
+ "/negative-scenario/duplicity/container-list.yang").getPath())) {
+ TestUtils.loadModule(stream);
+ fail("YangParseException should by thrown");
+ }
+ } catch (YangParseException e) {
+ assertTrue(e.getMessage().contains(
+ "Error in module 'container-list' on line 10: Duplicate node found at line 6"));
+ }
+ }
+ @Test
+ public void testDuplicateContainerLeaf() throws IOException {
+ try {
+ try (InputStream stream = new FileInputStream(getClass().getResource(
+ "/negative-scenario/duplicity/container-leaf.yang").getPath())) {
+ TestUtils.loadModule(stream);
+ fail("YangParseException should by thrown");
+ }
+ } catch (YangParseException e) {
+ assertTrue(e.getMessage().contains(
+ "Error in module 'container-leaf' on line 10: Duplicate node found at line 6"));
+ }
+ }
+
+ @Test
+ public void testDuplicateTypedef() throws IOException {
+ try {
+ try (InputStream stream = new FileInputStream(getClass().getResource(
+ "/negative-scenario/duplicity/typedef.yang").getPath())) {
+ TestUtils.loadModule(stream);
+ fail("YangParseException should by thrown");
+ }
+ } catch (YangParseException e) {
+ assertTrue(e.getMessage().contains("Error in module 'typedef' on line 10: Duplicate node found at line 6"));
+ }
}
}
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
-import org.opendaylight.controller.yang.model.api.MustDefinition;
import org.opendaylight.controller.yang.model.api.NotificationDefinition;
import org.opendaylight.controller.yang.model.api.RpcDefinition;
-import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
public class YangParserTest {
private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
private Set<Module> modules;
@Before
assertEquals(" WILL BE DEFINED LATER", test.getReference());
}
+ @Test
+ public void testOrderingTypedef() {
+ Module test = TestUtils.findModule(modules, "types2");
+ Set<TypeDefinition<?>> typedefs = test.getTypeDefinitions();
+ String[] expectedOrder = new String[] { "my-base-int32-type", "my-custom-string", "my-decimal-type",
+ "my-decimal-type-ext", "my-int-type", "my-int-type-ext", "my-int-type2", "my-string-type",
+ "my-string-type-ext", "my-string-type2", "my-type1", "my-union", "my-union-ext", "nested-union1",
+ "nested-union2" };
+ String[] actualOrder = new String[typedefs.size()];
+
+ int i = 0;
+ for (TypeDefinition<?> type : typedefs) {
+ actualOrder[i] = type.getQName().getLocalName();
+ i++;
+ }
+ assertArrayEquals(expectedOrder, actualOrder);
+ }
+
+ @Test
+ public void testOrderingChildNodes() {
+ Module test = TestUtils.findModule(modules, "types2");
+ Set<DataSchemaNode> childNodes = test.getChildNodes();
+ String[] expectedOrder = new String[] { "count", "if-name", "interfaces", "name", "nested-type-leaf", "peer",
+ "system" };
+ String[] actualOrder = new String[childNodes.size()];
+
+ int i = 0;
+ for (DataSchemaNode child : childNodes) {
+ actualOrder[i] = child.getQName().getLocalName();
+ i++;
+ }
+ assertArrayEquals(expectedOrder, actualOrder);
+ }
+
+ @Test
+ public void testOrderingNestedChildNodes() {
+ Module test = TestUtils.findModule(modules, "types2");
+ Set<GroupingDefinition> groupings = test.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition target = groupings.iterator().next();
+
+ Set<DataSchemaNode> childNodes = target.getChildNodes();
+ String[] expectedOrder = new String[] { "address", "addresses", "data", "how", "port" };
+ String[] actualOrder = new String[childNodes.size()];
+
+ int i = 0;
+ for (DataSchemaNode child : childNodes) {
+ actualOrder[i] = child.getQName().getLocalName();
+ i++;
+ }
+ assertArrayEquals(expectedOrder, actualOrder);
+ }
+
@Test
public void testParseContainer() {
Module test = TestUtils.findModule(modules, "types2");
assertEquals(0, interfaces.getUnknownSchemaNodes().size());
// test DataSchemaNode args
assertFalse(interfaces.isAugmenting());
- assertFalse(interfaces.isConfiguration());
+ assertTrue(interfaces.isConfiguration());
ConstraintDefinition constraints = interfaces.getConstraints();
assertNull(constraints.getWhenCondition());
assertEquals(0, constraints.getMustConstraints().size());
assertEquals(0, ifEntry.getUnknownSchemaNodes().size());
// test DataSchemaNode args
assertFalse(ifEntry.isAugmenting());
- assertFalse(ifEntry.isConfiguration());
+ assertTrue(ifEntry.isConfiguration());
ConstraintDefinition constraints = ifEntry.getConstraints();
assertNull(constraints.getWhenCondition());
assertEquals(0, constraints.getMustConstraints().size());
assertEquals(100L, range.getMax());
}
- @Test
- public void testRefine() {
- Module testModule = TestUtils.findModule(modules, "types2");
-
- ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
- ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
- Set<UsesNode> usesNodes = destination.getUses();
- assertEquals(1, usesNodes.size());
- UsesNode usesNode = usesNodes.iterator().next();
- Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
- assertEquals(5, refines.size());
-
- LeafSchemaNode refineLeaf = null;
- ContainerSchemaNode refineContainer = null;
- ListSchemaNode refineList = null;
- GroupingDefinition refineGrouping = null;
- TypeDefinition<?> typedef = null;
- for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
- SchemaNode value = entry.getValue();
- if (value instanceof LeafSchemaNode) {
- refineLeaf = (LeafSchemaNode) value;
- } else if (value instanceof ContainerSchemaNode) {
- refineContainer = (ContainerSchemaNode) value;
- } else if (value instanceof ListSchemaNode) {
- refineList = (ListSchemaNode) value;
- } else if (value instanceof GroupingDefinition) {
- refineGrouping = (GroupingDefinition) value;
- } else if (value instanceof TypeDefinition<?>) {
- typedef = (TypeDefinition<?>) value;
- }
- }
-
- // leaf address
- assertNotNull(refineLeaf);
- assertEquals("address", refineLeaf.getQName().getLocalName());
- assertEquals("description of address defined by refine", refineLeaf.getDescription());
- assertEquals("address reference added by refine", refineLeaf.getReference());
- assertFalse(refineLeaf.isConfiguration());
- assertTrue(refineLeaf.getConstraints().isMandatory());
- Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
- assertEquals(1, leafMustConstraints.size());
- MustDefinition leafMust = leafMustConstraints.iterator().next();
- assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
-
- // container port
- assertNotNull(refineContainer);
- Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
- assertTrue(mustConstraints.isEmpty());
- assertEquals("description of port defined by refine", refineContainer.getDescription());
- assertEquals("port reference added by refine", refineContainer.getReference());
- assertFalse(refineContainer.isConfiguration());
- assertTrue(refineContainer.isPresenceContainer());
-
- // list addresses
- assertNotNull(refineList);
- assertEquals("description of addresses defined by refine", refineList.getDescription());
- assertEquals("addresses reference added by refine", refineList.getReference());
- assertFalse(refineList.isConfiguration());
- assertEquals(2, (int) refineList.getConstraints().getMinElements());
- assertEquals(12, (int) refineList.getConstraints().getMaxElements());
-
- // grouping target-inner
- assertNotNull(refineGrouping);
- Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
- assertEquals(1, refineGroupingChildren.size());
- LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
- assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
- assertEquals("new target-inner grouping description", refineGrouping.getDescription());
-
- // typedef group-type
- assertNotNull(typedef);
- assertEquals("new group-type description", typedef.getDescription());
- assertEquals("new group-type reference", typedef.getReference());
- assertTrue(typedef.getBaseType() instanceof ExtendedType);
- }
-
@Test
public void testChoice() {
Module testModule = TestUtils.findModule(modules, "types1");
ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
Set<ChoiceCaseNode> cases = how.getCases();
- assertEquals(3, cases.size());
+ assertEquals(5, cases.size());
+ ChoiceCaseNode input = null;
+ ChoiceCaseNode output = null;
+ for (ChoiceCaseNode caseNode : cases) {
+ if ("input".equals(caseNode.getQName().getLocalName())) {
+ input = caseNode;
+ } else if ("output".equals(caseNode.getQName().getLocalName())) {
+ output = caseNode;
+ }
+ }
+ assertNotNull(input);
+ assertNotNull(input.getPath());
+ assertNotNull(output);
+ assertNotNull(output.getPath());
}
@Test
assertNotNull(output.getDataChildByName("data"));
}
- @Test
- public void testGrouping() {
- Module testModule = TestUtils.findModule(modules, "types2");
- Set<GroupingDefinition> groupings = testModule.getGroupings();
- assertEquals(1, groupings.size());
- GroupingDefinition grouping = groupings.iterator().next();
- Set<DataSchemaNode> children = grouping.getChildNodes();
- assertEquals(5, children.size());
- }
-
@Test
public void testAugmentNodesTypesSchemaPath() throws Exception {
Module testModule = TestUtils.findModule(modules, "types1");
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
+import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+
+import com.google.common.collect.Lists;
+
+public class YangParserWithContextTest {
+ private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ private final YangParserImpl parser = new YangParserImpl();
+
+ @Test
+ public void testTypeFromContext() throws Exception {
+ SchemaContext context = null;
+ String resource = "/types/ietf-inet-types@2010-09-24.yang";
+ InputStream stream = new FileInputStream(getClass().getResource(resource).getPath());
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ stream.close();
+
+ Module module = null;
+ resource = "/context-test/test1.yang";
+ InputStream stream2 = new FileInputStream(getClass().getResource(resource).getPath());
+ module = TestUtils.loadModuleWithContext(stream2, context);
+ stream2.close();
+ assertNotNull(module);
+
+ LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName("id");
+
+ ExtendedType leafType = (ExtendedType) leaf.getType();
+ QName qname = leafType.getQName();
+ assertEquals(URI.create("urn:simple.demo.test1"), qname.getNamespace());
+ assertEquals(simpleDateFormat.parse("2013-06-18"), qname.getRevision());
+ assertEquals("t1", qname.getPrefix());
+ assertEquals("port-number", qname.getLocalName());
+
+ ExtendedType leafBaseType = (ExtendedType) leafType.getBaseType();
+ qname = leafBaseType.getQName();
+ assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-inet-types"), qname.getNamespace());
+ assertEquals(simpleDateFormat.parse("2010-09-24"), qname.getRevision());
+ assertEquals("inet", qname.getPrefix());
+ assertEquals("port-number", qname.getLocalName());
+
+ ExtendedType dscpExt = (ExtendedType)TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext");
+ List<RangeConstraint> ranges = dscpExt.getRanges();
+ assertEquals(1, ranges.size());
+ RangeConstraint range = ranges.get(0);
+ assertEquals(0L, range.getMin());
+ assertEquals(63L, range.getMax());
+ }
+
+ @Test
+ public void testUsesFromContext() throws Exception {
+ SchemaContext context = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+ Module testModule = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
+ testModule = TestUtils.loadModuleWithContext(stream, context);
+ }
+ assertNotNull(testModule);
+
+ // suffix _u = added by uses
+ // suffix _g = defined in grouping from context
+
+ // get grouping
+ Module contextModule = context.findModuleByNamespace(URI.create("urn:simple.types.data.demo"));
+ assertNotNull(contextModule);
+ Set<GroupingDefinition> groupings = contextModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+
+ // get node containing uses
+ ContainerSchemaNode peer = (ContainerSchemaNode)testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode)peer.getDataChildByName("destination");
+
+ // check uses
+ Set<UsesNode> uses = destination.getUses();
+ assertEquals(1, uses.size());
+
+ // check uses process
+ AnyXmlSchemaNode data_u = (AnyXmlSchemaNode)destination.getDataChildByName("data");
+ assertNotNull(data_u);
+ assertTrue(data_u.isAddedByUses());
+
+ AnyXmlSchemaNode data_g = (AnyXmlSchemaNode)grouping.getDataChildByName("data");
+ assertNotNull(data_g);
+ assertFalse(data_g.isAddedByUses());
+ assertFalse(data_u.equals(data_g));
+
+ ChoiceNode how_u = (ChoiceNode)destination.getDataChildByName("how");
+ assertNotNull(how_u);
+ assertTrue(how_u.isAddedByUses());
+
+ ChoiceNode how_g = (ChoiceNode)grouping.getDataChildByName("how");
+ assertNotNull(how_g);
+ assertFalse(how_g.isAddedByUses());
+ assertFalse(how_u.equals(how_g));
+
+ LeafSchemaNode address_u = (LeafSchemaNode)destination.getDataChildByName("address");
+ assertNotNull(address_u);
+ assertTrue(address_u.isAddedByUses());
+
+ LeafSchemaNode address_g = (LeafSchemaNode)grouping.getDataChildByName("address");
+ assertNotNull(address_g);
+ assertFalse(address_g.isAddedByUses());
+ assertFalse(address_u.equals(address_g));
+
+ ContainerSchemaNode port_u = (ContainerSchemaNode)destination.getDataChildByName("port");
+ assertNotNull(port_u);
+ assertTrue(port_u.isAddedByUses());
+
+ ContainerSchemaNode port_g = (ContainerSchemaNode)grouping.getDataChildByName("port");
+ assertNotNull(port_g);
+ assertFalse(port_g.isAddedByUses());
+ assertFalse(port_u.equals(port_g));
+
+ ListSchemaNode addresses_u = (ListSchemaNode)destination.getDataChildByName("addresses");
+ assertNotNull(addresses_u);
+ assertTrue(addresses_u.isAddedByUses());
+
+ ListSchemaNode addresses_g = (ListSchemaNode)grouping.getDataChildByName("addresses");
+ assertNotNull(addresses_g);
+ assertFalse(addresses_g.isAddedByUses());
+ assertFalse(addresses_u.equals(addresses_g));
+
+ // grouping defined by 'uses'
+ Set<GroupingDefinition> groupings_u = destination.getGroupings();
+ assertEquals(1, groupings_u.size());
+ GroupingDefinition grouping_u = groupings_u.iterator().next();
+ assertTrue(grouping_u.isAddedByUses());
+
+ // grouping defined in 'grouping' node
+ Set<GroupingDefinition> groupings_g = grouping.getGroupings();
+ assertEquals(1, groupings_g.size());
+ GroupingDefinition grouping_g = groupings_g.iterator().next();
+ assertFalse(grouping_g.isAddedByUses());
+ assertFalse(grouping_u.equals(grouping_g));
+
+ List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+ assertEquals(1, nodes_u.size());
+ UnknownSchemaNode node_u = nodes_u.get(0);
+ assertTrue(node_u.isAddedByUses());
+
+ List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
+ assertEquals(1, nodes_g.size());
+ UnknownSchemaNode node_g = nodes_g.get(0);
+ assertFalse(node_g.isAddedByUses());
+ assertFalse(node_u.equals(node_g));
+ }
+
+ @Test
+ public void testUsesRefineFromContext() throws Exception {
+ SchemaContext context = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+ Module module = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
+ module = TestUtils.loadModuleWithContext(stream, context);
+ }
+ assertNotNull(module);
+
+ ContainerSchemaNode peer = (ContainerSchemaNode) module.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+ Set<UsesNode> usesNodes = destination.getUses();
+ assertEquals(1, usesNodes.size());
+ UsesNode usesNode = usesNodes.iterator().next();
+
+ // test grouping path
+ List<QName> path = new ArrayList<QName>();
+ QName qname = new QName(URI.create("urn:simple.types.data.demo"), simpleDateFormat.parse("2013-02-27"), "t2",
+ "target");
+ path.add(qname);
+ SchemaPath expectedPath = new SchemaPath(path, true);
+ assertEquals(expectedPath, usesNode.getGroupingPath());
+
+ // test refine
+ Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+ assertEquals(5, refines.size());
+
+ LeafSchemaNode refineLeaf = null;
+ ContainerSchemaNode refineContainer = null;
+ ListSchemaNode refineList = null;
+ GroupingDefinition refineGrouping = null;
+ TypeDefinition<?> typedef = null;
+ for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
+ SchemaNode value = entry.getValue();
+ if (value instanceof LeafSchemaNode) {
+ refineLeaf = (LeafSchemaNode) value;
+ } else if (value instanceof ContainerSchemaNode) {
+ refineContainer = (ContainerSchemaNode) value;
+ } else if (value instanceof ListSchemaNode) {
+ refineList = (ListSchemaNode) value;
+ } else if (value instanceof GroupingDefinition) {
+ refineGrouping = (GroupingDefinition) value;
+ } else if (value instanceof TypeDefinition<?>) {
+ typedef = (TypeDefinition<?>) value;
+ }
+ }
+
+ // leaf address
+ assertNotNull(refineLeaf);
+ assertEquals("address", refineLeaf.getQName().getLocalName());
+ assertEquals("description of address defined by refine", refineLeaf.getDescription());
+ assertEquals("address reference added by refine", refineLeaf.getReference());
+ assertFalse(refineLeaf.isConfiguration());
+ assertTrue(refineLeaf.getConstraints().isMandatory());
+ Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+ assertEquals(1, leafMustConstraints.size());
+ MustDefinition leafMust = leafMustConstraints.iterator().next();
+ assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
+
+ // container port
+ assertNotNull(refineContainer);
+ Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+ assertTrue(mustConstraints.isEmpty());
+ assertEquals("description of port defined by refine", refineContainer.getDescription());
+ assertEquals("port reference added by refine", refineContainer.getReference());
+ assertFalse(refineContainer.isConfiguration());
+ assertTrue(refineContainer.isPresenceContainer());
+
+ // list addresses
+ assertNotNull(refineList);
+ assertEquals("description of addresses defined by refine", refineList.getDescription());
+ assertEquals("addresses reference added by refine", refineList.getReference());
+ assertFalse(refineList.isConfiguration());
+ assertEquals(2, (int) refineList.getConstraints().getMinElements());
+ assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+
+ // grouping target-inner
+ assertNotNull(refineGrouping);
+ Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
+ assertEquals(1, refineGroupingChildren.size());
+ LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
+ assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
+ assertEquals("new target-inner grouping description", refineGrouping.getDescription());
+
+ // typedef group-type
+ assertNotNull(typedef);
+ assertEquals("new group-type description", typedef.getDescription());
+ assertEquals("new group-type reference", typedef.getReference());
+ assertTrue(typedef.getBaseType() instanceof ExtendedType);
+ }
+
+ @Test
+ public void testIdentity() throws Exception {
+ SchemaContext context = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang")
+ .getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+ Module module = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) {
+ module = TestUtils.loadModuleWithContext(stream, context);
+ }
+ assertNotNull(module);
+
+ Set<IdentitySchemaNode> identities = module.getIdentities();
+ assertEquals(1, identities.size());
+
+ IdentitySchemaNode identity = identities.iterator().next();
+ QName idQName = identity.getQName();
+ assertEquals(URI.create("urn:simple.demo.test3"), idQName.getNamespace());
+ assertEquals(simpleDateFormat.parse("2013-06-18"), idQName.getRevision());
+ assertEquals("t3", idQName.getPrefix());
+ assertEquals("pt", idQName.getLocalName());
+
+ IdentitySchemaNode baseIdentity = identity.getBaseIdentity();
+ QName idBaseQName = baseIdentity.getQName();
+ assertEquals(URI.create("urn:simple.container.demo"), idBaseQName.getNamespace());
+ assertEquals(simpleDateFormat.parse("2012-04-16"), idBaseQName.getRevision());
+ assertEquals("iit", idBaseQName.getPrefix());
+ assertEquals("service-type", idBaseQName.getLocalName());
+ }
+
+ @Test
+ public void testUnknownNodes() throws Exception {
+ SchemaContext context = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+
+ Module module = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) {
+ module = TestUtils.loadModuleWithContext(stream, context);
+ }
+
+ ContainerSchemaNode network = (ContainerSchemaNode) module.getDataChildByName("network");
+ List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
+ assertEquals(1, unknownNodes.size());
+
+ UnknownSchemaNode un = unknownNodes.iterator().next();
+ QName unType = un.getNodeType();
+ assertEquals(URI.create("urn:simple.container.demo"), unType.getNamespace());
+ assertEquals(simpleDateFormat.parse("2012-04-16"), unType.getRevision());
+ assertEquals("custom", unType.getPrefix());
+ assertEquals("mountpoint", unType.getLocalName());
+ assertEquals("point", un.getNodeParameter());
+ }
+
+ @Test
+ public void testAugment() throws Exception {
+ // load first module
+ SchemaContext context = null;
+ String resource = "/context-augment-test/test4.yang";
+
+ try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+
+ Set<Module> contextModules = context.getModules();
+ Module t3 = TestUtils.findModule(contextModules, "test4");
+ ContainerSchemaNode interfaces = (ContainerSchemaNode) t3.getDataChildByName("interfaces");
+ ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+
+ // load another modules and parse them against already existing context
+ Set<Module> modules = null;
+ try (InputStream stream1 = new FileInputStream(getClass().getResource("/context-augment-test/test1.yang")
+ .getPath());
+ InputStream stream2 = new FileInputStream(getClass().getResource("/context-augment-test/test2.yang")
+ .getPath());
+ InputStream stream3 = new FileInputStream(getClass().getResource("/context-augment-test/test3.yang")
+ .getPath())) {
+ List<InputStream> input = Lists.newArrayList(stream1, stream2, stream3);
+ modules = TestUtils.loadModulesWithContext(input, context);
+ }
+ assertNotNull(modules);
+
+ // test augmentation process
+ ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
+ assertNotNull(augmentHolder);
+ DataSchemaNode ds0 = augmentHolder.getDataChildByName("ds0ChannelNumber");
+ assertNotNull(ds0);
+ DataSchemaNode interfaceId = augmentHolder.getDataChildByName("interface-id");
+ assertNotNull(interfaceId);
+ DataSchemaNode higherLayerIf = augmentHolder.getDataChildByName("higher-layer-if");
+ assertNotNull(higherLayerIf);
+ ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName("schemas");
+ assertNotNull(schemas);
+ assertNotNull(schemas.getDataChildByName("id"));
+
+ // test augment target after augmentation: check if it is same instance
+ ListSchemaNode ifEntryAfterAugment = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+ assertTrue(ifEntry == ifEntryAfterAugment);
+ }
+
+}
*/
package org.opendaylight.controller.yang.parser.util;
-import static org.hamcrest.core.AnyOf.*;
-import static org.hamcrest.core.Is.*;
-import static org.junit.Assert.*;
-import static org.junit.matchers.JUnitMatchers.*;
+import static org.hamcrest.core.AnyOf.anyOf;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
import static org.mockito.Mockito.*;
import java.util.Arrays;
List<ModuleBuilder> l = ModuleDependencySort.sort(builders);
- assertDependencyGraph(ModuleDependencySort.createModuleGraph(Arrays
- .asList(builders)));
+ assertDependencyGraph(ModuleDependencySort.createModuleGraph(Arrays.asList(builders)));
@SuppressWarnings("unchecked")
Matcher<String> cOrD = anyOf(is(c.getName()), is(d.getName()));
try {
ModuleDependencySort.sort(builders);
} catch (YangValidationException e) {
- assertThat(
- e.getMessage(),
- containsString("Module:a with revision:default declared twice"));
+ assertThat(e.getMessage(), containsString("Module:a with revision:default declared twice"));
throw e;
}
}
try {
ModuleDependencySort.sort(builders);
} catch (YangValidationException e) {
- assertThat(
- e.getMessage(),
- containsString("Not existing module imported:b:default by:a:default"));
+ assertThat(e.getMessage(), containsString("Not existing module imported:b:default by:a:default"));
throw e;
}
}
@Test(expected = YangValidationException.class)
public void testImportTwiceDifferentRevision() throws Exception {
- Date date = new Date();
- ModuleBuilder b2 = mockModuleBuilder("b", date);
+ Date date1 = new Date(463846463486L);
+ Date date2 = new Date(364896446683L);
+ b = mockModuleBuilder("b", date1);
+ ModuleBuilder b2 = mockModuleBuilder("b", date2);
mockDependency(a, b);
mockDependency(c, b2);
try {
ModuleDependencySort.sort(builders);
} catch (YangValidationException e) {
- assertThat(
- e.getMessage(),
- containsString("Module:b imported twice with different revisions:default, "
- + YangParserListenerImpl.simpleDateFormat
- .format(date)));
+ assertThat(e.getMessage(), containsString("Module:b imported twice with different revisions:"
+ + YangParserListenerImpl.simpleDateFormat.format(date1) + ", "
+ + YangParserListenerImpl.simpleDateFormat.format(date2)));
throw e;
}
}
ModuleDependencySort.sort(builders);
} catch (YangValidationException e) {
assertThat(e.getMessage(), containsString("Module:a with revision:"
- + YangParserListenerImpl.simpleDateFormat.format(rev)
- + " declared twice"));
+ + YangParserListenerImpl.simpleDateFormat.format(rev) + " declared twice"));
throw e;
}
}
- private void assertDependencyGraph(
- Map<String, Map<Date, ModuleNodeImpl>> moduleGraph) {
- for (Entry<String, Map<Date, ModuleNodeImpl>> node : moduleGraph
- .entrySet()) {
+ private void assertDependencyGraph(Map<String, Map<Date, ModuleNodeImpl>> moduleGraph) {
+ for (Entry<String, Map<Date, ModuleNodeImpl>> node : moduleGraph.entrySet()) {
String name = node.getKey();
// Expects only one module revision
- Set<Edge> inEdges = node.getValue().values().iterator().next()
- .getInEdges();
- Set<Edge> outEdges = node.getValue().values().iterator().next()
- .getOutEdges();
+ Set<Edge> inEdges = node.getValue().values().iterator().next().getInEdges();
+ Set<Edge> outEdges = node.getValue().values().iterator().next().getOutEdges();
if (name.equals("a")) {
assertEdgeCount(inEdges, 0, outEdges, 1);
}
}
- private void assertEdgeCount(Set<Edge> inEdges, int i, Set<Edge> outEdges,
- int j) {
+ private void assertEdgeCount(Set<Edge> inEdges, int i, Set<Edge> outEdges, int j) {
assertThat(inEdges.size(), is(i));
assertThat(outEdges.size(), is(j));
}
--- /dev/null
+module test1 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test1";
+ prefix "t1";
+
+ import test3 {
+ prefix "t3";
+ revision-date 2013-06-18;
+ }
+
+ import test2 {
+ prefix "t2";
+ revision-date 2013-06-18;
+ }
+
+ import test4 {
+ prefix "t4";
+ revision-date 2013-06-18;
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ augment "/t4:interfaces/t4:ifEntry/t2:augment-holder/t3:schemas" {
+ when "if:ifType='ds0'";
+ leaf id {
+ type string;
+ }
+ }
+
+}
--- /dev/null
+module test2 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test2";
+ prefix "t2";
+
+ import test3 {
+ prefix "t3";
+ revision-date 2013-06-18;
+ }
+
+ import test4 {
+ prefix "t4";
+ revision-date 2013-06-18;
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ augment "/t4:interfaces/t4:ifEntry/t3:augment-holder" {
+ when "if:ifType='ds0'";
+ leaf ds0ChannelNumber {
+ type string;
+ }
+ leaf interface-id {
+ type leafref {
+ path "/if:interfaces/if:interface/if:name";
+ }
+ }
+ leaf-list higher-layer-if {
+ type leafref {
+ path "/if:interfaces/if:interface/if:higher-layer-if";
+ }
+ }
+ container schemas {
+ }
+ }
+
+}
--- /dev/null
+module test3 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test3";
+ prefix "t3";
+
+ import test4 {
+ prefix "t4";
+ revision-date 2013-06-18;
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ augment "/t4:interfaces/t4:ifEntry" {
+ when "if:ifType='ds0'";
+ container augment-holder {
+ description "Description for augment holder";
+ }
+ }
+
+}
--- /dev/null
+module test4 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test4";
+ prefix "t4";
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ container interfaces {
+ list ifEntry {
+ key "ifIndex";
+ leaf ifIndex {
+ type uint32;
+ units minutes;
+ }
+ leaf ifMtu {
+ type int32;
+ }
+ min-elements 1;
+ max-elements 11;
+ }
+ }
+
+}
--- /dev/null
+module test1 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test1";
+ prefix "t1";
+
+ import ietf-inet-types {
+ prefix "inet";
+ revision-date 2010-09-24;
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ typedef dscp-ext {
+ type inet:dscp {
+ range "min..max";
+ }
+ }
+
+ leaf id {
+ type inet:port-number {
+ range "0..65536";
+ }
+ }
+
+}
--- /dev/null
+module test2 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test2";
+ prefix "t2";
+
+ import types2 {
+ prefix "data";
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ container peer {
+ container destination {
+ uses data:target {
+ refine address {
+ default "1.2.3.4";
+ description "description of address defined by refine";
+ reference "address reference added by refine";
+ config false;
+ mandatory true;
+ must "ifType != 'ethernet' or " +
+ "(ifType = 'ethernet' and ifMTU = 1500)" {
+ error-message "An ethernet MTU must be 1500";
+ }
+ }
+ refine port {
+ description "description of port defined by refine";
+ reference "port reference added by refine";
+ config false;
+ presence "presence is required";
+ }
+ refine addresses {
+ description "description of addresses defined by refine";
+ reference "addresses reference added by refine";
+ config false;
+ min-elements 2;
+ max-elements 12;
+ }
+ refine target-inner {
+ description "new target-inner grouping description";
+ }
+ refine group-type {
+ description "new group-type description";
+ reference "new group-type reference";
+ }
+ }
+ }
+ }
+
+}
--- /dev/null
+module test3 {
+
+ yang-version 1;
+ namespace "urn:simple.demo.test3";
+ prefix "t3";
+
+ import custom-types-test {
+ prefix "custom";
+ }
+
+ organization "opendaylight";
+ contact "WILL-BE-DEFINED-LATER";
+ revision 2013-06-18 {
+ }
+
+ identity pt {
+ base custom:service-type;
+ }
+
+ container network {
+ custom:mountpoint point {
+ mnt:target-ref target;
+ }
+
+ description "network-description";
+ reference "network-reference";
+ status obsolete;
+ config true;
+ presence "some presence text";
+ }
+
+}
container transfer {
choice how {
default interval;
+ container input {
+ }
+ list output {
+ leaf id {
+ type string;
+ }
+ }
case interval {
leaf interval {
type uint16;
}
container schemas {
}
+ choice odl {
+ leaf id {
+ type int8;
+ }
+ }
}
container mycont {
revision "2013-02-27" {
reference " WILL BE DEFINED LATER";
}
-
+
typedef my-base-int32-type {
type int32 {
range "2..20";
units "mile";
default "11";
}
-
+
typedef my-custom-string {
type string {
pattern "[a-k]*";
length "5..11";
}
}
-
+
typedef my-string-type {
type my-custom-string {
length "6..10";
range "10..20";
}
}
-
+
typedef my-int-type2 {
type my-int-type {
range "12..18";
}
}
-
+
typedef my-int-type-ext {
type my-int-type2 {
range "14..16";
}
}
-
+
typedef my-decimal-type {
type decimal64 {
fraction-digits 6;
}
}
-
+
typedef my-decimal-type-ext {
type decimal64 {
fraction-digits 5;
path "/interface/name";
}
}
-
+
leaf name {
type string;
}
-
+
leaf count {
type int8 {
range "1..10";
}
}
-
+
leaf nested-type-leaf {
type my-type1;
}
-
+
extension c-define {
description
"Takes as argument a name string.
yin-element "true";
}
}
-
+
container system {
leaf user {
type string;
}
}
-
+
grouping target {
anyxml data {
config true;
typedef group-type {
type my-decimal-type;
}
+
+ opendaylight;
}
container peer {
uses target {
refine address {
default "1.2.3.4";
- description "description of address defined by refine";
+ description "IP address of target node";
reference "address reference added by refine";
config false;
mandatory true;
}
}
}
-
+
container interfaces {
list ifEntry {
key "ifIndex";
type uint32;
units minutes;
}
-
+
leaf ifMtu {
type int32;
}
-
+
min-elements 1;
max-elements 11;
}
description "Description for augment holder";
}
}
-
+
augment "/data:interfaces/data:ifEntry" {
when "if:ifType='ds2'";
container augment-holder2 {
description "Description for augment holder";
}
}
-
+
augment "/data:interfaces/data:ifEntry/t3:augment-holder/t1:schemas" {
when "if:leafType='ds1'";
leaf linkleaf {
mnt:mountpoint point {
mnt:target-ref target;
}
-
+
description "network-description";
reference "network-reference";
status obsolete;
storage (memory, flash or disk) that can be used to
store syslog messages.";
}
-
+
extension c-define {
description
"Takes as argument a name string.
#define.";
argument "name";
}
-
+
notification event {
leaf event-class {
type string;
type string;
}
}
-
+
rpc get-config {
description
"Retrieve all or part of a specified configuration.";
--- /dev/null
+module container-leaf {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ container foo {
+ description "foo container";
+ }
+
+ leaf foo {
+ type int8;
+ }
+
+}
--- /dev/null
+module container-list {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ container foo {
+ description "foo container";
+ }
+
+ list foo {
+ description "foo list";
+ }
+
+}
--- /dev/null
+module container {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ container foo {
+ description "foo 1";
+ }
+
+ container foo {
+ description "foo 2";
+ }
+
+}
--- /dev/null
+module identity {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ identity id1;
+
+ identity id2;
+
+ identity id1 {
+ base id2;
+ }
+
+}
--- /dev/null
+module typedef {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ typedef int-ext {
+ type int32;
+ }
+
+ typedef int-ext {
+ type int16;
+ }
+
+}
module test0 {
yang-version 1;
namespace "urn:simple.container.demo";
- prefix "t1";
-
+ prefix "t0";
+
container interfaces {
-
}
+
}
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-ietf</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>ietf-inet-types</artifactId>
+ <version>2010.09.24-SNAPSHOT</version>
+</project>
\ No newline at end of file
--- /dev/null
+ module ietf-inet-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+ prefix "inet";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types for Internet addresses and related things.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of protocol field related types ***/
+
+ typedef ip-version {
+ type enumeration {
+ enum unknown {
+ value "0";
+ description
+ "An unknown or unspecified version of the Internet protocol.";
+ }
+ enum ipv4 {
+ value "1";
+ description
+ "The IPv4 protocol as defined in RFC 791.";
+ }
+ enum ipv6 {
+ value "2";
+ description
+ "The IPv6 protocol as defined in RFC 2460.";
+ }
+ }
+ description
+ "This value represents the version of the IP protocol.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetVersion textual convention of the SMIv2.";
+ reference
+ "RFC 791: Internet Protocol
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ typedef dscp {
+ type uint8 {
+ range "0..63";
+ }
+ description
+ "The dscp type represents a Differentiated Services Code-Point
+ that may be used for marking packets in a traffic stream.
+
+ In the value set and its semantics, this type is equivalent
+ to the Dscp textual convention of the SMIv2.";
+ reference
+ "RFC 3289: Management Information Base for the Differentiated
+ Services Architecture
+ RFC 2474: Definition of the Differentiated Services Field
+ (DS Field) in the IPv4 and IPv6 Headers
+ RFC 2780: IANA Allocation Guidelines For Values In
+ the Internet Protocol and Related Headers";
+ }
+
+ typedef ipv6-flow-label {
+ type uint32 {
+ range "0..1048575";
+ }
+ description
+ "The flow-label type represents flow identifier or Flow Label
+ in an IPv6 packet header that may be used to discriminate
+ traffic flows.
+
+ In the value set and its semantics, this type is equivalent
+ to the IPv6FlowLabel textual convention of the SMIv2.";
+ reference
+ "RFC 3595: Textual Conventions for IPv6 Flow Label
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+ }
+
+ typedef port-number {
+ type uint16 {
+ range "0..65535";
+ }
+ description
+ "The port-number type represents a 16-bit port number of an
+ Internet transport layer protocol such as UDP, TCP, DCCP, or
+ SCTP. Port numbers are assigned by IANA. A current list of
+ all assignments is available from <http://www.iana.org/>.
+
+ Note that the port number value zero is reserved by IANA. In
+ situations where the value zero does not make sense, it can
+ be excluded by subtyping the port-number type.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetPortNumber textual convention of the SMIv2.";
+ reference
+ "RFC 768: User Datagram Protocol
+ RFC 793: Transmission Control Protocol
+ RFC 4960: Stream Control Transmission Protocol
+ RFC 4340: Datagram Congestion Control Protocol (DCCP)
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of autonomous system related types ***/
+
+ typedef as-number {
+ type uint32;
+ description
+ "The as-number type represents autonomous system numbers
+ which identify an Autonomous System (AS). An AS is a set
+ of routers under a single technical administration, using
+ an interior gateway protocol and common metrics to route
+ packets within the AS, and using an exterior gateway
+ protocol to route packets to other ASs'. IANA maintains
+ the AS number space and has delegated large parts to the
+ regional registries.
+
+ Autonomous system numbers were originally limited to 16
+ bits. BGP extensions have enlarged the autonomous system
+ number space to 32 bits. This type therefore uses an uint32
+ base type without a range restriction in order to support
+ a larger autonomous system number space.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetAutonomousSystemNumber textual convention of
+ the SMIv2.";
+ reference
+ "RFC 1930: Guidelines for creation, selection, and registration
+ of an Autonomous System (AS)
+ RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+ RFC 4893: BGP Support for Four-octet AS Number Space
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of IP address and hostname related types ***/
+
+ typedef ip-address {
+ type union {
+ type inet:ipv4-address;
+ type inet:ipv6-address;
+ }
+ description
+ "The ip-address type represents an IP address and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-address {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '(%[\p{N}\p{L}]+)?';
+ }
+ description
+ "The ipv4-address type represents an IPv4 address in
+ dotted-quad notation. The IPv4 address may include a zone
+ index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format for the zone index is the numerical
+ format";
+ }
+
+ typedef ipv6-address {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(%[\p{N}\p{L}]+)?';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(%.+)?';
+ }
+ description
+ "The ipv6-address type represents an IPv6 address in full,
+ mixed, shortened, and shortened-mixed notation. The IPv6
+ address may include a zone index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format of IPv6 addresses uses the compressed
+ format described in RFC 4291, Section 2.2, item 2 with the
+ following additional rules: the :: substitution must be
+ applied to the longest sequence of all-zero 16-bit chunks
+ in an IPv6 address. If there is a tie, the first sequence
+ of all-zero 16-bit chunks is replaced by ::. Single
+ all-zero 16-bit chunks are not compressed. The canonical
+ format uses lowercase characters and leading zeros are
+ not allowed. The canonical format for the zone index is
+ the numerical format as described in RFC 4007, Section
+ 11.2.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture
+ RFC 4007: IPv6 Scoped Address Architecture
+ RFC 5952: A Recommendation for IPv6 Address Text Representation";
+ }
+
+ typedef ip-prefix {
+ type union {
+ type inet:ipv4-prefix;
+ type inet:ipv6-prefix;
+ }
+ description
+ "The ip-prefix type represents an IP prefix and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-prefix {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+ }
+ description
+ "The ipv4-prefix type represents an IPv4 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal to 32.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The canonical format of an IPv4 prefix has all bits of
+ the IPv4 address set to zero that are not part of the
+ IPv4 prefix.";
+ }
+
+ typedef ipv6-prefix {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(/.+)';
+ }
+ description
+ "The ipv6-prefix type represents an IPv6 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal 128.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The IPv6 address should have all bits that do not belong
+ to the prefix set to zero.
+
+ The canonical format of an IPv6 prefix has all bits of
+ the IPv6 address set to zero that are not part of the
+ IPv6 prefix. Furthermore, IPv6 address is represented
+ in the compressed format described in RFC 4291, Section
+ 2.2, item 2 with the following additional rules: the ::
+ substitution must be applied to the longest sequence of
+ all-zero 16-bit chunks in an IPv6 address. If there is
+ a tie, the first sequence of all-zero 16-bit chunks is
+ replaced by ::. Single all-zero 16-bit chunks are not
+ compressed. The canonical format uses lowercase
+ characters and leading zeros are not allowed.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture";
+ }
+
+ /*** collection of domain name and URI types ***/
+
+ typedef domain-name {
+ type string {
+ pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+ + '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+ + '|\.';
+ length "1..253";
+ }
+ description
+ "The domain-name type represents a DNS domain name. The
+ name SHOULD be fully qualified whenever possible.
+
+ Internet domain names are only loosely specified. Section
+ 3.5 of RFC 1034 recommends a syntax (modified in Section
+ 2.1 of RFC 1123). The pattern above is intended to allow
+ for current practice in domain name use, and some possible
+ future expansion. It is designed to hold various types of
+ domain names, including names used for A or AAAA records
+ (host names) and other records, such as SRV records. Note
+ that Internet host names have a stricter syntax (described
+ in RFC 952) than the DNS recommendations in RFCs 1034 and
+ 1123, and that systems that want to store host names in
+ schema nodes using the domain-name type are recommended to
+ adhere to this stricter standard to ensure interoperability.
+
+ The encoding of DNS names in the DNS protocol is limited
+ to 255 characters. Since the encoding consists of labels
+ prefixed by a length bytes and there is a trailing NULL
+ byte, only 253 characters can appear in the textual dotted
+ notation.
+
+ The description clause of schema nodes using the domain-name
+ type MUST describe when and how these names are resolved to
+ IP addresses. Note that the resolution of a domain-name value
+ may require to query multiple DNS records (e.g., A for IPv4
+ and AAAA for IPv6). The order of the resolution process and
+ which DNS record takes precedence can either be defined
+ explicitely or it may depend on the configuration of the
+ resolver.
+
+ Domain-name values use the US-ASCII encoding. Their canonical
+ format uses lowercase US-ASCII characters. Internationalized
+ domain names MUST be encoded in punycode as described in RFC
+ 3492";
+ reference
+ "RFC 952: DoD Internet Host Table Specification
+ RFC 1034: Domain Names - Concepts and Facilities
+ RFC 1123: Requirements for Internet Hosts -- Application
+ and Support
+ RFC 2782: A DNS RR for specifying the location of services
+ (DNS SRV)
+ RFC 3492: Punycode: A Bootstring encoding of Unicode for
+ Internationalized Domain Names in Applications
+ (IDNA)
+ RFC 5891: Internationalizing Domain Names in Applications
+ (IDNA): Protocol";
+ }
+
+ typedef host {
+ type union {
+ type inet:ip-address;
+ type inet:domain-name;
+ }
+ description
+ "The host type represents either an IP address or a DNS
+ domain name.";
+ }
+
+ typedef uri {
+ type string;
+ description
+ "The uri type represents a Uniform Resource Identifier
+ (URI) as defined by STD 66.
+
+ Objects using the uri type MUST be in US-ASCII encoding,
+ and MUST be normalized as described by RFC 3986 Sections
+ 6.2.1, 6.2.2.1, and 6.2.2.2. All unnecessary
+ percent-encoding is removed, and all case-insensitive
+ characters are set to lowercase except for hexadecimal
+ digits, which are normalized to uppercase as described in
+ Section 6.2.2.1.
+
+ The purpose of this normalization is to help provide
+ unique URIs. Note that this normalization is not
+ sufficient to provide uniqueness. Two URIs that are
+ textually distinct after this normalization may still be
+ equivalent.
+
+ Objects using the uri type may restrict the schemes that
+ they permit. For example, 'data:' and 'urn:' schemes
+ might not be appropriate.
+
+ A zero-length URI is not a valid URI. This can be used to
+ express 'URI absent' where required.
+
+ In the value set and its semantics, this type is equivalent
+ to the Uri SMIv2 textual convention defined in RFC 5017.";
+ reference
+ "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+ RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+ Group: Uniform Resource Identifiers (URIs), URLs,
+ and Uniform Resource Names (URNs): Clarifications
+ and Recommendations
+ RFC 5017: MIB Textual Conventions for Uniform Resource
+ Identifiers (URIs)";
+ }
+
+ }
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-ietf</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>ietf-yang-types</artifactId>
+ <version>2010.09.24-SNAPSHOT</version>
+</project>
\ No newline at end of file
--- /dev/null
+ module ietf-yang-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
+ prefix "yang";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of counter and gauge types ***/
+
+ typedef counter32 {
+ type uint32;
+ description
+ "The counter32 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter32 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter32 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter32.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter32 {
+ type yang:counter32;
+ default "0";
+ description
+ "The zero-based-counter32 type represents a counter32
+ that has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter32 textual convention of the SMIv2.";
+ reference
+ "RFC 4502: Remote Network Monitoring Management Information
+ Base Version 2";
+ }
+
+ typedef counter64 {
+ type uint64;
+ description
+ "The counter64 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter64 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter64 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter64.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter64 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter64 {
+ type yang:counter64;
+ default "0";
+ description
+ "The zero-based-counter64 type represents a counter64 that
+ has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter64 textual convention of the SMIv2.";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ typedef gauge32 {
+ type uint32;
+ description
+ "The gauge32 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^32-1 (4294967295 decimal), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge32 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge32 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the Gauge32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef gauge64 {
+ type uint64;
+ description
+ "The gauge64 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^64-1 (18446744073709551615), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge64 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge64 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the CounterBasedGauge64 SMIv2 textual convention defined
+ in RFC 2856";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ /*** collection of identifier related types ***/
+
+ typedef object-identifier {
+ type string {
+ pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))'
+ + '(\.(0|([1-9]\d*)))*';
+ }
+ description
+ "The object-identifier type represents administratively
+ assigned names in a registration-hierarchical-name tree.
+
+ Values of this type are denoted as a sequence of numerical
+ non-negative sub-identifier values. Each sub-identifier
+ value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers
+ are separated by single dots and without any intermediate
+ whitespace.
+
+ The ASN.1 standard restricts the value space of the first
+ sub-identifier to 0, 1, or 2. Furthermore, the value space
+ of the second sub-identifier is restricted to the range
+ 0 to 39 if the first sub-identifier is 0 or 1. Finally,
+ the ASN.1 standard requires that an object identifier
+ has always at least two sub-identifier. The pattern
+ captures these restrictions.
+
+ Although the number of sub-identifiers is not limited,
+ module designers should realize that there may be
+ implementations that stick with the SMIv2 limit of 128
+ sub-identifiers.
+
+ This type is a superset of the SMIv2 OBJECT IDENTIFIER type
+ since it is not restricted to 128 sub-identifiers. Hence,
+ this type SHOULD NOT be used to represent the SMIv2 OBJECT
+ IDENTIFIER type, the object-identifier-128 type SHOULD be
+ used instead.";
+ reference
+ "ISO9834-1: Information technology -- Open Systems
+ Interconnection -- Procedures for the operation of OSI
+ Registration Authorities: General procedures and top
+ arcs of the ASN.1 Object Identifier tree";
+ }
+
+
+
+
+ typedef object-identifier-128 {
+ type object-identifier {
+ pattern '\d*(\.\d*){1,127}';
+ }
+ description
+ "This type represents object-identifiers restricted to 128
+ sub-identifiers.
+
+ In the value set and its semantics, this type is equivalent
+ to the OBJECT IDENTIFIER type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ /*** collection of date and time related types ***/
+
+ typedef date-and-time {
+ type string {
+ pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?'
+ + '(Z|[\+\-]\d{2}:\d{2})';
+ }
+ description
+ "The date-and-time type is a profile of the ISO 8601
+ standard for representation of dates and times using the
+ Gregorian calendar. The profile is defined by the
+ date-time production in Section 5.6 of RFC 3339.
+
+ The date-and-time type is compatible with the dateTime XML
+ schema type with the following notable exceptions:
+
+ (a) The date-and-time type does not allow negative years.
+
+ (b) The date-and-time time-offset -00:00 indicates an unknown
+ time zone (see RFC 3339) while -00:00 and +00:00 and Z all
+ represent the same time zone in dateTime.
+
+ (c) The canonical format (see below) of data-and-time values
+ differs from the canonical format used by the dateTime XML
+ schema type, which requires all times to be in UTC using the
+ time-offset 'Z'.
+
+ This type is not equivalent to the DateAndTime textual
+ convention of the SMIv2 since RFC 3339 uses a different
+ separator between full-date and full-time and provides
+ higher resolution of time-secfrac.
+
+ The canonical format for date-and-time values with a known time
+ zone uses a numeric time zone offset that is calculated using
+ the device's configured known offset to UTC time. A change of
+ the device's offset to UTC time will cause date-and-time values
+ to change accordingly. Such changes might happen periodically
+ in case a server follows automatically daylight saving time
+ (DST) time zone offset changes. The canonical format for
+ date-and-time values with an unknown time zone (usually referring
+ to the notion of local time) uses the time-offset -00:00.";
+ reference
+ "RFC 3339: Date and Time on the Internet: Timestamps
+ RFC 2579: Textual Conventions for SMIv2
+ XSD-TYPES: XML Schema Part 2: Datatypes Second Edition";
+ }
+
+ typedef timeticks {
+ type uint32;
+ description
+ "The timeticks type represents a non-negative integer that
+ represents the time, modulo 2^32 (4294967296 decimal), in
+ hundredths of a second between two epochs. When a schema
+ node is defined that uses this type, the description of
+ the schema node identifies both of the reference epochs.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeTicks type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef timestamp {
+ type yang:timeticks;
+ description
+ "The timestamp type represents the value of an associated
+ timeticks schema node at which a specific occurrence happened.
+ The specific occurrence must be defined in the description
+ of any schema node defined using this type. When the specific
+ occurrence occurred prior to the last time the associated
+ timeticks attribute was zero, then the timestamp value is
+ zero. Note that this requires all timestamp values to be
+ reset to zero when the value of the associated timeticks
+ attribute reaches 497+ days and wraps around to zero.
+
+ The associated timeticks schema node must be specified
+ in the description of any schema node using this type.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeStamp textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of generic address types ***/
+
+ typedef phys-address {
+ type string {
+ pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?';
+ }
+ description
+ "Represents media- or physical-level addresses represented
+ as a sequence octets, each octet represented by two hexadecimal
+ numbers. Octets are separated by colons. The canonical
+ representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the PhysAddress textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ typedef mac-address {
+ type string {
+ pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}';
+ }
+ description
+ "The mac-address type represents an IEEE 802 MAC address.
+ The canonical representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the MacAddress textual convention of the SMIv2.";
+ reference
+ "IEEE 802: IEEE Standard for Local and Metropolitan Area
+ Networks: Overview and Architecture
+ RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of XML specific types ***/
+
+ typedef xpath1.0 {
+ type string;
+ description
+ "This type represents an XPATH 1.0 expression.
+
+ When a schema node is defined that uses this type, the
+ description of the schema node MUST specify the XPath
+ context in which the XPath expression is evaluated.";
+ reference
+ "XPATH: XML Path Language (XPath) Version 1.0";
+ }
+
+ }
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-parent</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>model-ietf</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>ietf-inet-types</module>
+ <module>ietf-yang-types</module>
+ </modules>
+</project>
\ No newline at end of file
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-parent</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>model-openflow</artifactId>
+</project>
\ No newline at end of file
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-parent</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>model-topology-bgp</artifactId>
+</project>
\ No newline at end of file
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>model-parent</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>model-topology</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ <version>2010.09.24-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+module topology {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:topology";
+ prefix "tp";
+
+ import ietf-inet-types { prefix "inet"; }
+
+ organization "TBD";
+
+ contact "WILL-BE-DEFINED-LATER";
+
+ description "";
+
+ revision 2013-06-11 {
+ description "Updated model with review comments.
+ Removed top-level container network.
+ Moved network elements to separate module.";
+ }
+
+ typedef topology-id {
+ type inet:uri;
+ }
+
+ typedef node-id {
+ description "Node abstract identifier, schema for URI will be defined by augmentation";
+ type inet:uri;
+ }
+
+ typedef link-id {
+ description "Node abstract identifier, schema for URI will be defined by augmentation";
+ type inet:uri;
+ }
+
+ typedef tp-id {
+ type inet:uri;
+ description "identifier for termination points on a port";
+ }
+
+ typedef tp-ref {
+ type leafref {
+ path "/topologies/topology/nodes/node/termination-points/termination-point/tp-id";
+ }
+ }
+ typedef topology-ref {
+ type leafref {
+ path "/topologies/topology/topology-id";
+ }
+ description "This type is used for leafs that reference topology identifier instance.";
+ // currently not used
+ }
+
+ typedef node-ref {
+ type leafref {
+ path "/topologies/topology/nodes/node/node-id";
+ }
+ description "This type is used for leafs that reference a node instance.";
+ }
+
+ typedef link-ref {
+ type leafref {
+ path "/topologies/topology/links/link/link-id";
+ }
+ description "This type is used for leafs that reference a link instance.";
+ // currently not used
+ }
+
+ container topologies {
+ list topology {
+ description "
+ This is the model of abstract topology which contains only Network
+ Nodes and Network Links. Each topology MUST be identified by
+ unique topology-id for reason that the store could contain many
+ topologies.
+ ";
+ key "topology-id";
+ leaf topology-id {
+ type topology-id;
+ description "
+ It is presumed that datastore will contain many topologies. To
+ distinguish between topologies it is vital to have UNIQUE
+ topology identifier.
+ ";
+ }
+
+ container types {
+ description "
+ The container for definition of topology types.
+ The augmenting modules should add empty optional leaf
+ to this container to signalize topology type.
+ ";
+ }
+
+ container nodes {
+ list node {
+ description "The list of network nodes defined for topology.";
+
+ key "node-id";
+ leaf node-id {
+ type node-id;
+ description "The Topology identifier of network-node.";
+ }
+
+ //leaf supporting-ne {
+ // type network-element-ref;
+ //}
+
+ container termination-points {
+ list termination-point {
+ key "tp-id";
+ leaf tp-id {
+ type tp-id;
+ }
+ }
+ }
+ }
+ }
+
+ container links {
+ list link {
+ description "
+ The Network Link which is defined by Local (Source) and
+ Remote (Destination) Network Nodes. Every link MUST be
+ defined either by identifier and his local and remote
+ Network Nodes (in real applications it is common that many
+ links are originated from one node and end up in same
+ remote node). To ensure that we would always know to
+ distinguish between links, every link SHOULD have
+ identifier.
+ ";
+ key "link-id";
+
+ leaf link-id {
+ type link-id;
+ description "";
+ }
+
+ container source {
+ leaf source-node {
+ type node-ref;
+ description "Source node identifier.";
+ }
+ leaf source-tp {
+ type tp-ref;
+ }
+ }
+
+ container destination {
+ leaf dest-node {
+ type node-ref;
+ description "Destination node identifier.";
+ }
+ leaf dest-tp {
+ type tp-ref;
+ }
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>yang-prototype</artifactId>
+ <groupId>org.opendaylight.controller</groupId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>model-parent</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>ietf</module>
+ <module>model-topology</module>
+ <module>model-openflow</module>
+ <!--module>model-topology-bgp</module-->
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <version>0.5.3-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.controller.maven.sal.api.gen.plugin.CodeGeneratorImpl
+ </codeGeneratorClass>
+ <outputBaseDir>
+ target/generated-sources/sal
+ </outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>maven-sal-api-gen-plugin</artifactId>
+ <version>0.5.3-SNAPSHOT</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/generated-sources/sal</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.opendaylight.controller
+ </groupId>
+ <artifactId>
+ yang-maven-plugin
+ </artifactId>
+ <versionRange>
+ [0.5,)
+ </versionRange>
+ <goals>
+ <goal>
+ generate-sources
+ </goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-binding</artifactId>
+ <version>0.5.3-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-common</artifactId>
+ <version>0.5.3-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
<modules>
<module>yang</module>
<module>code-generator</module>
+ <module>model</module>
</modules>
<properties>
<artifactId>yang-prototype</artifactId>
<version>0.5-SNAPSHOT</version>
</parent>
- <version>0.5.2-SNAPSHOT</version>
+ <version>0.5.3-SNAPSHOT</version>
<artifactId>yang</artifactId>
<packaging>pom</packaging>
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-binding</artifactId>\r
</project>
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.yang.binding;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: lsedlak
+ * Date: 27.6.2013
+ * Time: 11:44
+ * To change this template use File | Settings | File Templates.
+ */
+public class InstanceIdentifier <T extends DataObject> {
+
+}
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-common</artifactId>\r
<dependencies>\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-data-api</artifactId>\r
\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-data-util</artifactId>\r
<dependencies>\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-model-api</artifactId>\r
<dependencies>\r
*/\r
package org.opendaylight.controller.yang.model.api;\r
\r
+import java.util.List;\r
+\r
/**\r
* AugmentationSchema represents augment definition. The "augment" statement\r
* allows a module or submodule to add to the schema tree defined in an external\r
*/\r
SchemaPath getTargetPath();\r
\r
+ /**\r
+ * @return collection of all unknown nodes defined in this augmentation\r
+ */\r
+ public List<UnknownSchemaNode> getUnknownSchemaNodes();\r
+\r
}\r
*/
package org.opendaylight.controller.yang.model.api;
+import org.opendaylight.controller.yang.common.QName;
+
import java.util.Set;
/**
* @return ChoiceCaseNode objects defined in this node
*/
Set<ChoiceCaseNode> getCases();
-
+
+ /**
+ * @param name
+ * QName of seeked Choice Case Node
+ * @return child case node of this Choice if child with given name is
+ * present, <code>null</code> otherwise
+ */
+ ChoiceCaseNode getCaseNodeByName(QName name);
+
+ /**
+ * @param name
+ * name of seeked child as String
+ * @return child case node (or local name of case node) of this Choice if child with given name is
+ * present, <code>null</code> otherwise
+ */
+ ChoiceCaseNode getCaseNodeByName(String name);
+
String getDefaultCase();
}
public interface DataNodeContainer {\r
\r
/**\r
- * @return Set of all newly defined types within this DataNodeContainer\r
+ * Returns set of all newly defined types within this DataNodeContainer.\r
+ *\r
+ * @return typedef statements in lexicographical order\r
*/\r
Set<TypeDefinition<?>> getTypeDefinitions();\r
\r
/**\r
- * Set of all child nodes defined within this DataNodeContainer\r
+ * Returns set of all child nodes defined within this DataNodeContainer.\r
+ *\r
+ * @return child nodes in lexicographical order\r
*/\r
Set<DataSchemaNode> getChildNodes();\r
\r
/**\r
- * Set of all groupings defined within this DataNodeContainer\r
+ * Returns set of all groupings defined within this DataNodeContainer.\r
+ *\r
+ * @return grouping statements in lexicographical order\r
*/\r
Set<GroupingDefinition> getGroupings();\r
\r
/**\r
* Returns <code>true</code> if the data node was added by augmentation,\r
* otherwise returns <code>false</code>\r
- * \r
+ *\r
* @return <code>true</code> if the data node was added by augmentation,\r
* otherwise returns <code>false</code>\r
*/\r
boolean isAugmenting();\r
\r
+ /**\r
+ * Returns <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ *\r
+ * @return <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ */\r
+ boolean isAddedByUses();\r
+\r
/**\r
* Returns <code>true</code> if the data represents configuration data,\r
* otherwise returns <code>false</code>\r
- * \r
+ *\r
* @return <code>true</code> if the data represents configuration data,\r
* otherwise returns <code>false</code>\r
*/\r
\r
/**\r
* Returns the constraints associated with Data Schema Node\r
- * \r
+ *\r
* @return the constraints associated with Data Schema Node\r
*/\r
ConstraintDefinition getConstraints();\r
*/\r
public interface GroupingDefinition extends DataNodeContainer, SchemaNode {\r
\r
+ /**\r
+ * Returns <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ *\r
+ * @return <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ */\r
+ boolean isAddedByUses();\r
+\r
}\r
\r
Set<ModuleImport> getImports();\r
\r
+ /**\r
+ * Returns feature statements defined in module.\r
+ *\r
+ * @return feature statements in lexicographical order\r
+ */\r
Set<FeatureDefinition> getFeatures();\r
\r
+ /**\r
+ * Returns notification statements defined in module.\r
+ *\r
+ * @return notification statements in lexicographical order\r
+ */\r
Set<NotificationDefinition> getNotifications();\r
\r
+ /**\r
+ * Returns augment statements defined in module.\r
+ *\r
+ * @return augment statements\r
+ */\r
Set<AugmentationSchema> getAugmentations();\r
\r
+ /**\r
+ * Returns rpc statements defined in module.\r
+ *\r
+ * @return rpc statements in lexicographical order\r
+ */\r
Set<RpcDefinition> getRpcs();\r
\r
+ /**\r
+ * Returns deviation statements defined in module.\r
+ *\r
+ * @return deviation statements\r
+ */\r
Set<Deviation> getDeviations();\r
\r
+ /**\r
+ * Returns identity statements defined in module.\r
+ *\r
+ * @return identity statements in lexicographical order\r
+ */\r
Set<IdentitySchemaNode> getIdentities();\r
\r
+ /**\r
+ * Returns extension statements defined in module.\r
+ *\r
+ * @return extension statements in lexicographical order\r
+ */\r
List<ExtensionDefinition> getExtensionSchemaNodes();\r
\r
+ /**\r
+ * Returns unknown nodes defined in module.\r
+ *\r
+ * @return unknown nodes in lexicographical order\r
+ */\r
+ List<UnknownSchemaNode> getUnknownSchemaNodes();\r
+\r
}\r
package org.opendaylight.controller.yang.model.api;\r
\r
/**\r
- * Interface describing YANG 'notification' statement. The\r
- * notification statement is used to define a NETCONF notification.\r
+ * Interface describing YANG 'notification' statement. The notification\r
+ * statement is used to define a NETCONF notification.\r
*/\r
-public interface NotificationDefinition extends SchemaNode, DataNodeContainer {\r
+public interface NotificationDefinition extends SchemaNode, DataNodeContainer, AugmentationTarget {\r
\r
}\r
public interface UnknownSchemaNode extends SchemaNode {
QName getNodeType();
+
String getNodeParameter();
+ boolean isAddedByUses();
+
}
*/\r
boolean isAugmenting();\r
\r
+ /**\r
+ * Returns <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ *\r
+ * @return <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ */\r
+ boolean isAddedByUses();\r
+\r
/**\r
* Some of the properties of each node in the grouping can be refined with\r
* the "refine" statement.\r
<parent>\r
<groupId>org.opendaylight.controller</groupId>\r
<artifactId>yang</artifactId>\r
- <version>0.5.2-SNAPSHOT</version>\r
+ <version>0.5.3-SNAPSHOT</version>\r
</parent>\r
<artifactId>yang-model-util</artifactId>\r
<dependencies>\r
* interface which represents UNSIGNED Integer values defined in Yang language. <br>
* The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
* They represent unsigned integers of different sizes:
- *
+ *
* <ul>
* <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
* <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
* <li>uint64 - represents integer values between 0 and 18446744073709551615,
* inclusively.</li>
* </ul>
- *
+ *
*/
public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
private static final long MIN_VALUE = 0;
private final List<RangeConstraint> rangeStatements;
/**
- *
+ *
* @param actualPath
* @param namespace
* @param revision
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.yang.model.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.controller.yang.model.api.DataNodeContainer;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
-import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
-import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.*;
public class DataNodeIterator implements Iterator<DataSchemaNode> {
private final DataNodeContainer container;
- private List<ListSchemaNode> allLists;
- private List<ContainerSchemaNode> allContainers;
- private List<LeafSchemaNode> allLeafs;
- private List<LeafListSchemaNode> allLeafLists;
- private List<DataSchemaNode> allChilds;
+ private final List<ListSchemaNode> allLists;
+ private final List<ContainerSchemaNode> allContainers;
+ private final List<ChoiceNode> allChoices;
+ private final List<DataSchemaNode> allChilds;
public DataNodeIterator(final DataNodeContainer container) {
if (container == null) {
throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
}
- init();
+ this.allContainers = new ArrayList<>();
+ this.allLists = new ArrayList<>();
+ this.allChilds = new ArrayList<>();
+ this.allChoices = new ArrayList<>();
+
this.container = container;
traverse(this.container);
}
- private void init() {
- this.allContainers = new ArrayList<ContainerSchemaNode>();
- this.allLists = new ArrayList<ListSchemaNode>();
- this.allLeafs = new ArrayList<LeafSchemaNode>();
- this.allLeafLists = new ArrayList<LeafListSchemaNode>();
- this.allChilds = new ArrayList<DataSchemaNode>();
- }
-
public List<ContainerSchemaNode> allContainers() {
return allContainers;
}
return allLists;
}
- public List<LeafSchemaNode> allLeafs() {
- return allLeafs;
- }
-
- public List<LeafListSchemaNode> allLeafLists() {
- return allLeafLists;
+ public List<ChoiceNode> allChoices() {
+ return allChoices;
}
private void traverse(final DataNodeContainer dataNode) {
return;
}
- final Set<DataSchemaNode> childs = dataNode.getChildNodes();
- if (childs != null) {
- for (DataSchemaNode childNode : childs) {
+ final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+ if (childNodes != null) {
+ for (DataSchemaNode childNode : childNodes) {
if (childNode.isAugmenting()) {
continue;
}
final ListSchemaNode list = (ListSchemaNode) childNode;
allLists.add(list);
traverse(list);
- } else if (childNode instanceof LeafSchemaNode) {
- final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
- allLeafs.add(leaf);
- } else if (childNode instanceof LeafListSchemaNode) {
- final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
- allLeafLists.add(leafList);
+ } else if (childNode instanceof ChoiceNode) {
+ final ChoiceNode choiceNode = (ChoiceNode) childNode;
+ allChoices.add(choiceNode);
+ final Set<ChoiceCaseNode> cases = choiceNode.getCases();
+ if (cases != null) {
+ for (final ChoiceCaseNode caseNode : cases) {
+ traverse(caseNode);
+ }
+ }
}
}
}
final Set<GroupingDefinition> groupings = dataNode.getGroupings();
- if(groupings != null) {
- for(GroupingDefinition grouping : groupings) {
+ if (groupings != null) {
+ for (GroupingDefinition grouping : groupings) {
traverse(grouping);
}
}
@Override
public boolean hasNext() {
if (container.getChildNodes() != null) {
- Set<DataSchemaNode> childs = container.getChildNodes();
+ final Set<DataSchemaNode> childNodes = container.getChildNodes();
- if ((childs != null) && !childs.isEmpty()) {
- return childs.iterator().hasNext();
+ if ((childNodes != null) && !childNodes.isEmpty()) {
+ return childNodes.iterator().hasNext();
}
}
return false;
private Status status;
private String units;
private Object defaultValue;
+ private boolean addedByUses;
public static class Builder {
private final QName typeName;
private Status status = Status.CURRENT;
private String units = "";
private Object defaultValue = null;
+ private boolean addedByUses;
private List<RangeConstraint> ranges = Collections.emptyList();
private List<LengthConstraint> lengths = Collections.emptyList();
return this;
}
+ public Builder addedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ return this;
+ }
+
public Builder unknownSchemaNodes(
final List<UnknownSchemaNode> unknownSchemaNodes) {
this.unknownSchemaNodes = unknownSchemaNodes;
this.status = builder.status;
this.units = builder.units;
this.defaultValue = builder.defaultValue;
+ this.addedByUses = builder.addedByUses;
this.ranges = builder.ranges;
this.lengths = builder.lengths;
return defaultValue;
}
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
@Override
public QName getQName() {
return typeName;
/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.yang.model.util;
import java.util.Collections;
import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;
/**
- * The <code>default</code> implementation of Instance Identifier Type Definition interface.
+ * The <code>default</code> implementation of Instance Identifier Type
+ * Definition interface.
*
* @see InstanceIdentifierTypeDefinition
*/
public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
- private static final QName name = BaseTypes
- .constructQName("instance-identifier");
- private static final String description = "The instance-identifier built-in type is used to " +
- "uniquely identify a particular instance node in the data tree.";
+ private static final QName name = BaseTypes.constructQName("instance-identifier");
+ private static final String description = "The instance-identifier built-in type is used to "
+ + "uniquely identify a particular instance node in the data tree.";
private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
private final transient SchemaPath path;
private final RevisionAwareXPath xpath;
private final String units = "";
private final InstanceIdentifierTypeDefinition baseType;
- private final boolean requireInstance;
+ private boolean requireInstance = true;
+
+ public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath) {
+ super();
+ this.path = path;
+ this.xpath = xpath;
+ this.baseType = this;
+ }
- public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
+ public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath, final boolean requireInstance) {
super();
this.path = path;
this.xpath = xpath;
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
*/
@Override
public InstanceIdentifierTypeDefinition getBaseType() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
+ * ()
*/
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
- * getPathStatement()
+ * @see org.opendaylight.controller.yang.model.api.type.
+ * InstanceIdentifierTypeDefinition# getPathStatement()
*/
@Override
public RevisionAwareXPath getPathStatement() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
- * requireInstance()
+ * @see org.opendaylight.controller.yang.model.api.type.
+ * InstanceIdentifierTypeDefinition# requireInstance()
*/
@Override
public boolean requireInstance() {
import java.util.Set;
import org.opendaylight.controller.yang.common.QName;
-import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.controller.yang.model.api.DataNodeContainer;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
-import org.opendaylight.controller.yang.model.api.ListSchemaNode;
-import org.opendaylight.controller.yang.model.api.Module;
-import org.opendaylight.controller.yang.model.api.ModuleImport;
-import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
-import org.opendaylight.controller.yang.model.api.SchemaContext;
-import org.opendaylight.controller.yang.model.api.SchemaNode;
-import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.*;
public final class SchemaContextUtil {
- private SchemaContextUtil() {}
+ private SchemaContextUtil() {
+ }
public static DataSchemaNode findDataSchemaNode(final SchemaContext context, final SchemaPath schemaPath) {
if (schemaPath != null) {
// TODO: function to escape conditions in path
}
if (nonCondXPath.isAbsolute()) {
- final Queue<QName> qnamedPath = xpathToQNamePath(context, module,
- strXPath);
+ final Queue<QName> qnamedPath = xpathToQNamePath(context, module, strXPath);
if (qnamedPath != null) {
- final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context,
- module, qnamedPath);
+ final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamedPath);
return dataNode;
}
}
return null;
}
- public static DataSchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context,
- final Module module, final SchemaNode actualSchemaNode,
- final RevisionAwareXPath relativeXPath) {
- if ((actualSchemaNode != null) && (relativeXPath != null)
- && !relativeXPath.isAbsolute()) {
+ public static DataSchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module,
+ final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) {
+ if ((actualSchemaNode != null) && (relativeXPath != null) && !relativeXPath.isAbsolute()) {
final SchemaPath actualNodePath = actualSchemaNode.getPath();
if (actualNodePath != null) {
- final Queue<QName> qnamePath = resolveRelativeXPath(context, module,
- relativeXPath, actualNodePath);
+ final Queue<QName> qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualNodePath);
if (qnamePath != null) {
- final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context,
- module, qnamePath);
+ final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamePath);
return dataNode;
}
}
return null;
}
- private static Module resolveModuleFromSchemaPath(final SchemaContext
- context, final SchemaPath schemaPath) {
+ private static Module resolveModuleFromSchemaPath(final SchemaContext context, final SchemaPath schemaPath) {
if ((schemaPath != null) && (schemaPath.getPath() != null)) {
final List<QName> path = schemaPath.getPath();
if (!path.isEmpty()) {
return null;
}
- public static Module findParentModuleForTypeDefinition(
- final SchemaContext context, final TypeDefinition<?> type) {
+ public static Module findParentModuleForTypeDefinition(final SchemaContext context, final TypeDefinition<?> type) {
final SchemaPath schemaPath = type.getPath();
if ((schemaPath != null) && (schemaPath.getPath() != null)) {
- if(type instanceof ExtendedType) {
+ if (type instanceof ExtendedType) {
List<QName> path = schemaPath.getPath();
final QName qname = path.get(path.size() - 1);
final SchemaPath schemaPath = schemaNode.getPath();
if (schemaPath == null) {
- throw new IllegalStateException("Schema Path for Schema Node is not " +
- "set properly (Schema Path is NULL)");
+ throw new IllegalStateException("Schema Path for Schema Node is not "
+ + "set properly (Schema Path is NULL)");
}
final List<QName> qnamedPath = schemaPath.getPath();
if (qnamedPath == null || qnamedPath.isEmpty()) {
- throw new IllegalStateException("Schema Path contains invalid state of path parts." +
- "The Schema Path MUST contain at least ONE QName which defines namespace and Local name" +
- "of path.");
+ throw new IllegalStateException("Schema Path contains invalid state of path parts."
+ + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name"
+ + "of path.");
}
final QName qname = qnamedPath.get(qnamedPath.size() - 1);
return context.findModuleByNamespace(qname.getNamespace());
private static DataSchemaNode findSchemaNodeForGivenPath(final SchemaContext context, final Module module,
final Queue<QName> qnamedPath) {
- if ((module != null) && (module.getNamespace() != null)
- && (qnamedPath != null)) {
+ if ((module != null) && (module.getNamespace() != null) && (qnamedPath != null)) {
DataNodeContainer nextNode = module;
final URI moduleNamespace = module.getNamespace();
- QName childNodeQName = null;
+ QName childNodeQName;
DataSchemaNode schemaNode = null;
while ((nextNode != null) && !qnamedPath.isEmpty()) {
childNodeQName = qnamedPath.peek();
nextNode = (ContainerSchemaNode) schemaNode;
} else if (schemaNode instanceof ListSchemaNode) {
nextNode = (ListSchemaNode) schemaNode;
+ } else if (schemaNode instanceof ChoiceNode) {
+ final ChoiceNode choice = (ChoiceNode) schemaNode;
+ qnamedPath.poll();
+ if (!qnamedPath.isEmpty()) {
+ childNodeQName = qnamedPath.peek();
+ nextNode = choice.getCaseNodeByName(childNodeQName);
+ schemaNode = (DataSchemaNode)nextNode;
+ }
} else {
nextNode = null;
}
} else if (!childNodeNamespace.equals(moduleNamespace)) {
- final Module nextModule = context
- .findModuleByNamespace(childNodeNamespace);
- schemaNode = findSchemaNodeForGivenPath(context, nextModule,
- qnamedPath);
+ final Module nextModule = context.findModuleByNamespace(childNodeNamespace);
+ schemaNode = findSchemaNodeForGivenPath(context, nextModule, qnamedPath);
return schemaNode;
}
qnamedPath.poll();
if (parentModule != null && prefixedPathPart != null) {
if (prefixedPathPart.contains(":")) {
final String[] prefixedName = prefixedPathPart.split(":");
- final Module module = resolveModuleForPrefix(context, parentModule,
- prefixedName[0]);
+ final Module module = resolveModuleForPrefix(context, parentModule, prefixedName[0]);
if (module != null) {
- return new QName(module.getNamespace(), module
- .getRevision(), prefixedName[1]);
+ return new QName(module.getNamespace(), module.getRevision(), prefixedName[1]);
}
} else {
- return new QName(parentModule.getNamespace(),
- parentModule.getRevision(), prefixedPathPart);
+ return new QName(parentModule.getNamespace(), parentModule.getRevision(), prefixedPathPart);
}
}
return null;
}
- private static Module resolveModuleForPrefix(final SchemaContext context, final Module module,
- final String prefix) {
+ private static Module resolveModuleForPrefix(final SchemaContext context, final Module module, final String prefix) {
if ((module != null) && (prefix != null)) {
if (prefix.equals(module.getPrefix())) {
return module;
for (final ModuleImport mi : imports) {
if (prefix.equals(mi.getPrefix())) {
- return context.findModuleByName(mi.getModuleName(),
- mi.getRevision());
+ return context.findModuleByName(mi.getModuleName(), mi.getRevision());
}
}
}
}
private static Queue<QName> resolveRelativeXPath(final SchemaContext context, final Module module,
- final RevisionAwareXPath relativeXPath,
- final SchemaPath leafrefSchemaPath) {
+ final RevisionAwareXPath relativeXPath, final SchemaPath leafrefSchemaPath) {
final Queue<QName> absolutePath = new LinkedList<>();
- if ((module != null) && (relativeXPath != null) && !relativeXPath.isAbsolute()
- && (leafrefSchemaPath != null)) {
+ if ((module != null) && (relativeXPath != null) && !relativeXPath.isAbsolute() && (leafrefSchemaPath != null)) {
final String strXPath = relativeXPath.toString();
if (strXPath != null) {
final String[] xpaths = strXPath.split("/");
org.slf4j,
org.apache.felix.dm
</Import-Package>
+ <Export-Package>
+ org.opendaylight.controller.sample.simpleforwarding
+ </Export-Package>
<Bundle-Activator>
org.opendaylight.controller.samples.simpleforwarding.internal.Activator
</Bundle-Activator>
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.samples.simpleforwarding.internal;
+package org.opendaylight.controller.samples.simpleforwarding;
import java.io.Serializable;
import org.opendaylight.controller.sal.utils.EtherTypes;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.samples.simpleforwarding.HostNodePair;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.topologymanager.ITopologyManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+
public class SimpleForwardingImpl implements IfNewHostNotify,
IListenRoutingUpdates, IInventoryListener {
private static Logger log = LoggerFactory
import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.utils.NodeCreator;
-import org.opendaylight.controller.samples.simpleforwarding.internal.HostNodePair;
+import org.opendaylight.controller.samples.simpleforwarding.HostNodePair;
+
public class HostSwitchTest {
@Test
public boolean matchNode(String nodeId) {
return this.nodeId.equals(nodeId);
}
+
+ @Override
+ public String toString() {
+ return ("Span Config [nodeId=" + nodeId + " spanPort=" + spanPort + "]");
+ }
}
nodePorts.remove(sp);
}
+ @Override
public String toString() {
return ("Subnet Config [Description=" + name + " Subnet=" + subnet
+ " NodeConnectors=" + nodePorts + "]");
return false;
return true;
}
+
+ @Override
+ public String toString() {
+ return ("Switch Config [Node=" + nodeId + " Description=" + description +
+ " Tier=" + tier + " Mode=" + mode + "]");
+ }
}
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.inventory.IInventoryService;
import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
-import org.opendaylight.controller.sal.utils.HexEncode;
-import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.sal.utils.GlobalConstants;
+import org.opendaylight.controller.sal.utils.HexEncode;
import org.opendaylight.controller.sal.utils.IObjectReader;
import org.opendaylight.controller.sal.utils.ObjectReader;
import org.opendaylight.controller.sal.utils.ObjectWriter;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.switchmanager.ISpanAware;
import org.opendaylight.controller.switchmanager.ISwitchManager;
public void startUp() {
// Initialize configuration file names
- subnetFileName = ROOT + "subnets" + this.getContainerName() + ".conf";
+ subnetFileName = ROOT + "subnets_" + this.getContainerName() + ".conf";
spanFileName = ROOT + "spanPorts_" + this.getContainerName() + ".conf";
switchConfigFileName = ROOT + "switchConfig_" + this.getContainerName()
+ ".conf";
}
public void shutDown() {
- destroyCaches(this.getContainerName());
}
@SuppressWarnings("deprecation")
}
conf.addNodeConnectors(switchPorts);
+ subnetsConfigList.put(name, conf);
// Update Database
Subnet sub = subnets.get(conf.getIPnum());
Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
sub.addNodeConnectors(sp);
+ subnets.put(conf.getIPnum(), sub);
return new Status(StatusCode.SUCCESS, null);
}
return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
}
conf.removeNodeConnectors(switchPorts);
+ subnetsConfigList.put(name, conf);
// Update Database
Subnet sub = subnets.get(conf.getIPnum());
Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
sub.deleteNodeConnectors(sp);
+ subnets.put(conf.getIPnum(), sub);
return new Status(StatusCode.SUCCESS, null);
}
@SuppressWarnings("unchecked")
private void loadSubnetConfiguration() {
ObjectReader objReader = new ObjectReader();
- ConcurrentMap<Integer, SubnetConfig> confList = (ConcurrentMap<Integer, SubnetConfig>) objReader
+ ConcurrentMap<String, SubnetConfig> confList = (ConcurrentMap<String, SubnetConfig>) objReader
.read(this, subnetFileName);
if (confList == null) {
@Override
public void updateSwitchConfig(SwitchConfig cfgObject) {
+ // update default container only
+ if (!isDefaultContainer) {
+ return;
+ }
+
boolean modeChange = false;
SwitchConfig sc = nodeConfigList.get(cfgObject.getNodeId());
nodeConfigList.put(cfgObject.getNodeId(), cfgObject);
try {
- // update default container only
- if (isDefaultContainer) {
- String nodeId = cfgObject.getNodeId();
- Node node = Node.fromString(nodeId);
- Map<String, Property> propMap;
- if (nodeProps.get(node) != null) {
- propMap = nodeProps.get(node);
- } else {
- propMap = new HashMap<String, Property>();
- }
- Property desc = new Description(cfgObject.getNodeDescription());
- propMap.put(desc.getName(), desc);
- Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
- propMap.put(tier.getName(), tier);
- addNodeProps(node, propMap);
+ String nodeId = cfgObject.getNodeId();
+ Node node = Node.fromString(nodeId);
+ Map<String, Property> propMap;
+ if (nodeProps.get(node) != null) {
+ propMap = nodeProps.get(node);
+ } else {
+ propMap = new HashMap<String, Property>();
+ }
+ Property desc = new Description(cfgObject.getNodeDescription());
+ propMap.put(desc.getName(), desc);
+ Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
+ propMap.put(tier.getName(), tier);
+ addNodeProps(node, propMap);
- log.info("Set Node {}'s Mode to {}", nodeId,
- cfgObject.getMode());
+ log.info("Set Node {}'s Mode to {}", nodeId,
+ cfgObject.getMode());
- if (modeChange) {
- notifyModeChange(node, cfgObject.isProactive());
- }
+ if (modeChange) {
+ notifyModeChange(node, cfgObject.isProactive());
}
} catch (Exception e) {
log.debug("updateSwitchConfig: {}", e.getMessage());
addNodeProps(node, null);
}
- // check if span is configed
addSpanPort(nodeConnector);
break;
case REMOVED:
return;
}
- nodeProps = this.inventoryService.getNodeProps();
- Set<Node> nodeSet = nodeProps.keySet();
- if (nodeSet != null) {
- for (Node node : nodeSet) {
- log.debug("getInventories: {} added for container {}",
- new Object[] { node, containerName });
- addNode(node, null);
+ Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
+ for(Map.Entry<Node, Map<String, Property>> entry : nodeProp.entrySet()) {
+ Node node = entry.getKey();
+ log.debug("getInventories: {} added for container {}",
+ new Object[] { node, containerName });
+ Map<String, Property> propMap = entry.getValue();
+ Set<Property> props = new HashSet<Property>();
+ for(Property property : propMap.values()) {
+ props.add(property);
}
+ addNode(node, props);
}
- nodeConnectorProps = inventoryService.getNodeConnectorProps();
+ Map<NodeConnector, Map<String, Property>> nodeConnectorProp = this.inventoryService.getNodeConnectorProps();
+ for(Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProp.entrySet()) {
+ Map<String, Property> propMap = entry.getValue();
+ for(Property property : propMap.values()) {
+ addNodeConnectorProp(entry.getKey(), property);
+ }
+ }
}
private void clearInventories() {
/*
* Add span configuration to local cache and notify clients
*/
- private void addSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
+ private void addSpanPorts(Node node, List<NodeConnector> nodeConnectors) {
List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConncetors) {
+ for (NodeConnector nodeConnector : nodeConnectors) {
if (!spanNodeConnectors.contains(nodeConnector)) {
ncLists.add(nodeConnector);
}
}
}
- private void addSpanPort(NodeConnector nodeConncetor) {
- List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- ncLists.add(nodeConncetor);
- addSpanPorts(nodeConncetor.getNode(), ncLists);
+ private void addSpanPort(NodeConnector nodeConnector) {
+ // only add if span is configured on this nodeConnector
+ for (SpanConfig conf : getSpanConfigList(nodeConnector.getNode())) {
+ if (conf.getPortArrayList().contains(nodeConnector)) {
+ List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
+ ncLists.add(nodeConnector);
+ addSpanPorts(nodeConnector.getNode(), ncLists);
+ return;
+ }
+ }
}
/*
* Remove span configuration to local cache and notify clients
*/
- private void removeSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
+ private void removeSpanPorts(Node node, List<NodeConnector> nodeConnectors) {
List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConncetors) {
+ for (NodeConnector nodeConnector : nodeConnectors) {
if (spanNodeConnectors.contains(nodeConnector)) {
ncLists.add(nodeConnector);
}
}
}
- private void removeSpanPort(NodeConnector nodeConncetor) {
- List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- ncLists.add(nodeConncetor);
- removeSpanPorts(nodeConncetor.getNode(), ncLists);
+ private void removeSpanPort(NodeConnector nodeConnector) {
+ if (spanNodeConnectors.contains(nodeConnector)) {
+ List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
+ ncLists.add(nodeConnector);
+ removeSpanPorts(nodeConnector.getNode(), ncLists);
+ }
}
private void addNodeProps(Node node, Map<String, Property> propMap) {
modal : {
initialize: {
updateNode: function(evt) {
- var nodeId = decodeURIComponent(evt.target.id);
- var h3 = "Update Node Information";
- var footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
- var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.modal, h3, "", footer);
-
- // bind save button
- $('#' + one.f.switchmanager.nodesLearnt.id.modal.save, $modal).click(function() {
- one.f.switchmanager.nodesLearnt.modal.save($modal);
- });
- // inject body (nodePorts)
one.f.switchmanager.nodesLearnt.ajax.main(one.f.switchmanager.rootUrl + "/tiers", function(tiers) {
- var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, evt.target.switchDetails, tiers);
+
+ var nodeId = decodeURIComponent(evt.target.id);
+ var h3;
+ var footer = [];
+ var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, evt.target.switchDetails, tiers);
+ if ( (one.main.registry == undefined || one.main.registry.container == 'default') && evt.target.privilege == 'WRITE'){
+ h3 = "Update Node Information";
+ footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
+ } else { //disable node edit
+ $body.find('*').attr('disabled', 'disabled');
+ h3 = 'Node Information';
+ }
+
+ var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.modal, h3, "", footer);
+ // bind save button
+ $('#' + one.f.switchmanager.nodesLearnt.id.modal.save, $modal).click(function() {
+ one.f.switchmanager.nodesLearnt.modal.save($modal);
+ });
+
+ // inject body (nodePorts)
one.lib.modal.inject.body($modal, $body);
$modal.modal();
});
$select.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.operationMode);
$select.val(switchDetails["mode"]);
$fieldset.append($label).append($select);
-
$form.append($fieldset);
return $form;
},
footer: {
updateNode: function() {
var footer = [];
- if(one.role < 2) {
- var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.nodesLearnt.id.modal.save, "btn-success", "");
- var $saveButton = one.lib.dashlet.button.button(saveButton);
- footer.push($saveButton);
- }
+ var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.nodesLearnt.id.modal.save, "btn-success", "");
+ var $saveButton = one.lib.dashlet.button.button(saveButton);
+ footer.push($saveButton);
+
return footer;
},
popout: function() {
var tr = {};
var entry = [];
var nodenameentry = value["nodeName"] ? value["nodeName"] : "Click to update";
+
// TODO: Move anchor tag creation to one.lib.form.
- var aTag = document.createElement("a");
- aTag.setAttribute("id", encodeURIComponent(value["nodeId"]));
- aTag.switchDetails = value;
- aTag.addEventListener("click", one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
- aTag.addEventListener("mouseover", function(evt) {
- evt.target.style.cursor = "pointer";
- }, false);
+ var aTag;
+ aTag = document.createElement("a");
+ aTag.privilege = data.privilege;
+ aTag.addEventListener("click", one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
+ aTag.addEventListener("mouseover", function(evt) {
+ evt.target.style.cursor = "pointer";
+ }, false);
+ aTag.setAttribute("id", encodeURIComponent(value["nodeId"]));
+ aTag.switchDetails = value;
aTag.innerHTML = nodenameentry;
entry.push(aTag);
entry.push(value["nodeId"]);
one.lib.dashlet.empty($dashlet);
$dashlet.append(one.lib.dashlet.header(one.f.dashlet.subnetGatewayConfig.name));
// Add gateway IP Address button
- if(one.role < 2) {
- var button = one.lib.dashlet.button.single("Add Gateway IP Address",
- one.f.switchmanager.subnetGatewayConfig.id.dashlet.addIPAddress, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
- var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.gateway();
- $modal.modal();
- });
- $dashlet.append($button);
-
-
- // Delete gateway ip address button
- var button = one.lib.dashlet.button.single("Delete Gateway IP Address(es)",
- one.f.switchmanager.subnetGatewayConfig.id.dashlet.removeIPAddress, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
- var requestData = {};
- var gatewaysToDelete = [];
- var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
- checkedCheckBoxes.each(function(index, value) {
- gatewaysToDelete.push(checkedCheckBoxes[index].id);
- });
- if(gatewaysToDelete.length > 0) {
- requestData["gatewaysToDelete"] = gatewaysToDelete.toString();
- var url = one.f.switchmanager.rootUrl + "/subnetGateway/delete";
- one.f.switchmanager.subnetGatewayConfig.ajax.main(url, requestData, function(response) {
- if(response.status == true) {
- // refresh dashlet by passing dashlet div as param
- one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
- } else {
- alert(response.message);
- }
- });
- }
- });
- $dashlet.append($button);
-
- // Add Ports button
- var button = one.lib.dashlet.button.single("Add Ports",
- one.f.switchmanager.subnetGatewayConfig.id.dashlet.addPorts, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
- var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.ports();
- $modal.modal();
- });
- $dashlet.append($button);
- }
var url = one.f.switchmanager.rootUrl + "/subnets";
one.f.switchmanager.subnetGatewayConfig.ajax.main(url, {}, function(content) {
+
+ if (content.privilege === 'WRITE') {
+ var button = one.lib.dashlet.button.single("Add Gateway IP Address",
+ one.f.switchmanager.subnetGatewayConfig.id.dashlet.addIPAddress, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+ var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.gateway();
+ $modal.modal();
+ });
+ $dashlet.append($button);
+
+ // Delete gateway ip address button
+ var button = one.lib.dashlet.button.single("Delete Gateway IP Address(es)",
+ one.f.switchmanager.subnetGatewayConfig.id.dashlet.removeIPAddress, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+ var requestData = {};
+ var gatewaysToDelete = [];
+ var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+ checkedCheckBoxes.each(function(index, value) {
+ gatewaysToDelete.push(checkedCheckBoxes[index].id);
+ });
+ if (gatewaysToDelete.length > 0) {
+ requestData["gatewaysToDelete"] = gatewaysToDelete.toString();
+ var url = one.f.switchmanager.rootUrl + "/subnetGateway/delete";
+ one.f.switchmanager.subnetGatewayConfig.ajax.main(url, requestData, function(response) {
+ if (response.status == true) {
+ // refresh dashlet by passing dashlet div as param
+ one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
+ } else {
+ alert(response.message);
+ }
+ });
+ }
+ });
+ $dashlet.append($button);
+
+ // Add Ports button
+ var button = one.lib.dashlet.button.single("Add Ports",
+ one.f.switchmanager.subnetGatewayConfig.id.dashlet.addPorts, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+ var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.ports();
+ $modal.modal();
+ });
+ $dashlet.append($button);
+ }
+
var body = one.f.switchmanager.subnetGatewayConfig.data.devices(content);
// first column contains checkbox. no need for header
content.columnNames.splice(0,0," ");
},
footer : function() {
var footer = [];
- if(one.role < 2) {
- var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.subnetGatewayConfig.id.modal.save, "btn-success", "");
- var $saveButton = one.lib.dashlet.button.button(saveButton);
- footer.push($saveButton);
- }
+ var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.subnetGatewayConfig.id.modal.save, "btn-success", "");
+ var $saveButton = one.lib.dashlet.button.button(saveButton);
+ footer.push($saveButton);
return footer;
}
},
dashlet: function($dashlet) {
one.lib.dashlet.empty($dashlet);
- if(one.role < 2) {
- // Add static route button
- var button = one.lib.dashlet.button.single("Add Static Route",
- one.f.switchmanager.staticRouteConfig.id.dashlet.add, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
- var $modal = one.f.switchmanager.staticRouteConfig.modal.initialize();
- $modal.modal();
- });
- $dashlet.append(one.lib.dashlet.header(one.f.dashlet.staticRouteConfig.name));
- $dashlet.append($button);
-
- // Delete static route button
- var button = one.lib.dashlet.button.single("Delete Static Route(s)",
- one.f.switchmanager.staticRouteConfig.id.dashlet.remove, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
- var requestData = {};
- var routesToDelete = [];
- var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
- checkedCheckBoxes.each(function(index, value) {
- routesToDelete.push(checkedCheckBoxes[index].id);
- });
- if(routesToDelete.length > 0) {
- requestData["routesToDelete"] = routesToDelete.toString();
- var url = one.f.switchmanager.rootUrl + "/staticRoute/delete";
- one.f.switchmanager.staticRouteConfig.ajax.main(url, requestData, function(response) {
- if(response.status == true) {
- // refresh dashlet by passing dashlet div as param
- one.f.switchmanager.staticRouteConfig.dashlet($("#left-bottom .dashlet"));
- } else {
- alert(response.message);
- }
- });
- }
- });
- $dashlet.append($button);
- }
-
+
var url = one.f.switchmanager.rootUrl + "/staticRoutes";
one.f.switchmanager.staticRouteConfig.ajax.main(url, {}, function(content) {
+
+ if (content.privilege === 'WRITE') {
+ // Add static route button
+ var button = one.lib.dashlet.button.single("Add Static Route", one.f.switchmanager.staticRouteConfig.id.dashlet.add, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+ var $modal = one.f.switchmanager.staticRouteConfig.modal.initialize();
+ $modal.modal();
+ });
+ $dashlet.append(one.lib.dashlet.header(one.f.dashlet.staticRouteConfig.name));
+ $dashlet.append($button);
+
+ // Delete static route button
+ var button = one.lib.dashlet.button.single("Delete Static Route(s)", one.f.switchmanager.staticRouteConfig.id.dashlet.remove, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+ var requestData = {};
+ var routesToDelete = [];
+ var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+ checkedCheckBoxes.each(function(index, value) {
+ routesToDelete.push(checkedCheckBoxes[index].id);
+ });
+ if (routesToDelete.length > 0) {
+ requestData["routesToDelete"] = routesToDelete.toString();
+ var url = one.f.switchmanager.rootUrl + "/staticRoute/delete";
+ one.f.switchmanager.staticRouteConfig.ajax.main(url, requestData, function(response) {
+ if (response.status == true) {
+ // refresh dashlet by passing dashlet div as param
+ one.f.switchmanager.staticRouteConfig.dashlet($("#left-bottom .dashlet"));
+ } else {
+ alert(response.message);
+ }
+ });
+ }
+ });
+ $dashlet.append($button);
+ }
+
var body = one.f.switchmanager.staticRouteConfig.data.staticRouteConfig(content);
// first column contains checkbox. no need for header
content.columnNames.splice(0,0," ");
},
footer : function() {
var footer = [];
- if (one.role < 2) {
- var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.staticRouteConfig.id.modal.save, "btn-success", "");
- var $saveButton = one.lib.dashlet.button.button(saveButton);
- footer.push($saveButton);
- }
+ var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.staticRouteConfig.id.modal.save, "btn-success", "");
+ var $saveButton = one.lib.dashlet.button.button(saveButton);
+ footer.push($saveButton);
return footer;
}
},
},
dashlet: function($dashlet) {
one.lib.dashlet.empty($dashlet);
- if(one.role < 2) {
-
- // Add span port button
- var button = one.lib.dashlet.button.single("Add Span Port", one.f.switchmanager.spanPortConfig.id.dashlet.add, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
-
- $button.click(function() {
- var $modal = one.f.switchmanager.spanPortConfig.modal.initialize();
- $modal.modal();
- });
- $dashlet.append(one.lib.dashlet.header(one.f.dashlet.spanPortConfig.name));
- $dashlet.append($button);
-
- // Delete span port button
- var button = one.lib.dashlet.button.single("Delete SPAN Port(s)",
- one.f.switchmanager.spanPortConfig.id.dashlet.remove, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
- $button.click(function() {
-
- var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
- if(checkedCheckBoxes.length > 0) {
- var spanPortsToDelete = "";
- checkedCheckBoxes.each(function(index, value) {
- spanPortsToDelete += checkedCheckBoxes[index].spanPort + "###";
- });
-
- var requestData = {};
- requestData["spanPortsToDelete"] = spanPortsToDelete;
- var url = one.f.switchmanager.rootUrl + "/spanPorts/delete";
- one.f.switchmanager.spanPortConfig.ajax.main(url, requestData, function(response) {
- if(response.status == true) {
- // refresh dashlet by passing dashlet div as param
- one.f.switchmanager.spanPortConfig.dashlet($("#right-bottom .dashlet"));
- } else {
- alert(response.message);
- }
- });
- }
- });
- $dashlet.append($button);
- }
//populate table in dashlet
var url = one.f.switchmanager.rootUrl + "/spanPorts";
one.f.switchmanager.spanPortConfig.ajax.main(url, {}, function(content) {
+
+ if (content.privilege === 'WRITE') {
+
+ // Add span port button
+ var button = one.lib.dashlet.button.single("Add Span Port", one.f.switchmanager.spanPortConfig.id.dashlet.add, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+
+ $button.click(function() {
+ var $modal = one.f.switchmanager.spanPortConfig.modal.initialize();
+ $modal.modal();
+ });
+ $dashlet.append(one.lib.dashlet.header(one.f.dashlet.spanPortConfig.name));
+ $dashlet.append($button);
+
+ // Delete span port button
+ var button = one.lib.dashlet.button.single("Delete SPAN Port(s)", one.f.switchmanager.spanPortConfig.id.dashlet.remove, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+ $button.click(function() {
+
+ var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+ if (checkedCheckBoxes.length > 0) {
+ var spanPortsToDelete = "";
+ checkedCheckBoxes.each(function(index, value) {
+ spanPortsToDelete += checkedCheckBoxes[index].spanPort + "###";
+ });
+
+ var requestData = {};
+ requestData["spanPortsToDelete"] = spanPortsToDelete;
+ var url = one.f.switchmanager.rootUrl + "/spanPorts/delete";
+ one.f.switchmanager.spanPortConfig.ajax.main(url, requestData, function(response) {
+ if (response.status == true) {
+ // refresh dashlet by passing dashlet div as param
+ one.f.switchmanager.spanPortConfig.dashlet($("#right-bottom .dashlet"));
+ } else {
+ alert(response.message);
+ }
+ });
+ }
+ });
+ $dashlet.append($button);
+ }
+
var body = one.f.switchmanager.spanPortConfig.data.devices(content);
// first column contains the checkbox. no header required.
content.columnNames.splice(0,0," ");
},
footer : function() {
var footer = [];
- if (one.role < 2) {
- var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.spanPortConfig.id.modal.save, "btn-success", "");
- var $saveButton = one.lib.dashlet.button.button(saveButton);
- footer.push($saveButton);
- }
+ var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.spanPortConfig.id.modal.save, "btn-success", "");
+ var $saveButton = one.lib.dashlet.button.button(saveButton);
+ footer.push($saveButton);
return footer;
}
},
@RequestMapping(value = "/main")
@ResponseBody
- public Set<Map<String, Object>> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
+ public Map<String, Object> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+ Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
+ if (privilege == Privilege.NONE) {
return null;
}
// get static flow list
List<FlowConfig> staticFlowList = frm.getStaticFlows();
- Set<Map<String, Object>> output = new HashSet<Map<String, Object>>();
+ Set<Map<String, Object>> flowSet = new HashSet<Map<String, Object>>();
for (FlowConfig flowConfig : staticFlowList) {
Map<String, Object> entry = new HashMap<String, Object>();
entry.put("flow", flowConfig);
entry.put("node", (description.isEmpty() || description
.equalsIgnoreCase("none")) ? node.toString() : description);
entry.put("nodeId", node.toString());
- output.add(entry);
+ flowSet.add(entry);
}
+ Map <String, Object> output = new HashMap<String, Object>(2);
+ output.put("flows", flowSet);
+ output.put("privilege", privilege);
return output;
}
.getDescription();
}
- @RequestMapping(value = "/flow/{nodeId}/{name}", method = RequestMethod.POST)
+ @RequestMapping(value = "/flow/{nodeId}/{name:.*}", method = RequestMethod.POST)
@ResponseBody
public String removeFlow(@PathVariable("nodeId") String nodeId,
@PathVariable("name") String name,
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
dashlet : function($dashlet) {
var $h4 = one.lib.dashlet.header("Nodes");
$dashlet.append($h4);
-
+
// load body
one.f.nodes.ajax.dashlet(function($table) {
// total nodes count
dashlet : function(body, callback) {
var attributes = ['table-striped', 'table-bordered', 'table-hover', 'table-condensed'];
var $table = one.lib.dashlet.table.table(attributes);
-
+
var headers = ['Node', 'Flows'];
var $thead = one.lib.dashlet.table.header(headers);
$table.append($thead);
-
+
var $tbody = one.lib.dashlet.table.body(body);
$table.append($tbody);
-
+
return $table;
}
}
dashlet : function($dashlet, details) {
var $h4 = one.lib.dashlet.header("Flow Details");
$dashlet.append($h4);
-
+
// details
if (details == undefined) {
var $none = $(document.createElement('div'));
var $p = $(document.createElement('p'));
$p.text('Please select a flow');
$p.addClass('text-center').addClass('text-info');
-
+
$dashlet.append($none)
.append($p);
}
},
registry : {},
dashlet : function($dashlet, callback) {
- var $h4 = one.lib.dashlet.header("Flow Entries");
-
- if (one.role < 2) {
- var button = one.lib.dashlet.button.single("Add Flow Entry", one.f.flows.id.dashlet.add, "btn-primary", "btn-mini");
- var $button = one.lib.dashlet.button.button(button);
-
- $button.click(function() {
- var $modal = one.f.flows.modal.initialize();
- $modal.modal();
- });
- }
-
- $dashlet.append($h4);
- if (one.role < 2) $dashlet.append($button);
-
+
// load body
one.f.flows.ajax.dashlet(function($table) {
+
+ var $h4 = one.lib.dashlet.header("Flow Entries");
+
+ $dashlet.append($h4);
+ if (one.f.flows.registry.privilege === 'WRITE') {
+ var button = one.lib.dashlet.button.single("Add Flow Entry", one.f.flows.id.dashlet.add, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+
+ $button.click(function() {
+ var $modal = one.f.flows.modal.initialize();
+ $modal.modal();
+ });
+ $dashlet.append($button);
+
+ }
+
+ // table bindings
+ $table.find('tbody').find('tr').click(function() {
+ var id = $($(this).find('td')[0]).text();
+ var node = $(this).data('id');
+ one.f.flows.detail(id, node);
+ });
+
// total flows
var flowCount = $table.find('tbody').find('tr').size();
// prompt output
$p = $(document.createElement('p'));
$p.append(out);
$dashlet.append($p);
- // table bindings
- $table.find('tbody').find('tr').click(function() {
- var id = $($(this).find('td')[0]).text();
- var node = $(this).data('id');
- one.f.flows.detail(id, node);
- });
- // add to dashlet
+ // add table to dashlet
$dashlet.append($table);
// details callback
if(callback != undefined) callback();
$detailDashlet.empty();
var $h4 = one.lib.dashlet.header("Flow Overview");
$detailDashlet.append($h4);
-
+
// details
var flows = one.f.flows.registry.flows;
var flow;
flow = value;
}
});
- if (one.role < 2) {
+ if (one.f.flows.registry.privilege === 'WRITE') {
// remove button
var button = one.lib.dashlet.button.single("Remove Flow", one.f.flows.id.dashlet.remove, "btn-danger", "btn-mini");
var $button = one.lib.dashlet.button.button(button);
});
// toggle button
var toggle;
- if (flow['flow']['installInHw'] == 'true') {
+ if (flow['flow']['installInHw'] == 'true' && flow['flow']['status'] == 'Success') {
toggle = one.lib.dashlet.button.single("Uninstall Flow", one.f.flows.id.dashlet.toggle, "btn-warning", "btn-mini");
} else {
toggle = one.lib.dashlet.button.single("Install Flow", one.f.flows.id.dashlet.toggle, "btn-success", "btn-mini");
}
});
});
+
+ $detailDashlet.append($button).append($toggle);
}
// append details
var body = one.f.detail.data.dashlet(flow);
var $body = one.f.detail.body.dashlet(body);
- if (one.role < 2) $detailDashlet.append($button).append($toggle);
$detailDashlet.append($body);
var body = one.f.detail.data.description(flow);
var $body = one.f.detail.body.description(body);
},
footer : function() {
var footer = [];
-
+
var removeButton = one.lib.dashlet.button.single("Remove Flow", one.f.flows.id.modal.dialog.remove, "btn-danger", "");
var $removeButton = one.lib.dashlet.button.button(removeButton);
footer.push($removeButton);
-
+
var closeButton = one.lib.dashlet.button.single("Cancel", one.f.flows.id.modal.dialog.close, "", "");
var $closeButton = one.lib.dashlet.button.button(closeButton);
footer.push($closeButton);
-
+
return footer;
},
body : function(id) {
var h3 = "Add Flow Entry";
var footer = one.f.flows.modal.footer();
var $modal = one.lib.modal.spawn(one.f.flows.id.modal.modal, h3, "", footer);
-
+
// bind close button
$('#'+one.f.flows.id.modal.close, $modal).click(function() {
$modal.modal('hide');
});
-
+
// bind add flow button
$('#'+one.f.flows.id.modal.add, $modal).click(function() {
one.f.flows.modal.add($modal, 'false');
$('#'+one.f.flows.id.modal.install, $modal).click(function() {
one.f.flows.modal.add($modal, 'true');
});
-
+
// inject body (nodePorts)
one.f.flows.modal.ajax.nodes(function(nodes, nodeports) {
var $body = one.f.flows.modal.body(nodes, nodeports);
one.lib.modal.inject.body($modal, $body);
});
-
+
return $modal;
},
add : function($modal, install) {
var result = {};
-
+
result['name'] = $('#'+one.f.flows.id.modal.form.name, $modal).val();
result['ingressPort'] = $('#'+one.f.flows.id.modal.form.port, $modal).val();
result['priority'] = $('#'+one.f.flows.id.modal.form.priority, $modal).val();
result['installInHw'] = install;
var nodeId = $('#'+one.f.flows.id.modal.form.nodes, $modal).val();
-
+
$.each(result, function(key, value) {
if (value == "") delete result[key];
});
-
+
var action = [];
var $table = $('#'+one.f.flows.id.modal.action.table, $modal);
$($table.find('tbody').find('tr')).each(function(index, value) {
}
});
result['actions'] = action;
-
+
// frontend validation
if (result['name'] == undefined) {
alert('Need flow name');
alert('Please specify an action');
return;
}
-
+
// package for ajax call
var resource = {};
resource['body'] = JSON.stringify(result);
resource['action'] = 'add';
resource['nodeId'] = nodeId;
-
+
one.f.flows.modal.ajax.saveflow(resource, function(data) {
if (data == "Success") {
$modal.modal('hide');
var nodes = one.f.flows.modal.data.nodes(data);
var nodeports = data;
one.f.flows.registry['nodeports'] = nodeports;
-
+
successCallback(nodes, nodeports);
});
},
one.lib.form.select.prepend($select, { '' : 'Please Select a Node' });
$select.val($select.find("option:first").val());
$select.attr('id', one.f.flows.id.modal.form.nodes);
-
+
// bind onchange
$select.change(function() {
// retrieve port value
one.f.flows.modal.action.parse(action.attr('value'));
$select[0].selectedIndex = 0;
});
-
+
$fieldset.append($select).append($table);
-
+
// return
$form.append($fieldset);
return $form;
var addButton = one.lib.dashlet.button.single("Add Action", one.f.flows.id.modal.action.add, "btn-primary", "");
var $addButton = one.lib.dashlet.button.button(addButton);
footer.push($addButton);
-
+
var closeButton = one.lib.dashlet.button.single("Close", one.f.flows.id.modal.action.close, "", "");
var $closeButton = one.lib.dashlet.button.button(closeButton);
footer.push($closeButton);
-
+
return footer;
}
},
var installButton = one.lib.dashlet.button.single("Install Flow", one.f.flows.id.modal.install, "btn-success", "");
var $installButton = one.lib.dashlet.button.button(installButton);
footer.push($installButton);
-
+
var addButton = one.lib.dashlet.button.single("Save Flow", one.f.flows.id.modal.add, "btn-primary", "");
var $addButton = one.lib.dashlet.button.button(addButton);
footer.push($addButton);
-
+
var closeButton = one.lib.dashlet.button.single("Close", one.f.flows.id.modal.close, "", "");
var $closeButton = one.lib.dashlet.button.button(closeButton);
footer.push($closeButton);
-
+
return footer;
}
},
ajax : {
dashlet : function(callback) {
$.getJSON(one.f.address.root+one.f.address.flows.main, function(data) {
- one.f.flows.registry['flows'] = data;
- var body = one.f.flows.data.dashlet(data);
+ one.f.flows.registry['flows'] = data.flows;
+ one.f.flows.registry['privilege'] = data.privilege;
+ var body = one.f.flows.data.dashlet(data.flows);
var $body = one.f.flows.body.dashlet(body, callback);
callback($body);
});
var entry = [];
entry.push(value['name']);
entry.push(value['node']);
- if (value['flow']['installInHw'] == 'true')
+ if (value['flow']['installInHw'] == 'true' && value['flow']['status'] == 'Success')
tr['type'] = ['success'];
- else if (value['flow']['installInHw'] == 'false')
+ else if (value['flow']['installInHw'] == 'false' && value['flow']['status'] == 'Success')
+ tr['type'] = ['warning'];
+ else
tr['type'] = ['warning'];
tr['entry'] = entry;
tr['id'] = value['nodeId'];
-
+
body.push(tr);
});
return body;
dashlet : function(body, callback) {
var attributes = ['table-striped', 'table-bordered', 'table-hover', 'table-condensed', 'table-cursor'];
var $table = one.lib.dashlet.table.table(attributes);
-
+
var headers = ['Flow Name', 'Node'];
var $thead = one.lib.dashlet.table.header(headers);
$table.append($thead);
-
+
var $tbody = one.lib.dashlet.table.body(body);
$table.append($tbody);
-
+
return $table;
}
}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
+ <button type="button" class="help" aria-hidden="true"
+ >?</button>
<h3></h3>
</div>
<div class="modal-body"></div>
.table-cursor tr:hover {
cursor: pointer;
}
+
+// hide
+.modal {
+ .help {
+ display: none;
+ }
+}
\ No newline at end of file