Moved CMTS emulator to its own module so it can either be run standalone or be used... 28/22728/2
authorSteven Pisarski <s.pisarski@cablelabs.com>
Tue, 16 Jun 2015 20:01:50 +0000 (14:01 -0600)
committerSteve Pisarski <s.pisarski@cablelabs.com>
Wed, 17 Jun 2015 17:14:33 +0000 (17:14 +0000)
Change-Id: Id090efb3bd3ef674fc927d1820ec0f0330a002b8
Signed-off-by: Steven Pisarski <s.pisarski@cablelabs.com>
packetcable-driver/pom.xml
packetcable-emulator/conf/cmts.yaml [new file with mode: 0644]
packetcable-emulator/pom.xml [new file with mode: 0644]
packetcable-emulator/src/main/java/org/pcmm/rcd/impl/CMTS.java [moved from packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java with 50% similarity]
packetcable-policy-server/pom.xml
pom.xml

index d40faae011196a3924e5e013e2e58e7959818c9f..d7bf8acb9be51d52552bc15636fdbbb0b885b22d 100644 (file)
@@ -62,6 +62,7 @@
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
+                       <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>ch.qos.logback</groupId>
diff --git a/packetcable-emulator/conf/cmts.yaml b/packetcable-emulator/conf/cmts.yaml
new file mode 100644 (file)
index 0000000..5d9147e
--- /dev/null
@@ -0,0 +1,24 @@
+# The CMTS Emulator's communications port number
+port: 3918
+
+# The configured gates
+gates:
+  - type: UPSTREAM
+    names:
+      - extrm_up
+      - foo_up
+  - type: DOWNSTREAM
+    names:
+      - extrm_dn
+      - foo_dn
+
+# The connected cable modem info
+cmStatuses:
+  - host: 10.32.110.180
+    status: true
+  - host: 10.32.110.179
+    status: true
+  - host: 10.32.110.178
+    status: true
+  - host: 99.99.99.99
+    status: false
diff --git a/packetcable-emulator/pom.xml b/packetcable-emulator/pom.xml
new file mode 100644 (file)
index 0000000..7ee0597
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.opendaylight.packetcable</groupId>
+        <artifactId>packetcable</artifactId>
+        <version>1.3.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>packetcable-emulator</artifactId>
+    <packaging>jar</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                    <archive>
+                        <manifest>
+                            <mainClass>org.pcmm.rcd.impl.CMTS</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.packetcable</groupId>
+            <artifactId>packetcable-driver</artifactId>
+            <version>1.3.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-yaml</artifactId>
+            <version>2.5.0</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+
+</project>
similarity index 50%
rename from packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java
rename to packetcable-emulator/src/main/java/org/pcmm/rcd/impl/CMTS.java
index b3a426632b25d0964e116d0f957000286e308ab2..e53439e604a475ddac6fb0fb888ed2392e3b10c5 100644 (file)
@@ -4,19 +4,20 @@
 
 package org.pcmm.rcd.impl;
 
-import org.pcmm.PCMMConstants;
-import org.pcmm.PCMMProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 import org.pcmm.gates.IGateSpec.Direction;
 import org.pcmm.rcd.ICMTS;
 
+import java.io.FileInputStream;
 import java.io.IOException;
-import java.net.InetAddress;
 import java.net.Socket;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
- * This class starts a mock CMTS that can be used for testing.
+ * Mock CMTS that can be used for testing. startServer() is called to start required threads after instantiation.
  */
 public class CMTS extends AbstractPCMMServer implements ICMTS {
 
@@ -80,23 +81,83 @@ public class CMTS extends AbstractPCMMServer implements ICMTS {
         * @throws IOException - should the server fail to start for reasons such as port contention.
         */
        public static void main(final String[] args) throws IOException {
-               final Set<String> upGates = new HashSet<>();
-               upGates.add("extrm_up");
-               final Set<String> dnGates = new HashSet<>();
-               dnGates.add("extrm_dn");
-               final Map<Direction, Set<String>> gates = new HashMap<>();
-               gates.put(Direction.UPSTREAM, upGates);
-               gates.put(Direction.DOWNSTREAM, dnGates);
-
-               final Map<String, Boolean> cmStatus = new HashMap<>();
-               final InetAddress invalidCmAddrInet = InetAddress.getByAddress(new byte[] {99, 99, 99, 99});
-               cmStatus.put(InetAddress.getByAddress(new byte[]{10, 32, 110, (byte) 180}).getHostAddress(), true);
-               cmStatus.put(InetAddress.getByAddress(new byte[]{10, 32, 110, (byte) 179}).getHostAddress(), true);
-               cmStatus.put(InetAddress.getByAddress(new byte[]{10, 32, 110, (byte) 178}).getHostAddress(), true);
-               cmStatus.put(invalidCmAddrInet.getHostAddress(), false);
-
-               final CMTS cmts = new CMTS(PCMMProperties.get(PCMMConstants.PCMM_PORT, Integer.class), gates, cmStatus);
+               final CmtsYaml config = getConfig(args[0]);
+               final CMTS cmts = new CMTS(config.port, config.getGates(), config.getCmStatus());
                cmts.startServer();
        }
 
+       /**
+        * Returns the object that represents the YAML file
+        * @param uri - the location of the YAML file
+        * @return - the config object
+        * @throws IOException - when the URI does not contain the proper YAML file
+        */
+       private static CmtsYaml getConfig(final String uri) throws IOException {
+               final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+               return mapper.readValue(new FileInputStream(uri), CmtsYaml.class);
+       }
+
+       /**
+        * Class to hold configuration settings in a YAML file
+        */
+       public static class CmtsYaml {
+               @JsonProperty("port")
+               private int port;
+
+               @JsonProperty("gates")
+               private Collection<GateConfigYaml> gateConfigs;
+
+               @JsonProperty("cmStatuses")
+               private Collection<CmStatusYaml> cmStatuses;
+
+               public Map<Direction, Set<String>> getGates() {
+                       final Map<Direction, Set<String>> out = new HashMap<>();
+
+                       for (final GateConfigYaml gateConfig : gateConfigs) {
+                               final Direction direction;
+                               if (gateConfig.gateType.equalsIgnoreCase("UPSTREAM")) {
+                                       direction = Direction.UPSTREAM;
+                               } else if (gateConfig.gateType.equalsIgnoreCase("DOWNSTREAM")) {
+                                       direction = Direction.DOWNSTREAM;
+                               } else direction = null;
+
+                               if (direction != null) {
+                                       out.put(direction, gateConfig.gateNames);
+                               }
+                       }
+                       return out;
+               }
+
+               public Map<String, Boolean> getCmStatus() {
+                       final Map<String, Boolean> out = new HashMap<>();
+
+                       for (final CmStatusYaml cmStatus : cmStatuses) {
+                               out.put(cmStatus.hostIp, cmStatus.status);
+                       }
+                       return out;
+               }
+       }
+
+       /**
+        * Class to hold the YAML gate configuration values
+        */
+       public static class GateConfigYaml {
+               @JsonProperty("type")
+               private String gateType;
+
+               @JsonProperty("names")
+               private Set<String> gateNames;
+       }
+
+       /**
+        * Class to hold the YAML Cable Modem configuration values
+        */
+       public static class CmStatusYaml {
+               @JsonProperty("host")
+               private String hostIp;
+
+               @JsonProperty("status")
+               private boolean status;
+       }
+
 }
index e2a806d44e0c5f0f4fd984b082658469d2881532..a301112d97df9881bef1bd6b529dece88a98e121 100644 (file)
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-
-         <dependency>
+        <dependency>
+            <groupId>org.opendaylight.packetcable</groupId>
+            <artifactId>packetcable-emulator</artifactId>
+            <version>1.3.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
-              <artifactId>mockito-core</artifactId>
+            <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/pom.xml b/pom.xml
index 24da7687cf43e56dea53a0876bb613eb0e764b51..70e8302e730447ab7c6a1eef2694d8109b1492cc 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,9 @@
                <module>features-packetcable-policy</module>
                <module>packetcable-policy-config</module>
                <module>packetcable-policy-karaf</module>
+
+               <!-- Jar module CMTS emulator for testing -->
+               <module>packetcable-emulator</module>
        </modules>
        <scm>
                <connection>scm:git:ssh://git.opendaylight.org:29418/packetcable.git</connection>