Merge "Updated example with OF model done during HackFest."
authorGiovanni Meo <gmeo@cisco.com>
Mon, 10 Jun 2013 15:24:04 +0000 (15:24 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 10 Jun 2013 15:24:04 +0000 (15:24 +0000)
43 files changed:
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java
opendaylight/forwardingrulesmanager/api/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNextHop.java [new file with mode: 0644]
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NetUtils.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/utils/NetUtilsTest.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTestIT.java [moved from opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTest.java with 96% similarity]
opendaylight/sal/yang-prototype/code-generator/samples/maven-code-gen-sample/pom.xml
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserListenerImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/ParserUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/TypesResolutionTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EnumerationType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Leafref.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java
opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/TopologyUserLinkConfig.java
opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java
opendaylight/topologymanager/src/test/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImplTest.java

index f3429e62b181f155897ac7dc9034e355ac7d5d1f..77c1c859c601993a4c904099d4082a0d9ae4fa8d 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.controller.sal.action.Output;
 import org.opendaylight.controller.sal.action.PopVlan;
 import org.opendaylight.controller.sal.action.SetDlDst;
 import org.opendaylight.controller.sal.action.SetDlSrc;
+import org.opendaylight.controller.sal.action.SetNextHop;
 import org.opendaylight.controller.sal.action.SetNwDst;
 import org.opendaylight.controller.sal.action.SetNwSrc;
 import org.opendaylight.controller.sal.action.SetNwTos;
@@ -124,27 +125,6 @@ public class FlowConfig implements Serializable {
         ANY, V4, V6;
     };
 
-    private enum SetNextHopType {
-        CISCO_EXTENSION("Cisco NextHop Extension"), RESOLVE_L2RW(
-                "Resolve L2 Rewrite");
-
-        private SetNextHopType(String name) {
-            this.name = name;
-        }
-
-        private String name;
-
-        public String toString() {
-            return name;
-        }
-
-        public boolean equals(String type) {
-            if (type.trim().equalsIgnoreCase(name))
-                return true;
-            return false;
-        }
-    }
-
     public FlowConfig() {
     }
 
@@ -473,163 +453,160 @@ public class FlowConfig implements Serializable {
 
     @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;
+        }
         FlowConfig other = (FlowConfig) 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 (cookie == null) {
-            if (other.cookie != null)
+            if (other.cookie != null) {
                 return false;
-        } else if (!cookie.equals(other.cookie))
+            }
+        } else if (!cookie.equals(other.cookie)) {
             return false;
+        }
         if (dlDst == null) {
-            if (other.dlDst != null)
+            if (other.dlDst != null) {
                 return false;
-        } else if (!dlDst.equals(other.dlDst))
+            }
+        } else if (!dlDst.equals(other.dlDst)) {
             return false;
+        }
         if (dlSrc == null) {
-            if (other.dlSrc != null)
+            if (other.dlSrc != null) {
                 return false;
-        } else if (!dlSrc.equals(other.dlSrc))
+            }
+        } else if (!dlSrc.equals(other.dlSrc)) {
             return false;
-        if (dynamic != other.dynamic)
+        }
+        if (dynamic != other.dynamic) {
             return false;
+        }
         if (etherType == null) {
-            if (other.etherType != null)
+            if (other.etherType != null) {
                 return false;
-        } else if (!etherType.equals(other.etherType))
+            }
+        } else if (!etherType.equals(other.etherType)) {
             return false;
+        }
         if (ingressPort == null) {
-            if (other.ingressPort != null)
+            if (other.ingressPort != null) {
                 return false;
-        } else if (!ingressPort.equals(other.ingressPort))
+            }
+        } else if (!ingressPort.equals(other.ingressPort)) {
             return false;
+        }
         if (name == null) {
-            if (other.name != null)
+            if (other.name != null) {
                 return false;
-        } else if (!name.equals(other.name))
+            }
+        } else if (!name.equals(other.name)) {
             return false;
+        }
         if (nwDst == null) {
-            if (other.nwDst != null)
+            if (other.nwDst != null) {
                 return false;
-        } else if (!nwDst.equals(other.nwDst))
+            }
+        } else if (!nwDst.equals(other.nwDst)) {
             return false;
+        }
         if (nwSrc == null) {
-            if (other.nwSrc != null)
+            if (other.nwSrc != null) {
                 return false;
-        } else if (!nwSrc.equals(other.nwSrc))
+            }
+        } else if (!nwSrc.equals(other.nwSrc)) {
             return false;
+        }
         if (portGroup == null) {
-            if (other.portGroup != null)
+            if (other.portGroup != null) {
                 return false;
-        } else if (!portGroup.equals(other.portGroup))
+            }
+        } else if (!portGroup.equals(other.portGroup)) {
             return false;
+        }
         if (priority == null) {
-            if (other.priority != null)
+            if (other.priority != null) {
                 return false;
-        } else if (!priority.equals(other.priority))
+            }
+        } else if (!priority.equals(other.priority)) {
             return false;
+        }
         if (protocol == null) {
-            if (other.protocol != null)
+            if (other.protocol != null) {
                 return false;
-        } else if (!protocol.equals(other.protocol))
+            }
+        } else if (!protocol.equals(other.protocol)) {
             return false;
+        }
         if (node == null) {
-            if (other.node != null)
+            if (other.node != null) {
                 return false;
-        } else if (!node.equals(other.node))
+            }
+        } else if (!node.equals(other.node)) {
             return false;
+        }
         if (tosBits == null) {
-            if (other.tosBits != null)
+            if (other.tosBits != null) {
                 return false;
-        } else if (!tosBits.equals(other.tosBits))
+            }
+        } else if (!tosBits.equals(other.tosBits)) {
             return false;
+        }
         if (tpDst == null) {
-            if (other.tpDst != null)
+            if (other.tpDst != null) {
                 return false;
-        } else if (!tpDst.equals(other.tpDst))
+            }
+        } else if (!tpDst.equals(other.tpDst)) {
             return false;
+        }
         if (tpSrc == null) {
-            if (other.tpSrc != null)
+            if (other.tpSrc != null) {
                 return false;
-        } else if (!tpSrc.equals(other.tpSrc))
+            }
+        } else if (!tpSrc.equals(other.tpSrc)) {
             return false;
+        }
         if (vlanId == null) {
-            if (other.vlanId != null)
+            if (other.vlanId != null) {
                 return false;
-        } else if (!vlanId.equals(other.vlanId))
+            }
+        } else if (!vlanId.equals(other.vlanId)) {
             return false;
+        }
         if (vlanPriority == null) {
-            if (other.vlanPriority != null)
+            if (other.vlanPriority != null) {
                 return false;
-        } else if (!vlanPriority.equals(other.vlanPriority))
+            }
+        } else if (!vlanPriority.equals(other.vlanPriority)) {
             return false;
+        }
         if (idleTimeout == null) {
-            if (other.idleTimeout != null)
+            if (other.idleTimeout != null) {
                 return false;
-        } else if (!idleTimeout.equals(other.idleTimeout))
+            }
+        } else if (!idleTimeout.equals(other.idleTimeout)) {
             return false;
+        }
         if (hardTimeout == null) {
-            if (other.hardTimeout != null)
+            if (other.hardTimeout != null) {
                 return false;
-        } else if (!hardTimeout.equals(other.hardTimeout))
-            return false;
-        return true;
-    }
-
-    public InetAddress getNextHopAddressForL2RWAction() {
-        if (actions != null) {
-            Matcher sstr;
-            for (String actiongrp : actions) {
-                sstr = Pattern.compile("SET_NEXT_HOP=(.*)").matcher(actiongrp);
-                if (sstr.matches()) {
-                    SetNextHopType setNHType = SetNextHopType.CISCO_EXTENSION;
-                    String nextHopInfo = sstr.group(1);
-                    String values[] = nextHopInfo.split("//");
-                    String address = values[0].trim();
-                    String type = null;
-                    if (values.length > 1) {
-                        type = values[1].trim();
-                    }
-
-                    if (type != null) {
-                        for (SetNextHopType nh : SetNextHopType.values()) {
-                            if (nh.equals(type))
-                                setNHType = nh;
-                        }
-                    }
-
-                    log.debug("Get Nexthop address = {} Type = {}", address,
-                            setNHType.toString());
-                    if (setNHType == SetNextHopType.RESOLVE_L2RW) {
-                        try {
-                            return InetAddress.getByName(address);
-                        } catch (Exception e) {
-                            log.debug(
-                                    "Exception during nextHopAddress resolution : ",
-                                    e);
-                        }
-                    }
-                }
             }
+        } else if (!hardTimeout.equals(other.hardTimeout)) {
+            return false;
         }
-        return null;
-    }
-
-    public String getNextHopL2RWUsageError() {
-        return "Could not resolve NextHop IP Address for the selected Switch.<br>"
-                + "Please Check the following configurations.<br>"
-                + "1. Is the NextHop IP address directly connected to the Selected Switch<br>"
-                + "2. If appropriate Subnet Configurations are done in the Switch Manager<br>"
-                + "3. If the Nexthop IP-Address is Correct";
+        return true;
     }
 
     public boolean isL2AddressValid(String mac) {
@@ -772,8 +749,9 @@ public class FlowConfig implements Serializable {
             }
 
             // make sure it's a valid number
-            if (cookie != null)
+            if (cookie != null) {
                 Long.decode(cookie);
+            }
 
             if (ingressPort != null) {
                 Short port = Short.decode(ingressPort);
@@ -812,10 +790,11 @@ public class FlowConfig implements Serializable {
                             "Ethernet type %s is not valid", etherType));
                     return false;
                 } else {
-                    if (type == 0x800)
+                    if (type == 0x800) {
                         etype = EtherIPType.V4;
-                    else if (type == 0x86dd)
+                    } else if (type == 0x86dd) {
                         etype = EtherIPType.V6;
+                    }
                 }
             }
 
@@ -1084,13 +1063,10 @@ public class FlowConfig implements Serializable {
                             ActionType.SET_NEXT_HOP.toString() + "=(.*)")
                             .matcher(actiongrp);
                     if (sstr.matches()) {
-                        String nextHopInfo = sstr.group(1);
-                        String values[] = nextHopInfo.split("//");
-                        String address = values[0].trim();
-
-                        if ((address == null) || !isOutputNextHopValid(address)) {
+                        if (!NetUtils.isIPAddressValid(sstr.group(1))) {
                             resultStr.append(String.format(
-                                    "next hop %s is not valid", sstr.group(1)));
+                                    "IP destination address %s is not valid",
+                                    sstr.group(1)));
                             return false;
                         }
                         continue;
@@ -1198,17 +1174,6 @@ public class FlowConfig implements Serializable {
         return flow;
     }
 
-    public boolean isOutputNextHopValid(String onh) {
-        if (onh == null) {
-            return false;
-        }
-        /*
-         * For now, only takes IPv4 or IPv6 address
-         */
-        return (NetUtils.isIPv4AddressValid(onh) || NetUtils
-                .isIPv6AddressValid(onh));
-    }
-
     public boolean isByNameAndNodeIdEqual(FlowConfig that) {
         return (this.name.equals(that.name) && this.node.equals(that.node));
     }
@@ -1221,14 +1186,6 @@ public class FlowConfig implements Serializable {
         return this.node.equals(node);
     }
 
-    public static List<String> getSupportedNextHopTypes() {
-        List<String> s = new ArrayList<String>();
-        for (SetNextHopType nh : SetNextHopType.values()) {
-            s.add(nh.toString());
-        }
-        return s;
-    }
-
     public void toggleStatus() {
         installInHw = (installInHw == null) ? "true" : (installInHw
                 .equals("true")) ? "false" : "true";
@@ -1393,7 +1350,8 @@ public class FlowConfig implements Serializable {
                         ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(
                         actiongrp);
                 if (sstr.matches()) {
-                    log.warn("We do not handle next hop action yet....");
+                    actionList.add(new SetNextHop(NetUtils.parseInetAddress(sstr
+                            .group(1))));
                     continue;
                 }
             }
index 0b11d13f3cdb582634e912d2a681f77298531b4b..34337ba42b625443b3a7587171325ee331dbe2be 100644 (file)
@@ -339,21 +339,6 @@ public class frmTest {
 
     }
 
-    @Test
-    public void testFlowConfigNextHopValidity() throws UnknownHostException {
-        FlowConfig fc = new FlowConfig();
-        Assert.assertFalse(fc.isOutputNextHopValid(null));
-        Assert.assertFalse(fc.isOutputNextHopValid("abc"));
-        Assert.assertFalse(fc.isOutputNextHopValid("1.1.1"));
-        Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49"));
-
-        Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1"));
-        Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32"));
-        Assert.assertTrue(fc
-                .isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355"));
-
-    }
-
     @Test
     public void testFlowConfigEqualities() throws UnknownHostException {
         FlowConfig fc = new FlowConfig();
index 074774a25e2e8c295801c5ae9763f4661ba6a79c..8d3a1be20339b866b4165ad305f20aef2629d371 100644 (file)
@@ -100,7 +100,7 @@ public class FlowConverter {
     /**
      * Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions
      * form (V6Match)
-     * 
+     *
      * @return
      */
     public OFMatch getOFMatch() {
@@ -177,7 +177,7 @@ public class FlowConverter {
                  * actually the DSCP field followed by a zero ECN
                  */
                 byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue();
-                byte dscp = (byte) ((int) tos << 2);
+                byte dscp = (byte) (tos << 2);
                 if (!isIPv6) {
                     ofMatch.setNetworkTypeOfService(dscp);
                     wildcards &= ~OFMatch.OFPFW_NW_TOS;
@@ -262,7 +262,7 @@ public class FlowConverter {
 
     /**
      * Returns the list of actions in OF 1.0 form
-     * 
+     *
      * @return
      */
     public List<OFAction> getOFActions() {
@@ -411,7 +411,7 @@ public class FlowConverter {
                     continue;
                 }
                 if (action.getType() == ActionType.SET_NEXT_HOP) {
-                    // TODO
+                    logger.info("Unsupported action: {}", action);
                     continue;
                 }
             }
@@ -424,7 +424,7 @@ public class FlowConverter {
     /**
      * Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or to an OF 1.0 +
      * IPv6 extension (V6FlowMod) Flow modifier Message
-     * 
+     *
      * @param sw
      * @param command
      * @param port
@@ -505,7 +505,7 @@ public class FlowConverter {
                     if (ofMatch.getInputPort() != 0) {
                         salMatch.setField(new MatchField(MatchType.IN_PORT,
                                 NodeConnectorCreator.createNodeConnector(
-                                        (Short) ofMatch.getInputPort(), node)));
+                                        ofMatch.getInputPort(), node)));
                     }
                     if (ofMatch.getDataLayerSource() != null
                             && !NetUtils
@@ -560,11 +560,11 @@ public class FlowConverter {
                     }
                     if (ofMatch.getTransportSource() != 0) {
                         salMatch.setField(MatchType.TP_SRC,
-                                ((Short) ofMatch.getTransportSource()));
+                                ofMatch.getTransportSource());
                     }
                     if (ofMatch.getTransportDestination() != 0) {
                         salMatch.setField(MatchType.TP_DST,
-                                ((Short) ofMatch.getTransportDestination()));
+                                ofMatch.getTransportDestination());
                     }
                 } else {
                     // Compute OF1.0 + IPv6 extensions Match
@@ -573,7 +573,7 @@ public class FlowConverter {
                         // Mask on input port is not defined
                         salMatch.setField(new MatchField(MatchType.IN_PORT,
                                 NodeConnectorCreator.createOFNodeConnector(
-                                        (Short) v6Match.getInputPort(), node)));
+                                        v6Match.getInputPort(), node)));
                     }
                     if (v6Match.getDataLayerSource() != null
                             && !NetUtils
@@ -623,11 +623,11 @@ public class FlowConverter {
                     }
                     if (v6Match.getTransportSource() != 0) {
                         salMatch.setField(MatchType.TP_SRC,
-                                ((Short) v6Match.getTransportSource()));
+                                (v6Match.getTransportSource()));
                     }
                     if (v6Match.getTransportDestination() != 0) {
                         salMatch.setField(MatchType.TP_DST,
-                                ((Short) v6Match.getTransportDestination()));
+                                (v6Match.getTransportDestination()));
                     }
                 }
             }
index 7a2ace5bae6008e0262b06755d1e70bec668219f..ec6ea1223e71f6103fcfef6aecb655c1108e6179 100644 (file)
@@ -23,16 +23,11 @@ import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider;
 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
-import org.opendaylight.controller.sal.core.Actions;
-import org.opendaylight.controller.sal.core.Buffers;
-import org.opendaylight.controller.sal.core.Capabilities;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.Node.NodeIDType;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.Tables;
-import org.opendaylight.controller.sal.core.TimeStamp;
 import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
@@ -151,44 +146,6 @@ public class InventoryService implements IInventoryShimInternalListener,
      */
     @Override
     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
-        if (nodeProps == null)
-            return null;
-        Map<Long, ISwitch> switches = controller.getSwitches();
-        for (Map.Entry<Long, ISwitch> entry : switches.entrySet()) {
-            ISwitch sw = entry.getValue();
-            Node node = OFSwitchToNode(sw);
-            Map<String, Property> propMap = null;
-            if (isDefaultContainer) {
-                propMap = new HashMap<String, Property>();
-                byte tables = sw.getTables();
-                Tables t = new Tables(tables);
-                if (t != null) {
-                    propMap.put(Tables.TablesPropName, t);
-                }
-                int cap = sw.getCapabilities();
-                Capabilities c = new Capabilities(cap);
-                if (c != null) {
-                    propMap.put(Capabilities.CapabilitiesPropName, c);
-                }
-                int act = sw.getActions();
-                Actions a = new Actions(act);
-                if (a != null) {
-                    propMap.put(Actions.ActionsPropName, a);
-                }
-                int buffers = sw.getBuffers();
-                Buffers b = new Buffers(buffers);
-                if (b != null) {
-                    propMap.put(Buffers.BuffersPropName, b);
-                }
-                Date connectedSince = sw.getConnectedDate();
-                Long connectedSinceTime = (connectedSince == null) ? 0
-                        : connectedSince.getTime();
-                TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
-                        "connectedSince");
-                propMap.put(TimeStamp.TimeStampPropName, timeStamp);
-                nodeProps.put(node, propMap);
-            }
-        }
         return nodeProps;
     }
 
diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNextHop.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNextHop.java
new file mode 100644 (file)
index 0000000..33d9b93
--- /dev/null
@@ -0,0 +1,64 @@
+package org.opendaylight.controller.sal.action;
+
+import java.net.InetAddress;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class SetNextHop extends Action {
+    @XmlElement
+    private InetAddress address;
+
+    /* Dummy constructor for JAXB */
+    @SuppressWarnings("unused")
+    private SetNextHop() {
+    }
+
+    public SetNextHop(InetAddress address) {
+        type = ActionType.SET_NEXT_HOP;
+        this.address = address;
+    }
+
+    public InetAddress getAddress() {
+        return address;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((address == null) ? 0 : address.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        SetNextHop other = (SetNextHop) obj;
+        if (address == null) {
+            if (other.address != null) {
+                return false;
+            }
+        } else if (!address.equals(other.address)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return type + "[" + address.toString() + "]";
+    }
+}
index 691ddc93561bc0359858fa778b9e83d73b3cf2e3..2591d931e1d70e5084531c464f8c2b8c5209317f 100644 (file)
@@ -40,10 +40,11 @@ public abstract class NetUtils {
      * @return     the integer number
      */
     public static int byteArray4ToInt(byte[] ba) {
-        if (ba == null || ba.length != 4)
+        if (ba == null || ba.length != 4) {
             return 0;
-        return (int) ((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]);
     }
 
     /**
@@ -131,7 +132,7 @@ public abstract class NetUtils {
             int intMask = 0;
             int numBytes = prefixMask.length;
             for (int i = 0; i < numBytes; i++) {
-                intMask |= ((int) prefixMask[i] & 0xff) << (8 * (numBytes - 1 - i));
+                intMask |= (prefixMask[i] & 0xff) << (8 * (numBytes - 1 - i));
             }
 
             int bit = 1;
@@ -219,13 +220,13 @@ public abstract class NetUtils {
         if (isAny(testAddress) || isAny(filterAddress)) {
             return false;
         }
-        
+
         int testMaskLen = (testMask != null) ? NetUtils.getSubnetMaskLength(testMask.getAddress()) : 0;
         int filterMaskLen = (filterMask != null) ? NetUtils.getSubnetMaskLength(filterMask.getAddress()) : 0;
-        
+
         int testPrefixLen = (testAddress instanceof Inet6Address) ? (128 - testMaskLen) : (32 - testMaskLen);
         int filterPrefixLen = (filterAddress instanceof Inet6Address) ? (128 - filterMaskLen) : (32 - filterMaskLen);
-        
+
         // Mask length check. Test mask has to be more specific than filter one
         if (testPrefixLen < filterPrefixLen) {
             return true;
@@ -292,8 +293,9 @@ public abstract class NetUtils {
      * @return
      */
     public static boolean isIPv4AddressValid(String cidr) {
-        if (cidr == null)
+        if (cidr == null) {
             return false;
+        }
 
         String values[] = cidr.split("/");
         Pattern ipv4Pattern = Pattern
@@ -319,8 +321,9 @@ public abstract class NetUtils {
      * @return
      */
     public static boolean isIPv6AddressValid(String cidr) {
-        if (cidr == null)
+        if (cidr == null) {
             return false;
+        }
 
         String values[] = cidr.split("/");
         try {
@@ -341,29 +344,42 @@ public abstract class NetUtils {
         }
         return true;
     }
-    
+
+    /**
+     * Checks if the passed IP address in string form is a valid v4 or v6
+     * address. The address may specify a mask at the end as "/MMM"
+     *
+     * @param cidr
+     *            the v4 or v6 address as IP/MMM
+     * @return
+     */
+    public static boolean isIPAddressValid(String cidr) {
+        return NetUtils.isIPv4AddressValid(cidr)
+                || NetUtils.isIPv6AddressValid(cidr);
+    }
+
     /*
-     * Following utilities are useful when you need to 
+     * 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
      * @return the int variable containing the unsigned byte value
      */
     public static int getUnsignedByte(byte b) {
-               return (b > 0)? (int)b : ((int)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
      * @return the int variable containing the unsigned short value
      */
        public static int getUnsignedShort(short s) {
-               return (s > 0)? (int)s : ((int)s & 0x7FFF | 0x8000);
+               return (s > 0)? (int)s : (s & 0x7FFF | 0x8000);
        }
 }
index 6858494283a2ec6cf0ee0e56e57d88d5a3ce5960..4fd59790034d413034f7c4209e473c357f2aefa7 100644 (file)
@@ -156,7 +156,7 @@ public class ActionTest {
         try {
             ip = InetAddress.getByName("2001:420:281:1003:f2de:f1ff:fe71:728d");
         } catch (UnknownHostException e) {
-            logger.error("",e);
+            logger.error("", e);
         }
         action = new SetNwSrc(ip);
         Assert.assertTrue(action.isValid());
@@ -172,7 +172,7 @@ public class ActionTest {
 
         action = new SetNwTos(0x40);
         Assert.assertFalse(action.isValid());
-        
+
         action = new SetNwTos(0xff1);
         Assert.assertFalse(action.isValid());
 
@@ -206,6 +206,29 @@ public class ActionTest {
         Assert.assertFalse(action.isValid());
     }
 
+    @Test
+    public void testNextHopActionCreation() {
+        SetNextHop action = null;
+
+        InetAddress ip = null;
+        try {
+            ip = InetAddress.getByName("171.71.9.52");
+        } catch (UnknownHostException e) {
+            logger.error("", e);
+        }
+
+        action = new SetNextHop(ip);
+        Assert.assertTrue(action.getAddress().equals(ip));
+
+        try {
+            ip = InetAddress.getByName("2001:420:281:1003:f2de:f1ff:fe71:728d");
+        } catch (UnknownHostException e) {
+            logger.error("", e);
+        }
+        action = new SetNextHop(ip);
+        Assert.assertTrue(action.getAddress().equals(ip));
+    }
+
     @Test
     public void testActionList() {
         List<Action> actions = new ArrayList<Action>();
index 2d16afbd3d8fd6161922c092c212ae84722f9920..599f97448a4ce4e4d504542f9ae7df6347442789 100644 (file)
@@ -273,7 +273,7 @@ public class NetUtilsTest {
                 .isIPv6AddressValid("fe80:::0:0:0:204:61ff:fe9d/-1")); //not valid both
 
     }
-    
+
     @Test
     public void testInetAddressConflict() throws UnknownHostException {
 
@@ -318,4 +318,17 @@ public class NetUtilsTest {
                 InetAddress.getByName("255.255.0.0")));
 
     }
+
+    @Test
+    public void testIPAddressValidity() {
+        Assert.assertFalse(NetUtils.isIPAddressValid(null));
+        Assert.assertFalse(NetUtils.isIPAddressValid("abc"));
+        Assert.assertFalse(NetUtils.isIPAddressValid("1.1.1"));
+        Assert.assertFalse(NetUtils.isIPAddressValid("1.1.1.1/49"));
+
+        Assert.assertTrue(NetUtils.isIPAddressValid("1.1.1.1"));
+        Assert.assertTrue(NetUtils.isIPAddressValid("1.1.1.1/32"));
+        Assert.assertTrue(NetUtils
+                .isIPAddressValid("2001:420:281:1004:407a:57f4:4d15:c355"));
+    }
 }
index 896827ee45414e0d0b2d0dd8b621f296ac583444..8d846a13e60f3efa658eb56a08590c264edc5ed3 100644 (file)
             <scope>test</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>2.6</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>
\ No newline at end of file
@@ -16,7 +16,7 @@ import org.apache.maven.it.VerificationException;
 import org.apache.maven.it.Verifier;
 import org.junit.Test;
 
-public class YangToSourcesPluginTest {
+public class YangToSourcesPluginTestIT {
 
     // TODO Test yang files in transitive dependencies
 
@@ -112,7 +112,7 @@ public class YangToSourcesPluginTest {
 
     @Test
     public void testNoOutputDir() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/", false);
+        Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false);
         verifyCorrectLog(v);
     }
 
@@ -126,7 +126,7 @@ public class YangToSourcesPluginTest {
         v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang");
         v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang");
 
-        Verifier v2 = YangToSourcesPluginTest.setUp("GenerateTest2/", false);
+        Verifier v2 = YangToSourcesPluginTestIT.setUp("GenerateTest2/", false);
         v2.executeGoal("clean");
         v2.executeGoal("package");
         v2.assertFilePresent("target/classes/META-INF/yang/private.yang");
index 03a2e8588e6d5e908b7bf32286d38614b5e0838a..b1bcb062b81632ec4c9a101c9783bf17ba664b54 100644 (file)
@@ -31,8 +31,7 @@
                                     </outputBaseDir>
                                 </generator>
                             </codeGenerators>
-                            <resourceProviders>
-                            </resourceProviders>
+                            <inspectDependencies>false</inspectDependencies>
                         </configuration>
                     </execution>
                 </executions>
index 25af3ebae5f47f9cb875b7a91af8de512c217bf3..401189b1d1efbb11a79801c9837fb1053f1f226d 100644 (file)
@@ -49,6 +49,7 @@ 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.model.util.YangTypesConverter;
 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;
@@ -552,11 +553,16 @@ public final class YangParserImpl implements YangModelParser {
             constraints.addPatterns(patterns);
             fractionDigits = ext.getFractionDigits();
             constraints.setFractionDigits(fractionDigits);
-            return findConstraints(
-                    findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
-                            ext.getQName().getLocalName(), builder.getName(),
-                            nodeToResolve.getLine()), constraints, modules,
-                    builder);
+            if(YangTypesConverter.isBaseYangType(ext.getBaseType().getQName().getLocalName())) {
+                mergeConstraints(ext.getBaseType(), constraints);
+                return constraints;
+            } else {
+                return findConstraints(
+                        findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
+                                ext.getQName().getLocalName(), builder.getName(),
+                                nodeToResolve.getLine()), constraints, modules,
+                        builder);
+            }
         } else if (referencedType instanceof UnknownType) {
             final UnknownType unknown = (UnknownType) referencedType;
             ranges = unknown.getRangeStatements();
index 8b739098a067f3fbd0144963b0cce0600e091045..d7394e62291db2ca98e6be896cc551a4b800e08e 100644 (file)
@@ -356,10 +356,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                             getIdentityrefBase(typeBody), actualPath, path,
                             line);
                 } else {
-                    List<String> typePath = new ArrayList<String>(actualPath);
-                    typePath.add(typeName);
-
-                    type = parseTypeBody(typeName, typeBody, typePath,
+                    type = parseTypeBody(typeName, typeBody, actualPath,
                             namespace, revision, yangModelPrefix);
                     moduleBuilder.setType(type, actualPath);
                 }
index 2e3f0cc860ba80d22cef4d01b33b47d531626e10..e95a162de763811d1d9ead81d32df43aeb599827 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.yang.parser.util;
 
 import java.lang.reflect.Method;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -28,9 +27,6 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition
 import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
-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;
 import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
@@ -198,30 +194,22 @@ public final class ParserUtils {
                 newSchemaPath = createNewSchemaPath(parentSchemaPath,
                         nodeQName, binType.getQName());
                 List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
-                result = new BinaryType(newSchemaPath, bytes,
-                        binType.getLengthConstraints(), binType.getUnits());
+                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(),
-                        bitsType.getUnits());
+                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,
-                        (Boolean) booleanType.getDefaultValue(),
-                        booleanType.getUnits());
+                result = new BooleanType(newSchemaPath);
             } else if (nodeType instanceof DecimalTypeDefinition) {
                 DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
                 newSchemaPath = createNewSchemaPath(parentSchemaPath,
                         nodeQName, decimalType.getQName());
-                BigDecimal defaultValue = (BigDecimal) decimalType
-                        .getDefaultValue();
-                result = new Decimal64(newSchemaPath, decimalType.getUnits(),
-                        defaultValue, decimalType.getRangeStatements(),
-                        decimalType.getFractionDigits());
+                result = new Decimal64(newSchemaPath, decimalType.getFractionDigits());
             } else if (nodeType instanceof EmptyTypeDefinition) {
                 newSchemaPath = createNewSchemaPath(parentSchemaPath,
                         nodeQName, nodeType.getQName());
@@ -232,7 +220,7 @@ public final class ParserUtils {
                         nodeQName, enumType.getQName());
                 result = new EnumerationType(newSchemaPath,
                         (EnumPair) enumType.getDefaultValue(),
-                        enumType.getValues(), enumType.getUnits());
+                        enumType.getValues());
             } else if (nodeType instanceof IdentityrefTypeDefinition) {
                 IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
                 newSchemaPath = createNewSchemaPath(parentSchemaPath,
@@ -247,13 +235,13 @@ public final class ParserUtils {
                         instIdType.getPathStatement(),
                         instIdType.requireInstance());
             } else if (nodeType instanceof StringTypeDefinition) {
-                result = copyStringType(parentSchemaPath, nodeQName,
+                result = createNewStringType(parentSchemaPath, nodeQName,
                         (StringTypeDefinition) nodeType);
             } else if (nodeType instanceof IntegerTypeDefinition) {
-                result = copyIntType(parentSchemaPath, nodeQName,
+                result = createNewIntType(parentSchemaPath, nodeQName,
                         (IntegerTypeDefinition) nodeType);
             } else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
-                result = copyUIntType(parentSchemaPath, nodeQName,
+                result = createNewUintType(parentSchemaPath, nodeQName,
                         (UnsignedIntegerTypeDefinition) nodeType);
             } else if (nodeType instanceof LeafrefTypeDefinition) {
                 newSchemaPath = createNewSchemaPath(parentSchemaPath,
@@ -270,7 +258,7 @@ public final class ParserUtils {
         return result;
     }
 
-    private static TypeDefinition<?> copyStringType(SchemaPath schemaPath,
+    private static TypeDefinition<?> createNewStringType(SchemaPath schemaPath,
             QName nodeQName, StringTypeDefinition nodeType) {
         List<QName> path = schemaPath.getPath();
         List<QName> newPath = new ArrayList<QName>(path);
@@ -279,64 +267,44 @@ public final class ParserUtils {
         SchemaPath newSchemaPath = new SchemaPath(newPath,
                 schemaPath.isAbsolute());
 
-        String newDefault = nodeType.getDefaultValue().toString();
-        String newUnits = nodeType.getUnits();
-        List<LengthConstraint> lengths = nodeType.getLengthStatements();
-        List<PatternConstraint> patterns = nodeType.getPatterns();
-
-        return new StringType(newSchemaPath, newDefault, lengths, patterns,
-                newUnits);
+        return new StringType(newSchemaPath);
     }
 
-    private static TypeDefinition<?> copyIntType(SchemaPath schemaPath,
+    private static TypeDefinition<?> createNewIntType(SchemaPath schemaPath,
             QName nodeQName, IntegerTypeDefinition type) {
         QName typeQName = type.getQName();
         SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
                 typeQName);
-
         String localName = typeQName.getLocalName();
-        List<RangeConstraint> ranges = type.getRangeStatements();
-        String units = type.getUnits();
 
         if ("int8".equals(localName)) {
-            Byte defaultValue = (Byte) type.getDefaultValue();
-            return new Int8(newSchemaPath, ranges, units, defaultValue);
+            return new Int8(newSchemaPath);
         } else if ("int16".equals(localName)) {
-            Short defaultValue = (Short) type.getDefaultValue();
-            return new Int16(newSchemaPath, ranges, units, defaultValue);
+            return new Int16(newSchemaPath);
         } else if ("int32".equals(localName)) {
-            Integer defaultValue = (Integer) type.getDefaultValue();
-            return new Int32(newSchemaPath, ranges, units, defaultValue);
+            return new Int32(newSchemaPath);
         } else if ("int64".equals(localName)) {
-            Long defaultValue = (Long) type.getDefaultValue();
-            return new Int64(newSchemaPath, ranges, units, defaultValue);
+            return new Int64(newSchemaPath);
         } else {
             return null;
         }
     }
 
-    private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath,
+    private static TypeDefinition<?> createNewUintType(SchemaPath schemaPath,
             QName nodeQName, UnsignedIntegerTypeDefinition type) {
         QName typeQName = type.getQName();
         SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
                 typeQName);
-
         String localName = typeQName.getLocalName();
-        List<RangeConstraint> ranges = type.getRangeStatements();
-        String units = type.getUnits();
 
         if ("uint8".equals(localName)) {
-            Byte defaultValue = (Byte) type.getDefaultValue();
-            return new Int8(newSchemaPath, ranges, units, defaultValue);
+            return new Int8(newSchemaPath);
         } else if ("uint16".equals(localName)) {
-            Short defaultValue = (Short) type.getDefaultValue();
-            return new Int16(newSchemaPath, ranges, units, defaultValue);
+            return new Int16(newSchemaPath);
         } else if ("uint32".equals(localName)) {
-            Integer defaultValue = (Integer) type.getDefaultValue();
-            return new Int32(newSchemaPath, ranges, units, defaultValue);
+            return new Int32(newSchemaPath);
         } else if ("uint64".equals(localName)) {
-            Long defaultValue = (Long) type.getDefaultValue();
-            return new Int64(newSchemaPath, ranges, units, defaultValue);
+            return new Int64(newSchemaPath);
         } else {
             return null;
         }
index e63f12839dfa8d4d883806bccf6f5e226d45a5bc..f58ee740cfe4a274840098716be91a430265e70d 100644 (file)
@@ -84,10 +84,12 @@ 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;
 import org.opendaylight.controller.yang.model.util.BaseConstraints;
+import org.opendaylight.controller.yang.model.util.BaseTypes;
 import org.opendaylight.controller.yang.model.util.BinaryType;
 import org.opendaylight.controller.yang.model.util.BitsType;
 import org.opendaylight.controller.yang.model.util.Decimal64;
 import org.opendaylight.controller.yang.model.util.EnumerationType;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.InstanceIdentifier;
 import org.opendaylight.controller.yang.model.util.Int16;
 import org.opendaylight.controller.yang.model.util.Int32;
@@ -999,7 +1001,7 @@ public final class YangModelBuilderUtil {
             final Type_body_stmtsContext typeBody,
             final List<String> actualPath, final URI namespace,
             final Date revision, final String prefix) {
-        TypeDefinition<?> type = null;
+        TypeDefinition<?> baseType = null;
 
         List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
         Integer fractionDigits = getFractionDigits(typeBody);
@@ -1008,53 +1010,115 @@ public final class YangModelBuilderUtil {
         List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(
                 typeBody, actualPath, namespace, revision, prefix);
 
-        SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace,
-                revision, prefix);
+        SchemaPath baseTypePathFinal = createTypeSchemaPath(actualPath,
+                namespace, revision, prefix, typeName, true, true);
+        SchemaPath baseTypePath = createTypeSchemaPath(actualPath,
+                namespace, revision, prefix, typeName, true, false);
 
         if ("decimal64".equals(typeName)) {
-            type = new Decimal64(schemaPath, fractionDigits);
+            if (rangeStatements.isEmpty()) {
+                return new Decimal64(baseTypePathFinal, fractionDigits);
+            }
+            baseType = new Decimal64(baseTypePath, fractionDigits);
         } else if (typeName.startsWith("int")) {
             if ("int8".equals(typeName)) {
-                type = new Int8(schemaPath, rangeStatements, null, null);
+                baseType = new Int8(baseTypePath);
             } else if ("int16".equals(typeName)) {
-                type = new Int16(schemaPath, rangeStatements, null, null);
+                baseType = new Int16(baseTypePath);
             } else if ("int32".equals(typeName)) {
-                type = new Int32(schemaPath, rangeStatements, null, null);
+                baseType = new Int32(baseTypePath);
             } else if ("int64".equals(typeName)) {
-                type = new Int64(schemaPath, rangeStatements, null, null);
+                baseType = new Int64(baseTypePath);
             }
         } else if (typeName.startsWith("uint")) {
             if ("uint8".equals(typeName)) {
-                type = new Uint8(schemaPath, rangeStatements, null, null);
+                baseType = new Uint8(baseTypePath);
             } else if ("uint16".equals(typeName)) {
-                type = new Uint16(schemaPath, rangeStatements, null, null);
+                baseType = new Uint16(baseTypePath);
             } else if ("uint32".equals(typeName)) {
-                type = new Uint32(schemaPath, rangeStatements, null, null);
+                baseType = new Uint32(baseTypePath);
             } else if ("uint64".equals(typeName)) {
-                type = new Uint64(schemaPath, rangeStatements, null, null);
+                baseType = new Uint64(baseTypePath);
             }
         } else if ("enumeration".equals(typeName)) {
-            type = new EnumerationType(schemaPath, enumConstants);
+            return new EnumerationType(baseTypePathFinal, enumConstants);
         } else if ("string".equals(typeName)) {
-            type = new StringType(schemaPath, lengthStatements,
-                    patternStatements);
+            baseType = new StringType(baseTypePath);
         } else if ("bits".equals(typeName)) {
-            type = new BitsType(schemaPath, getBits(typeBody, actualPath,
-                    namespace, revision, prefix));
+            return new BitsType(baseTypePathFinal, getBits(typeBody,
+                    actualPath, namespace, revision, prefix));
         } else if ("leafref".equals(typeName)) {
             final String path = parseLeafrefPath(typeBody);
             final boolean absolute = path.startsWith("/");
             RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path,
                     absolute);
-            type = new Leafref(schemaPath, xpath);
+            return new Leafref(baseTypePathFinal, xpath);
         } else if ("binary".equals(typeName)) {
-            List<Byte> bytes = Collections.emptyList();
-            type = new BinaryType(schemaPath, bytes, lengthStatements, null);
+            baseType = new BinaryType(baseTypePath);
         } else if ("instance-identifier".equals(typeName)) {
             boolean requireInstance = isRequireInstance(typeBody);
-            type = new InstanceIdentifier(schemaPath, null, requireInstance);
+            baseType = new InstanceIdentifier(baseTypePath, null,
+                    requireInstance);
         }
-        return type;
+
+        TypeDefinition<?> result = null;
+        QName qname = new QName(namespace, revision, prefix, typeName);
+        ExtendedType.Builder typeBuilder = null;
+
+        SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace,
+                revision, prefix, typeName, false, false);
+        typeBuilder = new ExtendedType.Builder(qname, baseType, "", "",
+                schemaPath);
+
+        typeBuilder.ranges(rangeStatements);
+        typeBuilder.lengths(lengthStatements);
+        typeBuilder.patterns(patternStatements);
+        typeBuilder.fractionDigits(fractionDigits);
+
+        result = typeBuilder.build();
+        return result;
+    }
+
+    /**
+     * Create SchemaPath object from given path list with namespace, revision
+     * and prefix based on given values.
+     *
+     * @param actualPath
+     *            current position in model
+     * @param namespace
+     * @param revision
+     * @param prefix
+     * @param typeName
+     * @param isBaseYangType
+     *            if this is base yang type
+     * @param isBaseYangTypeFinal
+     *            if this is base yang type without restrictions
+     * @return SchemaPath object.
+     */
+    private static SchemaPath createTypeSchemaPath(
+            final List<String> actualPath, final URI namespace,
+            final Date revision, final String prefix, final String typeName,
+            final boolean isBaseYangType, final boolean isBaseYangTypeFinal) {
+        List<String> typePath = new ArrayList<String>(actualPath);
+        if (isBaseYangType && !isBaseYangTypeFinal) {
+            typePath.add(typeName);
+        }
+
+        final List<QName> path = new ArrayList<QName>();
+        QName qname;
+        // start from index 1 -> module name omited
+        for (int i = 1; i < typePath.size(); i++) {
+            qname = new QName(namespace, revision, prefix, typePath.get(i));
+            path.add(qname);
+        }
+        QName typeQName;
+        if (isBaseYangType) {
+            typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);
+        } else {
+            typeQName = new QName(namespace, revision, prefix, typeName);
+        }
+        path.add(typeQName);
+        return new SchemaPath(path, true);
     }
 
     /**
index 36c98c36e2a3928cded65ecdbad0ec11b850f2a4..461cc4b5c28522d675851bb417563f2baaa91830 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.controller.yang.model.util.EnumerationType;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.IdentityrefType;
 import org.opendaylight.controller.yang.model.util.InstanceIdentifier;
-import org.opendaylight.controller.yang.model.util.StringType;
 import org.opendaylight.controller.yang.model.util.UnionType;
 
 public class TypesResolutionTest {
@@ -123,7 +122,7 @@ public class TypesResolutionTest {
         List<TypeDefinition<?>> unionTypes = baseType.getTypes();
 
         ExtendedType ipv4 = (ExtendedType) unionTypes.get(0);
-        StringType ipv4Base = (StringType) ipv4.getBaseType();
+        ExtendedType ipv4Base = (ExtendedType) ipv4.getBaseType();
         String expectedPattern = "(([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}]+)?";
@@ -131,7 +130,7 @@ public class TypesResolutionTest {
                 .getRegularExpression());
 
         ExtendedType ipv6 = (ExtendedType) unionTypes.get(1);
-        StringType ipv6Base = (StringType) ipv6.getBaseType();
+        ExtendedType ipv6Base = (ExtendedType) ipv6.getBaseType();
         List<PatternConstraint> ipv6Patterns = ipv6Base.getPatterns();
         expectedPattern = "((:|[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}))|"
@@ -152,7 +151,7 @@ public class TypesResolutionTest {
         Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "domain-name");
-        StringType baseType = (StringType) type.getBaseType();
+        ExtendedType baseType = (ExtendedType) type.getBaseType();
         List<PatternConstraint> patterns = baseType.getPatterns();
         assertEquals(1, patterns.size());
         String expectedPattern = "((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
@@ -160,9 +159,9 @@ public class TypesResolutionTest {
                 + "|\\.";
         assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
 
-        List<LengthConstraint> lengths = baseType.getLengthStatements();
+        List<LengthConstraint> lengths = baseType.getLengths();
         assertEquals(1, lengths.size());
-        LengthConstraint length = baseType.getLengthStatements().get(0);
+        LengthConstraint length = baseType.getLengths().get(0);
         assertEquals(1L, length.getMin());
         assertEquals(253L, length.getMax());
     }
@@ -173,8 +172,9 @@ public class TypesResolutionTest {
                 .findModule(testedModules, "custom-types-test");
         LeafSchemaNode leaf = (LeafSchemaNode) tested
                 .getDataChildByName("inst-id-leaf1");
-        InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
-        assertFalse(leafType.requireInstance());
+        ExtendedType leafType = (ExtendedType) leaf.getType();
+        InstanceIdentifier leafTypeBase = (InstanceIdentifier)leafType.getBaseType();
+        assertFalse(leafTypeBase.requireInstance());
     }
 
     @Test
index fd2593ba4805fade12bb2193e7a3d4cf94a5b097..23bb4a41d2f25fc16c501f06ed9d65b316206d53 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.*;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.text.DateFormat;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -56,12 +57,15 @@ import org.opendaylight.controller.yang.model.util.Decimal64;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.Int16;
 import org.opendaylight.controller.yang.model.util.Int32;
+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.Uint32;
 import org.opendaylight.controller.yang.model.util.UnionType;
 
 public class YangParserTest {
+    private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
     private Set<Module> modules;
 
     @Before
@@ -198,6 +202,55 @@ public class YangParserTest {
         assertTrue(ifMtu.getType() instanceof Int32);
     }
 
+    @Test
+    public void testParseLeaf() throws ParseException {
+        Module test = TestUtils.findModule(modules, "types2");
+
+        // leaf if-name
+        LeafSchemaNode ifName = (LeafSchemaNode) test
+                .getDataChildByName("if-name");
+        Leafref ifNameType = (Leafref)ifName.getType();
+        QName qname = ifNameType.getQName();
+
+        URI baseYangTypeNS = URI.create("urn:ietf:params:xml:ns:yang:1");
+        assertEquals(baseYangTypeNS, qname.getNamespace());
+        assertNull(qname.getRevision());
+        assertEquals("", qname.getPrefix());
+        assertEquals("leafref", qname.getLocalName());
+
+        // leaf name
+        LeafSchemaNode name = (LeafSchemaNode) test
+                .getDataChildByName("name");
+        StringType nameType = (StringType)name.getType();
+        QName nameQName = nameType.getQName();
+
+        assertEquals(baseYangTypeNS, nameQName.getNamespace());
+        assertNull(nameQName.getRevision());
+        assertEquals("", nameQName.getPrefix());
+        assertEquals("string", nameQName.getLocalName());
+
+        // leaf count
+        LeafSchemaNode count = (LeafSchemaNode) test
+                .getDataChildByName("count");
+        ExtendedType countType = (ExtendedType)count.getType();
+        QName countTypeQName = countType.getQName();
+
+        URI expectedNS = URI.create("urn:simple.types.data.demo");
+        Date expectedDate = simpleDateFormat.parse("2013-02-27");
+        assertEquals(expectedNS, countTypeQName.getNamespace());
+        assertEquals(expectedDate, countTypeQName.getRevision());
+        assertEquals("t2", countTypeQName.getPrefix());
+        assertEquals("int8", countTypeQName.getLocalName());
+
+        Int8 countTypeBase = (Int8)countType.getBaseType();
+        QName countTypeBaseQName = countTypeBase.getQName();
+
+        assertEquals(baseYangTypeNS, countTypeBaseQName.getNamespace());
+        assertNull(countTypeBaseQName.getRevision());
+        assertEquals("", countTypeBaseQName.getPrefix());
+        assertEquals("int8", countTypeBaseQName.getLocalName());
+    }
+
     @Test
     public void testAugmentResolving() {
         // testfile1
@@ -371,8 +424,14 @@ public class YangParserTest {
         ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
         assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
 
-        Int32 int32base = (Int32) baseType.getBaseType();
-        List<RangeConstraint> ranges = int32base.getRangeStatements();
+        ExtendedType int32Type = (ExtendedType) baseType.getBaseType();
+        Int32 int32TypeBase = (Int32)int32Type.getBaseType();
+        QName qname = int32TypeBase.getQName();
+        assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), qname.getNamespace());
+        assertNull(qname.getRevision());
+        assertEquals("", qname.getPrefix());
+        assertEquals("int32", qname.getLocalName());
+        List<RangeConstraint> ranges = int32Type.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(2L, range.getMin());
@@ -419,14 +478,14 @@ public class YangParserTest {
         UnionType unionBase = (UnionType) baseType.getBaseType();
 
         List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
-        Int16 unionType1 = (Int16) unionTypes.get(0);
-        List<RangeConstraint> ranges = unionType1.getRangeStatements();
+        ExtendedType unionType1 = (ExtendedType) unionTypes.get(0);
+        List<RangeConstraint> ranges = unionType1.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(1L, range.getMin());
         assertEquals(100L, range.getMax());
 
-        assertTrue(unionTypes.get(0) instanceof Int16);
+        assertTrue(unionType1.getBaseType() instanceof Int16);
         assertTrue(unionTypes.get(1) instanceof Int32);
     }
 
@@ -458,11 +517,12 @@ public class YangParserTest {
                 .getBaseType();
         List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion
                 .getTypes();
-        assertTrue(extendedTargetTypes.get(0) instanceof Int16);
+        assertTrue(extendedTargetTypes.get(0).getBaseType() instanceof Int16);
         assertTrue(extendedTargetTypes.get(1) instanceof Int32);
 
-        Int16 int16 = (Int16) extendedTargetTypes.get(0);
-        List<RangeConstraint> ranges = int16.getRangeStatements();
+        ExtendedType int16 = (ExtendedType) extendedTargetTypes.get(0);
+        assertTrue(int16.getBaseType() instanceof Int16);
+        List<RangeConstraint> ranges = int16.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(1L, range.getMin());
@@ -536,10 +596,10 @@ public class YangParserTest {
         UnionType myUnionBase = (UnionType) myUnion.getBaseType();
         List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
         assertEquals(2, myUnionBaseTypes.size());
-        assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
+        assertTrue(myUnionBaseTypes.get(0).getBaseType() instanceof Int16);
         assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
-        Int16 int16 = (Int16) myUnionBaseTypes.get(0);
-        List<RangeConstraint> ranges = int16.getRangeStatements();
+        ExtendedType int16 = (ExtendedType) myUnionBaseTypes.get(0);
+        List<RangeConstraint> ranges = int16.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(1L, range.getMin());
@@ -770,7 +830,6 @@ public class YangParserTest {
 
     @Test
     public void testAugmentNodesTypesSchemaPath() throws Exception {
-        final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         Module testModule = TestUtils.findModule(modules, "types1");
         Set<AugmentationSchema> augments = testModule.getAugmentations();
         assertEquals(1, augments.size());
@@ -807,4 +866,93 @@ public class YangParserTest {
         assertEquals(q3, higherLayerTypePath.get(3));
     }
 
+    @Test
+    public void testTypePath() throws ParseException {
+        Module test = TestUtils.findModule(modules, "types2");
+        Set<TypeDefinition<?>> types = test.getTypeDefinitions();
+
+        // my-base-int32-type
+        ExtendedType int32Typedef = (ExtendedType)TestUtils.findTypedef(types, "my-base-int32-type");
+        QName int32TypedefQName = int32Typedef.getQName();
+
+        URI expectedNS = URI.create("urn:simple.types.data.demo");
+        Date expectedDate = simpleDateFormat.parse("2013-02-27");
+        assertEquals(expectedNS, int32TypedefQName.getNamespace());
+        assertEquals(expectedDate, int32TypedefQName.getRevision());
+        assertEquals("t2", int32TypedefQName.getPrefix());
+        assertEquals("my-base-int32-type", int32TypedefQName.getLocalName());
+
+        SchemaPath typeSchemaPath = int32Typedef.getPath();
+        List<QName> typePath = typeSchemaPath.getPath();
+        assertEquals(1, typePath.size());
+        assertEquals(int32TypedefQName, typePath.get(0));
+
+        // my-base-int32-type/int32
+        ExtendedType int32Ext = (ExtendedType)int32Typedef.getBaseType();
+        QName int32ExtQName = int32Ext.getQName();
+
+        assertEquals(expectedNS, int32ExtQName.getNamespace());
+        assertEquals(expectedDate, int32ExtQName.getRevision());
+        assertEquals("t2", int32ExtQName.getPrefix());
+        assertEquals("int32", int32ExtQName.getLocalName());
+
+        SchemaPath int32ExtSchemaPath = int32Ext.getPath();
+        List<QName> int32ExtPath = int32ExtSchemaPath.getPath();
+        assertEquals(2, int32ExtPath.size());
+        assertEquals(int32TypedefQName, int32ExtPath.get(0));
+        assertEquals(int32ExtQName, int32ExtPath.get(1));
+
+        // my-base-int32-type/int32/int32
+        Int32 int32 = (Int32)int32Ext.getBaseType();
+        QName int32QName = int32.getQName();
+        assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), int32QName.getNamespace());
+        assertNull(int32QName.getRevision());
+        assertEquals("", int32QName.getPrefix());
+        assertEquals("int32", int32QName.getLocalName());
+
+        SchemaPath int32SchemaPath = int32.getPath();
+        List<QName> int32Path = int32SchemaPath.getPath();
+        assertEquals(3, int32Path.size());
+        assertEquals(int32TypedefQName, int32Path.get(0));
+        assertEquals(int32ExtQName, int32Path.get(1));
+        assertEquals(int32QName, int32Path.get(2));
+    }
+
+    @Test
+    public void testTypePath2() throws ParseException {
+        Module test = TestUtils.findModule(modules, "types2");
+        Set<TypeDefinition<?>> types = test.getTypeDefinitions();
+
+        // my-base-int32-type
+        ExtendedType myDecType = (ExtendedType)TestUtils.findTypedef(types, "my-decimal-type");
+        QName myDecTypeQName = myDecType.getQName();
+
+        URI expectedNS = URI.create("urn:simple.types.data.demo");
+        Date expectedDate = simpleDateFormat.parse("2013-02-27");
+        assertEquals(expectedNS, myDecTypeQName.getNamespace());
+        assertEquals(expectedDate, myDecTypeQName.getRevision());
+        assertEquals("t2", myDecTypeQName.getPrefix());
+        assertEquals("my-decimal-type", myDecTypeQName.getLocalName());
+
+        SchemaPath typeSchemaPath = myDecType.getPath();
+        List<QName> typePath = typeSchemaPath.getPath();
+        assertEquals(1, typePath.size());
+        assertEquals(myDecTypeQName, typePath.get(0));
+
+        // my-base-int32-type/int32
+        Decimal64 dec64 = (Decimal64)myDecType.getBaseType();
+        QName dec64QName = dec64.getQName();
+
+        assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), dec64QName.getNamespace());
+        assertNull(dec64QName.getRevision());
+        assertEquals("", dec64QName.getPrefix());
+        assertEquals("decimal64", dec64QName.getLocalName());
+
+        SchemaPath dec64SchemaPath = dec64.getPath();
+        List<QName> dec64Path = dec64SchemaPath.getPath();
+        assertEquals(2, dec64Path.size());
+        assertEquals(myDecTypeQName, dec64Path.get(0));
+        assertEquals(dec64QName, dec64Path.get(1));
+    }
+
 }
index 8860e06622fee0d1128649f3386a392138d35aa2..904c8e66fd2c3d8dd8ad9dc2f32588604ffc867f 100644 (file)
@@ -114,6 +114,12 @@ module types2 {
     leaf name {
         type string;
     }
+    
+    leaf count {
+        type int8 {
+            range "1..10";
+        }
+    }
      
     leaf nested-type-leaf {
         type my-type1;
index 0af3c81c6ac3e570c716a3376cf3549d8f3f16fe..baefbf40fe97d413a377a25fc9ba5ebe4e159d94 100644 (file)
@@ -35,29 +35,13 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
-
     private final QName name;
     private final SchemaPath path;
     private final String description;
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
-    protected AbstractSignedInteger(final QName name, final String description,
-            final Number minRange, final Number maxRange, final String units) {
-        this.name = name;
-        this.description = description;
-        this.path = BaseTypes.schemaPath(name);
-        this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
-        final String rangeDescription = "Integer values between " + minRange
-                + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
-                maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
-    }
-
     /**
      * @param name
      * @param description
index 013d80d79911c127ef4f3823a2fc996bf70c044f..6d5b5be8a0378dfa27fee06687e6174c860a1078 100644 (file)
@@ -36,25 +36,9 @@ public abstract class AbstractUnsignedInteger implements
     private final SchemaPath path;
     private final String description;
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
-    protected AbstractUnsignedInteger(final QName name,
-            final String description, final Number minRange,
-            final Number maxRange, final String units) {
-        this.name = name;
-        this.description = description;
-        this.path = BaseTypes.schemaPath(name);
-        this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
-        final String rangeDescription = "Integer values between " + minRange
-                + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
-                maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
-    }
-
     /**
      *
      * @param actualPath
index 74214dc0c77973a9f5b07777ea77d0735c33f9fc..ea09b65b5daa1382847faff9a4429eadee79d5fd 100644 (file)
@@ -24,65 +24,33 @@ import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
  * @see BinaryTypeDefinition
  */
 public final class BinaryType implements BinaryTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("binary");
     private final SchemaPath path;
     private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
     private final BinaryTypeDefinition baseType;
-    private List<Byte> bytes;
+    private final List<Byte> bytes;
     private final List<LengthConstraint> lengthConstraints;
-    private String units = "";
-
-    private BinaryType() {
-        super();
+    private final String units = "";
 
+    public BinaryType(final SchemaPath path) {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
                 ""));
         this.lengthConstraints = Collections.unmodifiableList(constraints);
         this.bytes = Collections.emptyList();
-        this.path = BaseTypes.schemaPath(name);
+        this.path = path;
         this.baseType = this;
     }
 
-    public BinaryType(final SchemaPath path) {
-        super();
-
+    public BinaryType(final SchemaPath path, final List<Byte> bytes) {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
                 ""));
         this.lengthConstraints = Collections.unmodifiableList(constraints);
-        this.bytes = Collections.emptyList();
-        this.path = path;
-        this.baseType = new BinaryType();
-    }
-
-    /**
-     *
-     *
-     * @param bytes
-     * @param lengthConstraints
-     * @param units
-     */
-    public BinaryType(final SchemaPath path, final List<Byte> bytes,
-            final List<LengthConstraint> lengthConstraints, final String units) {
-        super();
-
-        if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE,
-                    "", ""));
-            this.lengthConstraints = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthConstraints = Collections
-                    .unmodifiableList(lengthConstraints);
-        }
-
-        this.path = path;
         this.bytes = Collections.unmodifiableList(bytes);
-        this.units = units;
-        this.baseType = new BinaryType();
+        this.path = path;
+        this.baseType = this;
     }
 
     /*
index 51e0306e8b8737c1e7450c6fe60a8767b6c43280..94391d2288eace0dc4b6d9265d97ee06893e2dcb 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
  * @see BitsTypeDefinition
  */
 public final class BitsType implements BitsTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("bits");
     private final SchemaPath path;
     private final String description = "The bits built-in type represents a bit set.  "
@@ -32,24 +31,17 @@ public final class BitsType implements BitsTypeDefinition {
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
     private final BitsTypeDefinition baseType;
     private final List<Bit> bits;
-    private String units = "";
+    private final String units = "";
 
     /**
      * Default constructor. <br>
      * Instantiates Bits type as empty bits list.
      */
-    private BitsType() {
-        super();
-        this.bits = Collections.emptyList();
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public BitsType(final SchemaPath path) {
         super();
         this.bits = Collections.emptyList();
         this.path = path;
-        this.baseType = new BitsType();
+        this.baseType = this;
     }
 
     /**
@@ -64,27 +56,8 @@ public final class BitsType implements BitsTypeDefinition {
     public BitsType(final SchemaPath path, final List<Bit> bits) {
         super();
         this.bits = Collections.unmodifiableList(bits);
-        this.units = "";
-        this.path = path;
-        this.baseType = new BitsType();
-    }
-
-    /**
-     * Constructor with explicit definition of bits assigned to BitsType and
-     * Units. <br>
-     * The default value of Bits Type is List of bits.
-     *
-     * @param bits
-     *            The bits assigned for Bits Type
-     * @param units
-     *            units for bits type
-     */
-    public BitsType(final SchemaPath path, List<Bit> bits, String units) {
-        super();
-        this.bits = Collections.unmodifiableList(bits);
-        this.units = units;
         this.path = path;
-        this.baseType = new BitsType();
+        this.baseType = this;
     }
 
     /*
index 0cda67c27fe2cf7158c8561bdb44281fb1f24b48..04b2dc90d1ac66f507926d0e9edff0c51b63f682 100644 (file)
@@ -22,30 +22,22 @@ import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
  * @see BooleanTypeDefinition
  */
 public final class BooleanType implements BooleanTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("boolean");
     private final SchemaPath path;
     private final String description = "The boolean built-in type represents a boolean value.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
     private final BooleanTypeDefinition baseType;
     private final Boolean defaultValue;
-    private String units = "";
+    private final String units = "";
 
     /**
      * Default constructor with default value set to "false".
      */
-    private BooleanType() {
-        super();
-        this.defaultValue = false;
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public BooleanType(final SchemaPath path) {
         super();
         this.defaultValue = false;
         this.path = path;
-        this.baseType = new BooleanType();
+        this.baseType = this;
     }
 
     /**
@@ -58,23 +50,7 @@ public final class BooleanType implements BooleanTypeDefinition {
         super();
         this.defaultValue = defaultValue;
         this.path = path;
-        this.baseType = new BooleanType();
-    }
-
-    /**
-     * Boolean Type constructor.
-     *
-     * @param defaultValue
-     *            Default Value
-     * @param units
-     *            Units
-     */
-    public BooleanType(final SchemaPath path, final Boolean defaultValue, final String units) {
-        super();
-        this.defaultValue = defaultValue;
-        this.units = units;
-        this.path = path;
-        this.baseType = new BooleanType();
+        this.baseType = this;
     }
 
     /*
index 6a070837bd8e9f3f79cec5c02639ffbdd7f0965b..1387da9b1cf5ead763a14d21b8b3d784ecc6ceb5 100644 (file)
@@ -26,11 +26,10 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see DecimalTypeDefinition
  */
 public final class Decimal64 implements DecimalTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("decimal64");
     private final SchemaPath path;
-    private String units = "";
-    private BigDecimal defaultValue = null;
+    private final String units = "";
+    private final BigDecimal defaultValue = null;
 
     private final String description = "The decimal64 type represents a subset of the real numbers, which can "
             + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
@@ -54,25 +53,14 @@ public final class Decimal64 implements DecimalTypeDefinition {
      * If the fraction digits are not defined inner the definition boundaries
      * the constructor will throw {@link IllegalArgumentException}
      *
+     * @param path
      * @param fractionDigits
      *            integer between 1 and 18 inclusively
      *
      * @see DecimalTypeDefinition
      * @exception IllegalArgumentException
      */
-    private Decimal64(final Integer fractionDigits) {
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-        this.fractionDigits = fractionDigits;
-        this.rangeStatements = defaultRangeStatements();
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public Decimal64(final SchemaPath path, final Integer fractionDigits) {
-        super();
         if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
             throw new IllegalArgumentException(
                     "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
@@ -80,97 +68,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
         this.fractionDigits = fractionDigits;
         rangeStatements = defaultRangeStatements();
         this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
-    }
-
-    /**
-     * Decimal64 Type Constructor. <br>
-     *
-     * If parameter <code>Range Statements</code> is <code>null</code> or
-     * defined as <code>empty List</code> the constructor automatically assigns
-     * the boundaries as min and max value defined for Decimal64 in <a
-     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
-     * decimal64 Built-In Type</a> <br>
-     * <br>
-     * The fractions digits MUST be defined as integer between 1 and 18
-     * inclusively as defined interface {@link DecimalTypeDefinition} <br>
-     * If the fraction digits are not defined inner the definition boundaries
-     * the constructor will throw {@link IllegalArgumentException}
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param rangeStatements
-     *            Range Constraint Statements
-     * @param fractionDigits
-     *            integer between 1 and 18 inclusively
-     * @exception IllegalArgumentException
-     */
-    public Decimal64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            Integer fractionDigits) {
-        super();
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-        if (rangeStatements == null || rangeStatements.isEmpty()) {
-            this.rangeStatements = defaultRangeStatements();
-        } else {
-            this.rangeStatements = Collections
-                    .unmodifiableList(rangeStatements);
-        }
-        this.fractionDigits = fractionDigits;
-        this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
-    }
-
-    /**
-     * Decimal64 Type Constructor. <br>
-     * If parameter <code>Range Statements</code> is <code>null</code> or
-     * defined as <code>empty List</code> the constructor automatically assigns
-     * the boundaries as min and max value defined for Decimal64 in <a
-     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
-     * decimal64 Built-In Type</a> <br>
-     * <br>
-     * The fractions digits MUST be defined as integer between 1 and 18
-     * inclusively as defined interface {@link DecimalTypeDefinition} <br>
-     * If the fraction digits are not defined inner the definition boundaries
-     * the constructor will throw {@link IllegalArgumentException}
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param units
-     *            units associated with the type
-     * @param defaultValue
-     *            Default Value for type
-     * @param rangeStatements
-     *            Range Constraint Statements
-     * @param fractionDigits
-     *            integer between 1 and 18 inclusively
-     */
-    public Decimal64(final SchemaPath path, final String units,
-            final BigDecimal defaultValue,
-            final List<RangeConstraint> rangeStatements,
-            final Integer fractionDigits) {
-        super();
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-
-        if (rangeStatements == null || rangeStatements.isEmpty()) {
-            this.rangeStatements = defaultRangeStatements();
-
-        } else {
-            this.rangeStatements = Collections
-                    .unmodifiableList(rangeStatements);
-        }
-        this.units = units;
-        this.defaultValue = defaultValue;
-        this.fractionDigits = fractionDigits;
-        this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
+        this.baseType = this;
     }
 
     /**
index 424f313efae6b20ccf35cf78e6b12057594114e0..0e542bc019f3e5fa043fc8fe769bf5457df9d6ea 100644 (file)
@@ -17,21 +17,15 @@ import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;
 
 public final class EmptyType implements EmptyTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("empty");
     private final SchemaPath path;
     private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#page-131";
     private final EmptyTypeDefinition baseType;
 
-    private EmptyType() {
-        path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public EmptyType(final SchemaPath path) {
         this.path = path;
-        this.baseType = new EmptyType();
+        this.baseType = this;
     }
 
     @Override
index 175ea100ca0919c51f8f9a08e841bc9b13cffc9e..de7ee3060347df9337479de99db162c554da0bf8 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
  * @see EnumTypeDefinition
  */
 public final class EnumerationType implements EnumTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("enumeration");
     private final SchemaPath path;
     private final String description = "The enumeration built-in type represents values from a set of assigned names.";
@@ -30,32 +29,24 @@ public final class EnumerationType implements EnumTypeDefinition {
 
     private final EnumPair defaultEnum;
     private final List<EnumPair> enums;
-    private String units = "";
+    private final String units = "";
     private final EnumTypeDefinition baseType;
 
-    private EnumerationType(final List<EnumPair> enums) {
-        this.path = BaseTypes.schemaPath(name);
-        this.enums = Collections.unmodifiableList(enums);
-        this.defaultEnum = null;
-        baseType = this;
-    }
-
     public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
         super();
         this.path = path;
         this.enums = Collections.unmodifiableList(enums);
         this.defaultEnum = null;
-        baseType = new EnumerationType(enums);
+        this.baseType = this;
     }
 
     public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
-            final List<EnumPair> enums, final String units) {
+            final List<EnumPair> enums) {
         super();
         this.path = path;
-        baseType = new EnumerationType(enums);
+        this.baseType = this;
         this.defaultEnum = defaultEnum;
         this.enums = Collections.unmodifiableList(enums);
-        this.units = units;
     }
 
     /*
index 6c4598131e496b405e1183ae521b44e507fb00ce..30f0013d240e7e713882eba614efd4d0cd467091 100644 (file)
@@ -22,27 +22,18 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition
  * @see IdentityrefTypeDefinition\r
  */\r
 public final class IdentityrefType implements IdentityrefTypeDefinition {\r
-\r
     private final QName name = BaseTypes.constructQName("identityref");\r
     private final SchemaPath path;\r
     private final String description = "The identityref type is used to reference an existing identity.";\r
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
     private final IdentityrefTypeDefinition baseType;\r
-\r
     private final QName identity;\r
-\r
-    private String units = "";\r
-\r
-    private IdentityrefType(QName identity) {\r
-        this.identity = identity;\r
-        this.path = BaseTypes.schemaPath(name);\r
-        this.baseType = this;\r
-    }\r
+    private final String units = "";\r
 \r
     public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
         this.identity = identity;\r
         this.path = schemaPath;\r
-        this.baseType = new IdentityrefType(identity);\r
+        this.baseType = this;\r
     }\r
 \r
     @Override\r
index 4c17fa6154248fb711c7bd844feb60e65cfd4ba3..8139d5b50b50bb302d1e5802b5a01ac74c8545b8 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDef
  * @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 " +
@@ -36,20 +35,12 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     private final InstanceIdentifierTypeDefinition baseType;
     private final boolean requireInstance;
 
-    private InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) {
-        super();
-        path = BaseTypes.schemaPath(name);
-        this.xpath = xpath;
-        this.requireInstance = requireInstance;
-        this.baseType = this;
-    }
-
     public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
         super();
         this.path = path;
         this.xpath = xpath;
         this.requireInstance = requireInstance;
-        this.baseType = new InstanceIdentifier(xpath, requireInstance);
+        this.baseType = this;
     }
 
     /*
index 0a24bf2d059166a65345775cbd34734e83813005..829cd140b18a04740e26ba75b4ab5c851e514866 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int16 built-in type. <br>
@@ -22,29 +19,15 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see AbstractSignedInteger
  */
 public final class Int16 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int16");
-    private Short defaultValue = null;
+    private final Short defaultValue = null;
     private static final String description = "int16  represents integer values between -32768 and 32767, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int16() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int16(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Int16();
-
-    }
+        this.baseType = this;
 
-    public Int16(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Short defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.defaultValue = defaultValue;
-        this.baseType = new Int16();
     }
 
     @Override
index 8d16e268c35c610750d6e129cbcc1d1ad6882e13..025448262e713a43f26356205f83fa107cc5e636 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int32 built-in type. <br>
@@ -24,34 +21,14 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public final class Int32 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int32");
-    private Integer defaultValue = null;
+    private final Integer defaultValue = null;
     private static final String description = "int32  represents integer values between -2147483648 and 2147483647, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int32() {
-        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int32(final SchemaPath path) {
         super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int32();
-    }
-
-    public Int32(final SchemaPath path, final Integer defaultValue) {
-        super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int32();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int32(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Integer defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int32();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index 92e92a94a276b8ee22b8c51932db82c5b40d4ea8..d51dcc7a8136912cf83188bd0d2c61becddfbb79 100644 (file)
@@ -7,12 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int64 built-in type. <br>
@@ -22,34 +19,15 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public final class Int64 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int64");
-    private Long defaultValue = null;
+    private final Long defaultValue = null;
     private static final String description =
             "int64  represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int64() {
-        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int64(final SchemaPath path) {
         super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int64();
-    }
-
-    public Int64(final SchemaPath path, final Long defaultValue) {
-        super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int64();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Long defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int64();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index f77eebad5223cdc32476ccafa219c873e6d9329d..9f205955492a767ca10e43f4f4aa5979ff1f879f 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int8 built-in type. <br>
@@ -22,34 +19,14 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see AbstractSignedInteger
  */
 public final class Int8 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int8");
-    private Byte defaultValue = null;
+    private final Byte defaultValue = null;
     private static final String description = "represents integer values between -128 and 127, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int8() {
-        super(name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int8(final SchemaPath path) {
         super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = new Int8();
-    }
-
-    public Int8(final SchemaPath path, final Byte defaultValue) {
-        super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = new Int8();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int8(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Byte defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int8();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index d17843af898b44adb1d6a5b2c9d140e446e2675b..bd42903184b68a472bf93caa670fe752f1d0c34e 100644 (file)
@@ -33,17 +33,10 @@ public final class Leafref implements LeafrefTypeDefinition {
     private final String units = "";
     private final LeafrefTypeDefinition baseType;
 
-    private Leafref(final RevisionAwareXPath xpath) {
-        this.xpath = xpath;
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
-        super();
         this.path = path;
         this.xpath = xpath;
-        baseType = new Leafref(xpath);
+        baseType = this;
     }
 
     /*
index 018ba00042d7ec27e9ee9c182c74ea56effdb98b..b430e801dd1be3093a3110605795117de3680e33 100644 (file)
@@ -25,27 +25,16 @@ import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition;
  * @see StringTypeDefinition
  */
 public final class StringType implements StringTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("string");
     private final SchemaPath path;
-    private String defaultValue = "";
+    private final String defaultValue = "";
     private final String description = "";
     private final String reference = "";
     private final List<LengthConstraint> lengthStatements;
     private final List<PatternConstraint> patterns;
-    private String units = "";
+    private final String units = "";
     private final StringTypeDefinition baseType;
 
-    private StringType() {
-        super();
-        path = BaseTypes.schemaPath(name);
-        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-        lengthStatements = Collections.unmodifiableList(constraints);
-        patterns = Collections.emptyList();
-        baseType = this;
-    }
-
     /**
      * Default Constructor.
      */
@@ -56,56 +45,7 @@ public final class StringType implements StringTypeDefinition {
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
         lengthStatements = Collections.unmodifiableList(constraints);
         patterns = Collections.emptyList();
-        baseType = new StringType();
-    }
-
-    /**
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param lengthStatements
-     * @param patterns
-     */
-    public StringType(final SchemaPath path, final List<LengthConstraint> lengthStatements,
-            final List<PatternConstraint> patterns) {
-        super();
-        this.path = path;
-        if(lengthStatements == null || lengthStatements.size() == 0) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-            this.lengthStatements = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthStatements = Collections.unmodifiableList(lengthStatements);
-        }
-        this.patterns = Collections.unmodifiableList(patterns);
-        baseType = new StringType();
-    }
-
-    /**
-     *
-     *
-     * @param defaultValue
-     * @param lengthStatements
-     * @param patterns
-     * @param units
-     */
-    public StringType(final SchemaPath path, final String defaultValue,
-            final List<LengthConstraint> lengthStatements,
-            final List<PatternConstraint> patterns, final String units) {
-        super();
-        this.path = path;
-        this.defaultValue = defaultValue;
-        if(lengthStatements == null || lengthStatements.size() == 0) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-            this.lengthStatements = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthStatements = Collections.unmodifiableList(lengthStatements);
-        }
-        this.patterns = Collections.unmodifiableList(patterns);
-        this.units = units;
-        this.baseType = new StringType();
+        baseType = this;
     }
 
     /*
index 95b438b509f8258c722aa403ee64a8ac08985411..79ae4674b0b48971005c09ad76cad8d528b6a215 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -21,33 +18,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint16 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint16");
     private Integer defaultValue = null;
     private static final String description = "uint16 represents integer values between 0 and 65535, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint16() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint16(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint16();
-    }
-
-    public Uint16(final SchemaPath path, final Integer defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint16();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint16(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Integer defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint16();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index e530e02bbb79357518ccf67fe5fd968da500ac47..fddf0c4008f9c172486a891f49012ef466412a1b 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -21,33 +18,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint32 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint32");
-    private Long defaultValue = null;
+    private final Long defaultValue = null;
     private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint32() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint32(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint32();
-    }
-
-    public Uint32(final SchemaPath path, final Long defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint32();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint32(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Long defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint32();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index a4aabb56c659bc939431fa8a581c83b091d7a63a..9252c08f577715c6744201d1a1b507373ff6f9e8 100644 (file)
@@ -8,11 +8,9 @@
 package org.opendaylight.controller.yang.model.util;
 
 import java.math.BigInteger;
-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.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -23,35 +21,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint64 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint64");
-
-    private BigInteger defaultValue = null;
+    private final BigInteger defaultValue = null;
     private static final String description = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint64() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint64(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint64();
-    }
-
-    public Uint64(final SchemaPath path, final BigInteger defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint64();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint64(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final BigInteger defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint64();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index c369e037763c7ec821cac453dfe9a413d70d1901..fa9d35ea291b2635aab13dc8f420df9dde1a4b86 100644 (file)
@@ -7,11 +7,8 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
-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.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -25,32 +22,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
 public final class Uint8 extends AbstractUnsignedInteger {
 
     private static final QName name = BaseTypes.constructQName("uint8");
-    private Short defaultValue = null;
+    private final Short defaultValue = null;
     private static final String description =
             "uint8  represents integer values between 0 and 255, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint8() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint8(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint8();
-    }
-
-    public Uint8(final SchemaPath path, final Short defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint8();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint8(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Short defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint8();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index 82849891f9b42b64c9043237598986b007d78403..76d53d5b38b872bd2558be82f340e37b4717ea01 100644 (file)
@@ -52,25 +52,25 @@ public final class YangTypesConverter {
             String typeName) {\r
         TypeDefinition<?> type = null;\r
 \r
-        SchemaPath path = createSchemaPath(actualPath, namespace, revision);\r
+        SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName);\r
         if (typeName.startsWith("int")) {\r
-            if (typeName.equals("int8")) {\r
+            if ("int8".equals(typeName)) {\r
                 type = new Int8(path);\r
-            } else if (typeName.equals("int16")) {\r
+            } else if ("int16".equals(typeName)) {\r
                 type = new Int16(path);\r
-            } else if (typeName.equals("int32")) {\r
+            } else if ("int32".equals(typeName)) {\r
                 type = new Int32(path);\r
-            } else if (typeName.equals("int64")) {\r
+            } else if ("int64".equals(typeName)) {\r
                 type = new Int64(path);\r
             }\r
         } else if (typeName.startsWith("uint")) {\r
-            if (typeName.equals("uint8")) {\r
+            if ("uint8".equals(typeName)) {\r
                 type = new Uint8(path);\r
-            } else if (typeName.equals("uint16")) {\r
+            } else if ("uint16".equals(typeName)) {\r
                 type = new Uint16(path);\r
-            } else if (typeName.equals("uint32")) {\r
+            } else if ("uint32".equals(typeName)) {\r
                 type = new Uint32(path);\r
-            } else if (typeName.equals("uint64")) {\r
+            } else if ("uint64".equals(typeName)) {\r
                 type = new Uint64(path);\r
             }\r
         } else if ("string".equals(typeName)) {\r
@@ -88,11 +88,18 @@ public final class YangTypesConverter {
         return type;\r
     }\r
 \r
-    private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision) {\r
+    private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision, String typeName) {\r
+        List<String> correctPath = new ArrayList<String>(actualPath);\r
+        // remove module name\r
+        correctPath.remove(0);\r
+\r
         List<QName> path = new ArrayList<QName>();\r
-        for(String element : actualPath) {\r
+        for(String element : correctPath) {\r
             path.add(new QName(namespace, revision, element));\r
         }\r
+        // add type qname\r
+        QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);\r
+        path.add(typeQName);\r
         return new SchemaPath(path, true);\r
     }\r
 \r
index 8ea2190f4aca09b1bc37b4889d61e4101904f82a..971213e483e567b4d4a6d0336ee613b85ceb25a8 100644 (file)
@@ -1699,7 +1699,7 @@ CommandProvider {
         List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
 
         for (NodeConnector nodeConnector : nodeConncetors) {
-            if (!spanNodeConnectors.contains(nodeConnector)) {
+            if (spanNodeConnectors.contains(nodeConnector)) {
                 ncLists.add(nodeConnector);
             }
         }
index d5b499c42b9737cfac8783eb8ec4943180d75aad..872fb17129108598fe2f9a5afc038a549dc3e295 100644 (file)
@@ -33,14 +33,7 @@ import org.slf4j.LoggerFactory;
 @XmlAccessorType(XmlAccessType.NONE)
 public class TopologyUserLinkConfig implements Serializable {
     private static final long serialVersionUID = 1L;
-    private static final String regexDatapathID = "^([0-9a-fA-F]{1,2}[:-]){7}[0-9a-fA-F]{1,2}$";
-    private static final String regexDatapathIDLong = "^[0-9a-fA-F]{1,16}$";
-    private static final String guiFields[] = { GUIField.STATUS.toString(),
-            GUIField.NAME.toString(), GUIField.SRCNODE.toString(),
-            GUIField.SRCPORT.toString(), GUIField.DSTNODE.toString(),
-            GUIField.DSTPORT.toString() };
-    private static final Logger logger = LoggerFactory
-    .getLogger(TopologyUserLinkConfig.class);
+    private static final Logger logger = LoggerFactory.getLogger(TopologyUserLinkConfig.class);
 
     public enum STATUS {
         SUCCESS("Success"), LINKDOWN("Link Down"), INCORRECT(
@@ -73,76 +66,24 @@ public class TopologyUserLinkConfig implements Serializable {
     @XmlElement
     private String name;
     @XmlElement
-    private String srcNodeIDType;
+    private String srcNodeConnector;
     @XmlElement
-    private String srcSwitchId;
-    @XmlElement
-    private String srcNodeConnectorIDType;
-    @XmlElement
-    private String srcPort;
-    @XmlElement
-    private String dstNodeIDType;
-    @XmlElement
-    private String dstSwitchId;
-    @XmlElement
-    private String dstNodeConnectorIDType;
-    @XmlElement
-    private String dstPort;
+    private String dstNodeConnector;
 
     public TopologyUserLinkConfig() {
         super();
         status = STATUS.LINKDOWN.toString();
     }
 
-       public TopologyUserLinkConfig(String name, String srcNodeIDType,
-                       String srcSwitchId, String srcNodeConnectorIDType, String srcPort,
-                       String dstNodeIDType, String dstSwitchId,
-                       String dstNodeConnectorIDType, String dstPort) {
+    public TopologyUserLinkConfig(String name, String srcNodeConnector, String dstNodeConnector) {
         super();
         this.name = name;
-        this.srcNodeIDType = srcNodeIDType;
-        this.srcSwitchId = srcSwitchId;
-        this.dstNodeIDType = dstNodeIDType;
-        this.dstSwitchId = dstSwitchId;
-        this.srcNodeConnectorIDType = srcNodeConnectorIDType;
-        this.srcPort = srcPort;
-        this.dstNodeConnectorIDType = dstNodeConnectorIDType;
-        this.dstPort = dstPort;
+        this.srcNodeConnector = srcNodeConnector;
+        this.dstNodeConnector = dstNodeConnector;
     }
 
-    public String getSrcNodeIDType() {
-               return srcNodeIDType;
-       }
-
-       public void setSrcNodeIDType(String srcNodeIDType) {
-               this.srcNodeIDType = srcNodeIDType;
-       }
-
-       public String getSrcNodeConnectorIDType() {
-               return srcNodeConnectorIDType;
-       }
 
-       public void setSrcNodeConnectorIDType(String srcNodeConnectorIDType) {
-               this.srcNodeConnectorIDType = srcNodeConnectorIDType;
-       }
-
-       public String getDstNodeIDType() {
-               return dstNodeIDType;
-       }
-
-       public void setDstNodeIDType(String dstNodeIDType) {
-               this.dstNodeIDType = dstNodeIDType;
-       }
-
-       public String getDstNodeConnectorIDType() {
-               return dstNodeConnectorIDType;
-       }
-
-       public void setDstNodeConnectorIDType(String dstNodeConnectorIDType) {
-               this.dstNodeConnectorIDType = dstNodeConnectorIDType;
-       }
-
-       public String getName() {
+    public String getName() {
         return name;
     }
 
@@ -150,45 +91,6 @@ public class TopologyUserLinkConfig implements Serializable {
         this.name = name;
     }
 
-    public String getSrcSwitchId() {
-        return srcSwitchId;
-    }
-
-    public long getSrcSwitchIDLong() {
-        return getSwitchIDLong(srcSwitchId);
-    }
-
-    public void setSrcSwitchId(String srcSwitchId) {
-        this.srcSwitchId = srcSwitchId;
-    }
-
-    public String getDstSwitchId() {
-        return dstSwitchId;
-    }
-
-    public long getDstSwitchIDLong() {
-        return getSwitchIDLong(dstSwitchId);
-    }
-
-    public void setDstSwitchId(String dstSwitchId) {
-        this.dstSwitchId = dstSwitchId;
-    }
-
-    public String getSrcPort() {
-        return srcPort;
-    }
-
-    public void setSrcPort(String srcPort) {
-        this.srcPort = srcPort;
-    }
-
-    public String getDstPort() {
-        return dstPort;
-    }
-
-    public void setDstPort(String dstPort) {
-        this.dstPort = dstPort;
-    }
 
     public STATUS getStatus() {
         return STATUS.fromString(status);
@@ -198,126 +100,54 @@ public class TopologyUserLinkConfig implements Serializable {
         this.status = s.toString();
     }
 
-    private boolean isValidSwitchId(String switchId) {
-        return (switchId != null && (switchId.matches(regexDatapathID) || switchId
-                .matches(regexDatapathIDLong)));
+    public String getSrcNodeConnector() {
+        return srcNodeConnector;
     }
 
-    private boolean isValidSwitchId(String switchId, String typeStr) {
-        if (typeStr.equals(NodeIDType.OPENFLOW)) {
-            return isValidSwitchId(switchId);
-        } else if (typeStr.equals(NodeIDType.ONEPK) || 
-                          typeStr.equals(NodeIDType.PCEP) || 
-                          typeStr.equals(NodeIDType.PRODUCTION)) {
-            return true;
-        } else {
-                       logger.warn("Invalid node id type {}", typeStr);
-               return false;
-        }
+    public void setSrcNodeConnector(String srcNodeConnector) {
+        this.srcNodeConnector = srcNodeConnector;
     }
 
-    private boolean isValidPortId(String portId, String nodeConnectorType) {
-               if (NodeConnectorIDType.getClassType(nodeConnectorType) == null) {
-                       logger.warn("Invalid node connector id type {}", nodeConnectorType);
-                       return false; 
-               }
-               
-               return true;
-       }
-
-    private long getSwitchIDLong(String switchId) {
-        int radix = 16;
-        String switchString = "0";
-
-        if (isValidSwitchId(switchId)) {
-            if (switchId.contains(":")) {
-                // Handle the 00:00:AA:BB:CC:DD:EE:FF notation
-                switchString = switchId.replace(":", "");
-            } else if (switchId.contains("-")) {
-                // Handle the 00-00-AA-BB-CC-DD-EE-FF notation
-                switchString = switchId.replace("-", "");
-            } else {
-                // Handle the 0123456789ABCDEF notation
-                switchString = switchId;
-            }
-        }
-        return Long.parseLong(switchString, radix);
+    public String getDstNodeConnector() {
+        return dstNodeConnector;
     }
 
-    public boolean isValid() {
-               if (name == null || srcSwitchId == null || dstSwitchId == null
-                               || srcPort == null || dstPort == null || srcNodeIDType == null
-                               || dstNodeIDType == null || srcNodeConnectorIDType == null
-                               || dstNodeConnectorIDType == null) {
-            return false;
-               }
-               
-               if (!isValidSwitchId(srcSwitchId, srcNodeIDType) || 
-                       !isValidSwitchId(dstSwitchId, dstNodeIDType)) {
-                       logger.warn("Invalid switch id");
-                       return false;
-               }
-               
-               if (!isValidPortId(srcPort, srcNodeConnectorIDType) || 
-                       !isValidPortId(dstPort, dstNodeConnectorIDType)) {
-                       logger.warn("Invalid port id");
-                       return false;
-               }
-                       
-               return true;
+    public void setDstNodeConnector(String dstNodeConnector) {
+        this.dstNodeConnector = dstNodeConnector;
     }
 
-    public boolean isSrcPortByName() {
-        try {
-            Short.parseShort(srcPort);
-        } catch (Exception e) {
-            return true;
-        }
-        return false;
+    public boolean isValidNodeConnector(String nodeConnectorStr) {
+        NodeConnector nc = NodeConnector.fromString(nodeConnectorStr);
+        if (nc == null) return false;
+        return true;
     }
 
-    public boolean isDstPortByName() {
-        try {
-            Short.parseShort(dstPort);
-        } catch (Exception e) {
-            return true;
+    public boolean isValid() {
+        if (name == null || srcNodeConnector == null || dstNodeConnector == null) {
+            return false;
         }
-        return false;
-    }
 
-    public static List<String> getGuiFieldsNames() {
-        List<String> fieldList = new ArrayList<String>();
-        for (String str : guiFields) {
-            fieldList.add(str);
+        if (!isValidNodeConnector(srcNodeConnector) || 
+                !isValidNodeConnector(dstNodeConnector)) {
+            logger.warn("Invalid NodeConnector");
+            return false;
         }
-        return fieldList;
-    }
 
-    @Override
-    public String toString() {
-               return "ITopologyUserLinkConfig [status=" + status + ", name=" + name
-                               + ", srcNodeIDType=" + srcNodeIDType + ", srcSwitchId="
-                               + srcSwitchId + ", srcNodeConnectorIDType="
-                               + srcNodeConnectorIDType + ", srcPort=" + srcPort
-                               + ", dstNodeIDType=" + dstNodeIDType + ", dstId="
-                               + dstSwitchId + ", dstNodeConnectorIDType="
-                               + dstNodeConnectorIDType + ", dstPort=" + dstPort + "]";
+        return true;
     }
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
-    }
-
-    public boolean equals(Long srcNid, String srcPortName, Long dstNid,
-            String dstPortName) {
-        if (srcNid.equals(getSrcSwitchIDLong())
-                && dstNid.equals(getDstSwitchIDLong())
-                && srcPortName.equals(getSrcPort())
-                && dstPortName.equals(getDstPort())) {
-            return true;
-        }
-        return false;
+        final int prime = 31;
+        int result = 1;
+        result = prime
+                * result
+                + ((dstNodeConnector == null) ? 0 : dstNodeConnector.hashCode());
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime
+                * result
+                + ((srcNodeConnector == null) ? 0 : srcNodeConnector.hashCode());
+        return result;
     }
 
     @Override
@@ -329,26 +159,23 @@ public class TopologyUserLinkConfig implements Serializable {
         if (getClass() != obj.getClass())
             return false;
         TopologyUserLinkConfig other = (TopologyUserLinkConfig) obj;
-        if (dstPort == null) {
-            if (other.dstPort != null)
+        if (dstNodeConnector == null) {
+            if (other.dstNodeConnector != null)
                 return false;
-        } else if (!dstPort.equals(other.dstPort))
+        } else if (!dstNodeConnector.equals(other.dstNodeConnector))
             return false;
-        if (dstSwitchId == null) {
-            if (other.dstSwitchId != null)
+        if (srcNodeConnector == null) {
+            if (other.srcNodeConnector != null)
                 return false;
-        } else if (!dstSwitchId.equals(other.dstSwitchId))
-            return false;
-        if (srcPort == null) {
-            if (other.srcPort != null)
-                return false;
-        } else if (!srcPort.equals(other.srcPort))
-            return false;
-        if (srcSwitchId == null) {
-            if (other.srcSwitchId != null)
-                return false;
-        } else if (!srcSwitchId.equals(other.srcSwitchId))
+        } else if (!srcNodeConnector.equals(other.srcNodeConnector))
             return false;
         return true;
     }
-}
+
+    @Override
+    public String toString() {
+        return "TopologyUserLinkConfig [status=" + status + ", name=" + name
+                + ", srcNodeConnector=" + srcNodeConnector
+                + ", dstNodeConnector=" + dstNodeConnector + "]";
+    }
+}
\ No newline at end of file
index 8c39098a5ec56f532ecd29c99045f2e644ca1d61..277465813baef5d1e183f36ac64efad92cf7fb0c 100644 (file)
@@ -66,8 +66,8 @@ import org.slf4j.LoggerFactory;
  * topology database and notifies all the listeners of topology changes.
  */
 public class TopologyManagerImpl implements ITopologyManager,
-        IConfigurationContainerAware, IListenTopoUpdates, IObjectReader,
-        CommandProvider {
+IConfigurationContainerAware, IListenTopoUpdates, IObjectReader,
+CommandProvider {
     private static final Logger log = LoggerFactory
             .getLogger(TopologyManagerImpl.class);
     private ITopologyService topoService = null;
@@ -232,7 +232,7 @@ public class TopologyManagerImpl implements ITopologyManager,
         this.clusterContainerService.destroyCache("topologymanager.hostsDB");
         this.hostsDB = null;
         this.clusterContainerService
-                .destroyCache("topologymanager.nodeConnectorDB");
+        .destroyCache("topologymanager.nodeConnectorDB");
         this.nodeConnectorsDB = null;
         log.debug("Topology Manager DB Deallocated");
     }
@@ -596,82 +596,21 @@ public class TopologyManagerImpl implements ITopologyManager,
 
     private Edge getReverseLinkTuple(TopologyUserLinkConfig link) {
         TopologyUserLinkConfig rLink = new TopologyUserLinkConfig(
-                link.getName(), link.getDstNodeIDType(), link.getDstSwitchId(),
-                link.getDstNodeConnectorIDType(), link.getDstPort(),
-                link.getSrcNodeIDType(), link.getSrcSwitchId(),
-                link.getSrcNodeConnectorIDType(), link.getSrcPort());
+                link.getName(), link.getDstNodeConnector(), link.getSrcNodeConnector());
         return getLinkTuple(rLink);
     }
 
+
     private Edge getLinkTuple(TopologyUserLinkConfig link) {
         Edge linkTuple = null;
-
-        // if atleast 1 link exists for the srcPort and atleast 1 link exists
-        // for the dstPort
-        // that makes it ineligible for the Manual link addition
-        // This is just an extra protection to avoid mis-programming.
-        boolean srcLinkExists = false;
-        boolean dstLinkExists = false;
-        // TODO check a way to validate the port with inventory services
-        // if (srcSw.getPorts().contains(srcPort) &&
-        // dstSw.getPorts().contains(srcPort) &&
-        if (!srcLinkExists && !dstLinkExists) {
-            Node sNode = null;
-            Node dNode = null;
-            NodeConnector sPort = null;
-            NodeConnector dPort = null;
-            linkTuple = null;
-            String srcNodeIDType = link.getSrcNodeIDType();
-            String srcNodeConnectorIDType = link.getSrcNodeConnectorIDType();
-            String dstNodeIDType = link.getDstNodeIDType();
-            String dstNodeConnectorIDType = link.getDstNodeConnectorIDType();
-            try {
-                if (srcNodeIDType.equals(NodeIDType.OPENFLOW)) {
-                    sNode = new Node(srcNodeIDType, link.getSrcSwitchIDLong());
-                } else {
-                    sNode = new Node(srcNodeIDType, link.getSrcSwitchId());
-                }
-
-                if (dstNodeIDType.equals(NodeIDType.OPENFLOW)) {
-                    dNode = new Node(dstNodeIDType, link.getDstSwitchIDLong());
-                } else {
-                    dNode = new Node(dstNodeIDType, link.getDstSwitchId());
-                }
-
-                if (srcNodeConnectorIDType.equals(NodeConnectorIDType.OPENFLOW)) {
-                    Short srcPort = Short.valueOf((short) 0);
-                    if (!link.isSrcPortByName()) {
-                        srcPort = Short.parseShort(link.getSrcPort());
-                    }
-                    sPort = new NodeConnector(srcNodeConnectorIDType, srcPort,
-                            sNode);
-                } else {
-                    sPort = new NodeConnector(srcNodeConnectorIDType,
-                            link.getSrcPort(), sNode);
-                }
-
-                if (dstNodeConnectorIDType.equals(NodeConnectorIDType.OPENFLOW)) {
-                    Short dstPort = Short.valueOf((short) 0);
-                    if (!link.isDstPortByName()) {
-                        dstPort = Short.parseShort(link.getDstPort());
-                    }
-                    dPort = new NodeConnector(dstNodeConnectorIDType, dstPort,
-                            dNode);
-                } else {
-                    dPort = new NodeConnector(dstNodeConnectorIDType,
-                            link.getDstPort(), dNode);
-                }
-                linkTuple = new Edge(sPort, dPort);
-            } catch (ConstructionException cex) {
-                log.warn("Caught exception ", cex);
-            }
-            return linkTuple;
-        }
-
-        if (srcLinkExists && dstLinkExists) {
-            link.setStatus(TopologyUserLinkConfig.STATUS.INCORRECT);
+        NodeConnector srcNodeConnector = NodeConnector.fromString(link.getSrcNodeConnector());
+        NodeConnector dstNodeConnector = NodeConnector.fromString(link.getDstNodeConnector());
+        if (srcNodeConnector == null || dstNodeConnector == null) return null;
+        try {
+            linkTuple = new Edge(srcNodeConnector, dstNodeConnector);
+        } catch (Exception e) {            
         }
-        return null;
+        return linkTuple;
     }
 
     @Override
@@ -795,19 +734,7 @@ public class TopologyManagerImpl implements ITopologyManager,
             return;
         }
 
-        String nodeType1 = nc1.getNode().getType().toString();
-        String nid1 = nc1.getNode().getID().toString();
-        String ncType1 = nc1.getType().toString();
-        String ncid1 = nc1.getID().toString();
-
-        String nodeType2 = nc2.getNode().getType().toString();
-        String nid2 = nc2.getNode().getID().toString();
-        String ncType2 = nc2.getType().toString();
-        String ncid2 = nc2.getID().toString();
-
-        TopologyUserLinkConfig config = new TopologyUserLinkConfig(name,
-                nodeType1, nid1, ncType1, ncid1, nodeType2, nid2, ncType2,
-                ncid2);
+        TopologyUserLinkConfig config = new TopologyUserLinkConfig(name, ncStr1, ncStr2);
         ci.println(this.addUserLink(config));
     }
 
index c176cb2cf3e50ba3b878e5923efeafe108059851..b4dfba9277cd12befbf7eb54a6f4943096ef7946 100644 (file)
@@ -116,19 +116,19 @@ public class TopologyManagerImplTest {
                             .equals(nodeId + 10))
                             || (headNcId.equals(nodeId + 10) && tailNcId
                                     .equals(nodeId))
-                            || (headNcId.equals(nodeId + 1) && tailNcId
-                                    .equals(nodeId + 11))
-                            || (headNcId.equals(nodeId + 11) && tailNcId
-                                    .equals(nodeId + 1)));
+                                    || (headNcId.equals(nodeId + 1) && tailNcId
+                                            .equals(nodeId + 11))
+                                            || (headNcId.equals(nodeId + 11) && tailNcId
+                                                    .equals(nodeId + 1)));
                 } else if (nodeId == 11 || nodeId == 13 || nodeId == 15) {
                     Assert.assertTrue((headNcId.equals(nodeId) && tailNcId
                             .equals(nodeId - 10))
                             || (headNcId.equals(nodeId) && tailNcId
                                     .equals(nodeId - 10))
-                            || (headNcId.equals(nodeId - 9) && tailNcId
-                                    .equals(nodeId + 1))
-                            || (headNcId.equals(nodeId + 1) && tailNcId
-                                    .equals(nodeId - 9)));
+                                    || (headNcId.equals(nodeId - 9) && tailNcId
+                                            .equals(nodeId + 1))
+                                            || (headNcId.equals(nodeId + 1) && tailNcId
+                                                    .equals(nodeId - 9)));
                 }
             }
             i.remove();
@@ -160,19 +160,19 @@ public class TopologyManagerImplTest {
                         .equals(headNodeId + 10))
                         || (headNcId.equals(headNodeId + 10) && tailNcId
                                 .equals(headNodeId))
-                        || (headNcId.equals(headNodeId + 1) && tailNcId
-                                .equals(headNodeId + 11))
-                        || (headNcId.equals(headNodeId + 11) && tailNcId
-                                .equals(headNodeId + 1)));
+                                || (headNcId.equals(headNodeId + 1) && tailNcId
+                                        .equals(headNodeId + 11))
+                                        || (headNcId.equals(headNodeId + 11) && tailNcId
+                                                .equals(headNodeId + 1)));
             } else if (headNodeId == 11 || headNodeId == 13 || headNodeId == 15) {
                 Assert.assertTrue((headNcId.equals(headNodeId) && tailNcId
                         .equals(headNodeId - 10))
                         || (headNcId.equals(headNodeId) && tailNcId
                                 .equals(headNodeId - 10))
-                        || (headNcId.equals(headNodeId - 9) && tailNcId
-                                .equals(headNodeId + 1))
-                        || (headNcId.equals(headNodeId + 1) && tailNcId
-                                .equals(headNodeId - 9)));
+                                || (headNcId.equals(headNodeId - 9) && tailNcId
+                                        .equals(headNodeId + 1))
+                                        || (headNcId.equals(headNodeId + 1) && tailNcId
+                                                .equals(headNodeId - 9)));
             }
 
             Set<Property> prop = entry.getValue();
@@ -212,13 +212,13 @@ public class TopologyManagerImplTest {
     @Test
     public void testAddDeleteUserLink() {
         TopologyUserLinkConfig link1 = new TopologyUserLinkConfig("default1",
-                "OF", "1", "OF", "2", "OF", "1", "OF", "2");
+                "OF|1@OF|2", "OF|1@OF|2");
         TopologyUserLinkConfig link2 = new TopologyUserLinkConfig("default1",
-                "OF", "10", "OF", "20", "OF", "10", "OF", "20");
+                "OF|10@OF|20", "OF|10@OF|20");
         TopologyUserLinkConfig link3 = new TopologyUserLinkConfig("default2",
-                "OF", "1", "OF", "2", "OF", "1", "OF", "2");
+                "OF|1@OF|2", "OF|1@OF|2");
         TopologyUserLinkConfig link4 = new TopologyUserLinkConfig("default20",
-                "OF", "10", "OF", "20", "OF", "10", "OF", "20");
+                "OF|10@OF|20", "OF|10@OF|20");
 
         TopologyManagerImpl topoManagerImpl = new TopologyManagerImpl();
         topoManagerImpl.nonClusterObjectCreate();
@@ -244,40 +244,34 @@ public class TopologyManagerImplTest {
         TopologyManagerImpl topoManagerImpl = new TopologyManagerImpl();
         topoManagerImpl.nonClusterObjectCreate();
 
-        String name = null;
-        String srcNodeIDType = null;
+        String name = "Test";
         String srcSwitchId = null;
         String srcNodeConnectorIDType = null;
         String srcPort = null;
+        String srcNodeIDType = null;
         String dstNodeIDType = null;
         String dstSwitchId = null;
         String dstNodeConnectorIDType = null;
         String dstPort = null;
+        String srcNodeConnector = null;
+        String dstNodeConnector = null;
 
         /* Creating userlinks and checking for their validity */
-        link[0] = new TopologyUserLinkConfig(name, srcNodeIDType, srcSwitchId,
-                srcNodeConnectorIDType, srcPort, dstNodeIDType, dstSwitchId,
-                dstNodeConnectorIDType, dstPort);
+        link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
         Assert.assertTrue(link[0].isValid() == false);
 
-        srcSwitchId = "1";
-        link[0] = new TopologyUserLinkConfig(name, srcNodeIDType, srcSwitchId,
-                srcNodeConnectorIDType, srcPort, dstNodeIDType, dstSwitchId,
-                dstNodeConnectorIDType, dstPort);
+        srcNodeConnector = "OF|1@OF|1";
+        link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
         Assert.assertTrue(link[0].isValid() == false);
 
-        dstSwitchId = "2";
-        link[0] = new TopologyUserLinkConfig(name, srcNodeIDType, srcSwitchId,
-                srcNodeConnectorIDType, srcPort, dstNodeIDType, dstSwitchId,
-                dstNodeConnectorIDType, dstPort);
-        Assert.assertTrue(link[0].isValid() == false);
+        dstNodeConnector = "OF|1@OF|2";
+        link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
+        Assert.assertTrue(link[0].isValid() == true);
 
         Integer i;
 
         for (i = 0; i < 5; i++) {
-            link[i] = new TopologyUserLinkConfig(name, srcNodeIDType,
-                    srcSwitchId, srcNodeConnectorIDType, srcPort,
-                    dstNodeIDType, dstSwitchId, dstNodeConnectorIDType, dstPort);
+            link[i] = new TopologyUserLinkConfig();
 
             name = Integer.toString(i + 1);
             srcSwitchId = Integer.toString(i + 1);
@@ -286,29 +280,27 @@ public class TopologyManagerImplTest {
             dstPort = Integer.toString((i + 1) * 10);
 
             link[i].setName(name);
-            link[i].setSrcSwitchId(srcSwitchId);
-            link[i].setSrcPort(srcPort);
-            link[i].setDstSwitchId(dstSwitchId);
-            link[i].setDstPort(dstPort);
+            srcNodeConnectorIDType = dstNodeConnectorIDType = "INCORRECT";
+            srcNodeConnector = srcNodeConnectorIDType+"|"+srcSwitchId+"@"+srcNodeConnectorIDType+"|"+srcPort;
+            dstNodeConnector = dstNodeConnectorIDType+"|"+dstSwitchId+"@"+dstNodeConnectorIDType+"|"+dstPort;
 
+            link[i].setSrcNodeConnector(srcNodeConnector);
             Assert.assertTrue(link[i].isValid() == false);
 
-            link[i].setSrcNodeIDType("OF");
-            link[i].setSrcNodeConnectorIDType("OF");
-
+            srcNodeConnectorIDType = "OF";
+            srcNodeConnector = srcNodeConnectorIDType+"|"+srcSwitchId+"@"+srcNodeConnectorIDType+"|"+srcPort;
+            link[i].setSrcNodeConnector(srcNodeConnector);
             Assert.assertTrue(link[i].isValid() == false);
 
-            link[i].setDstNodeIDType("OF");
-            link[i].setDstNodeConnectorIDType("OF");
-
+            dstNodeConnectorIDType = "OF";
+            dstNodeConnector = dstNodeConnectorIDType+"|"+dstSwitchId+"@"+dstNodeConnectorIDType+"|"+dstPort;
+            link[i].setDstNodeConnector(dstNodeConnector);
             Assert.assertTrue(link[i].isValid() == true);
 
-            reverseLink[i] = new TopologyUserLinkConfig(name, dstNodeIDType,
-                    dstSwitchId, dstNodeConnectorIDType, dstPort,
-                    srcNodeIDType, srcSwitchId, srcNodeConnectorIDType, srcPort);
-
+            reverseLink[i] = new TopologyUserLinkConfig(name, dstNodeConnector, srcNodeConnector);
             topoManagerImpl.addUserLink(link[i]);
         }
+
         ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topoManagerImpl
                 .getUserLinks();
         TopologyUserLinkConfig resultLink;
@@ -318,20 +310,16 @@ public class TopologyManagerImplTest {
 
             Assert.assertTrue(resultLink.getName().equals(
                     reverseLink[i].getName()));
-            Assert.assertTrue(resultLink.getDstSwitchId().equals(
-                    reverseLink[i].getSrcSwitchId()));
-            Assert.assertTrue(resultLink.getDstPort().equals(
-                    reverseLink[i].getSrcPort()));
-            Assert.assertTrue(resultLink.getSrcSwitchId().equals(
-                    reverseLink[i].getDstSwitchId()));
-            Assert.assertTrue(resultLink.getSrcPort().equals(
-                    reverseLink[i].getDstPort()));
+            Assert.assertTrue(resultLink.getDstNodeConnector().equals(
+                    reverseLink[i].getSrcNodeConnector()));
+            Assert.assertTrue(resultLink.getSrcNodeConnector().equals(
+                    reverseLink[i].getDstNodeConnector()));
         }
     }
 
     @Test
     public void testHostLinkMethods() throws ConstructionException,
-            UnknownHostException {
+    UnknownHostException {
         TopologyManagerImpl topoManagerImpl = new TopologyManagerImpl();
         topoManagerImpl.nonClusterObjectCreate();
         int hostCounter = 0;
@@ -372,7 +360,7 @@ public class TopologyManagerImplTest {
             nc[i] = NodeConnectorCreator.createOFNodeConnector((short) (i + 1),
                     NodeCreator.createOFNode((long) (i + 1)));
             topoManagerImpl
-                    .updateHostLink(nc[i], h[i], UpdateType.ADDED, props);
+            .updateHostLink(nc[i], h[i], UpdateType.ADDED, props);
         }
 
         for (int i = 0; i < 5; i++) {