summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main')
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRecord.java81
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRegistry.java83
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixIeModelGenerator.java129
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGenerator.java28
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGeneratorMojo.java177
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/TextTemplate.java155
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.java54
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/resources/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.tmpl65
8 files changed, 772 insertions, 0 deletions
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRecord.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRecord.java
new file mode 100644
index 0000000..a109d5b
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRecord.java
@@ -0,0 +1,81 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+
+import java.util.List;
+
+/**
+ * Iana record representation for parsing IPFIX xml models.
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public class IanaRecord {
+ public String name;
+ public String dataType;
+ public String group;
+ public String dataTypeSemantics;
+ public String elementId;
+ public String applicability;
+ public String status;
+ public String description;
+ public String units;
+ public List<String> xrefs;
+ public String registration_rule;
+ public String reserved;
+ public String references;
+ public String note;
+ public String range;
+ public String unassigned;
+ public String value;
+ public String comments;
+ public int enterpriseNumber = 0;
+
+ @Override
+ public String toString() {
+ return String.format("%s:{ \n" + " elementId:%s, \n"
+ + " dataType:%s, \n" + " dataTypeSemantis:%s, \n"
+ + " units:%s \n" + " status:%s \n" + " en: %s \n}", name,
+ elementId, dataType, dataTypeSemantics, units, status,
+ enterpriseNumber);
+ }
+
+ public IanaRecord() {
+ }
+
+ public IanaRecord(String name) {
+ this.name = name;
+ }
+
+ public boolean isValid() {
+
+ boolean notNull = (name != null) && (elementId != null)
+ && (dataType != null) && (status != null);
+
+ return notNull;
+ }
+ /**
+ * Clean up some manually written notes from ipfix.xml.
+ */
+ public void cleanup(){
+ if( dataType!=null && name!=null && name.startsWith("messageMD5Checksum") ){
+ dataType = dataType.replace("(16 bytes)","");
+ }
+
+ }
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRegistry.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRegistry.java
new file mode 100644
index 0000000..f613b0e
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IanaRegistry.java
@@ -0,0 +1,83 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+
+import java.util.List;
+
+/**
+ * Iana registry representation for parsing IPFIX xml models.
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public class IanaRegistry {
+ // -- sys --
+// private final static Logger logger = LoggerFactory.getLogger(IanaRegistry.class);
+ // -- model --
+ public String id;
+ public String title;
+ public String created;
+ public String updated;
+ public String xref;
+ public String note;
+ public String registration_rule;
+ public String people;
+ public List<IanaRecord> records;
+ public List<IanaRegistry> children;
+
+ /**
+ * Recursively find registry with given id.
+ * @param registry
+ * @param id
+ * @param maxDepth Maximum nesting depth.
+ * @return
+ */
+ public static IanaRegistry find( IanaRegistry registry, String id, int maxDepth ){
+ return find(registry, id, 0, maxDepth);
+ }
+
+ /**
+ * Find the first registry that matches id.
+ * (recursive depth first search)
+ * @param id
+ * @return registry or null if not found
+ */
+ public static IanaRegistry find( IanaRegistry registry, String id, int depth, int maxDepth ){
+ if(registry==null || depth > maxDepth ){
+ return null;
+ }
+ if(registry.id!=null && id.contentEquals(registry.id)){
+ return registry;
+ }
+ if( registry.children!=null ){
+ for( IanaRegistry child: registry.children ){
+ IanaRegistry reg = find(child, id, depth+1, maxDepth);
+ if( reg!=null){
+ return reg;
+ }
+ }
+ }
+ return null;
+ }
+ @Override
+ public String toString() {
+ int nchildren = children!=null?children.size():0;
+ int nrecords = records!=null?records.size():0;
+ return String.format("registry:{ id:\"%s\", nchildren:%d, nrecords:%d } ", id, nchildren, nrecords);
+ }
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixIeModelGenerator.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixIeModelGenerator.java
new file mode 100644
index 0000000..1adbe30
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixIeModelGenerator.java
@@ -0,0 +1,129 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import de.fhg.fokus.net.ipfix.api.IpfixIeSemantics;
+import de.fhg.fokus.net.ipfix.api.IpfixIeUnits;
+import de.fhg.fokus.net.ipfix.mojo.mgen.tmpl.IpfixIeTmpl.Tokens;
+
+/**
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public class IpfixIeModelGenerator implements IpfixModelGenerator {
+ // -- sys --
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+ // -- constants --
+ private final static String IANA_REGISTRY_ID = "ipfix-information-element-definitions";
+ // -- model --
+ private final TextTemplate txtTemplate;
+ private final IanaRegistry registry;
+ private final String targetPackage;
+ private final File targetFolder;
+
+ public IpfixIeModelGenerator(TextTemplate txtTemplate,
+ IanaRegistry ianaRegistry, String targetPackage, File prefixFolder ) {
+ this.txtTemplate = txtTemplate;
+ this.targetPackage = targetPackage;
+ this.targetFolder = new File(prefixFolder,targetPackage.replaceAll("\\.", File.separator) );
+
+ this.registry = IanaRegistry.find(ianaRegistry, IANA_REGISTRY_ID, 10);
+ if (registry == null) {
+ logger.debug("Registry ID {} was not found!", IANA_REGISTRY_ID);
+ return;
+ }
+ logger.debug("Found registry: {}", registry);
+ }
+
+ private static String getClassNameForIe(IanaRecord record) {
+ return String.format("IpfixIe%s%s", Character.toUpperCase(record.name.charAt(0)),
+ record.name.substring(1));
+ }
+ private static String getCodecName( IanaRecord record ){
+ return String.format("IpfixIeCodec%s%s", Character.toUpperCase(record.dataType.charAt(0)),
+ record.dataType.substring(1));
+
+ }
+ private static String getClassDocumentation( IanaRecord record ){
+ return String.format("<pre>\n%s\n</pre>", record.toString());
+ }
+ private static String getImports( IanaRecord record ){
+ return "";
+ }
+// private static String getEnterpriseNumber( IanaRecord record ){
+// return record.enterpriseNumber==null?0:record.enterpriseNumber;
+// }
+ @Override
+ public void generate() {
+ // -- creating destination folder
+ if( !targetFolder.canRead() ){
+ targetFolder.mkdirs();
+ }
+
+ // -- processing records --
+ if (registry.records == null || registry.records.size() == 0) {
+ logger.warn("No records in registry found.");
+ return;
+ }
+ Map<String, String> replacements = new HashMap<String, String>();
+ // -- common replacements --
+ replacements.put(Tokens.TARGET_PACKAGE+"", targetPackage);
+
+ for (IanaRecord record : registry.records) {
+ // IanaRecord record = registry.records.get(0);
+ if (record != null && record.isValid()) {
+ record.cleanup();
+ logger.debug(record + "");
+ // -- record replacements --
+ String ieClassName = getClassNameForIe(record);
+ replacements.put(Tokens.CLASS_DOCUMENTATION+"",getClassDocumentation(record));
+ replacements.put(Tokens.IE_ID+"",record.elementId);
+ replacements.put(Tokens.IE_CLASS_NAME+"", ieClassName);
+ replacements.put(Tokens.IE_NAME+"", record.name);
+ replacements.put(Tokens.IE_CODEC+"", getCodecName(record));
+ replacements.put(Tokens.IE_DATA_TYPES+"", record.dataType.toUpperCase());
+ replacements.put(Tokens.IE_SEMANTICS+"", IpfixIeSemantics.getFromModelName(record.dataTypeSemantics)+"");
+ replacements.put(Tokens.IE_STATUS+"", record.status.toUpperCase());
+ replacements.put(Tokens.IE_UNITS+"", IpfixIeUnits.getFromModelName(record.units)+"");
+ replacements.put(Tokens.IMPORTS+"", getImports(record));
+ replacements.put(Tokens.IE_ENTERPRISE_NUMBER+"",record.enterpriseNumber+"");
+
+
+ try {
+ txtTemplate.generateFile(replacements, new File(targetFolder,ieClassName+".java" ));
+ } catch (IOException e) {
+ logger.error("Could not generate: {}, {}",ieClassName, e.getMessage());
+ }
+
+ // String.format("IpfixIe",record.name.to) );
+ }
+
+ }
+
+ }
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGenerator.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGenerator.java
new file mode 100644
index 0000000..91fa2c7
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGenerator.java
@@ -0,0 +1,28 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+/**
+ * IPFIX model generator.
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public interface IpfixModelGenerator {
+ public void generate();
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGeneratorMojo.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGeneratorMojo.java
new file mode 100644
index 0000000..adba39d
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/IpfixModelGeneratorMojo.java
@@ -0,0 +1,177 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.IOUtil;
+
+import com.thoughtworks.xstream.XStream;
+
+import de.fhg.fokus.net.ipfix.mojo.mgen.tmpl.IpfixIeTmpl;
+
+/**
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ *
+ * @goal generate-ipfix-model
+ * @phase generate-sources
+ *
+ */
+public class IpfixModelGeneratorMojo extends AbstractMojo {
+ // -- parameters --
+ /**
+ * @parameter expression="${generate-ipfix-model.targetPackage}"
+ * default-value="de.fhg.fokus.net.ipfix.model"
+ */
+ private String targetPackage;
+ /**
+ * @parameter expression="${generate-ipfix-model.modelDir}"
+ * default-value="model/"
+ *
+ */
+ private File modelDir;
+ /**
+ * @parameter expression="${project.build.directory}"
+ * @required
+ *
+ */
+ private File buildDir;
+ private File targetModelDir;
+ // private org.apache.maven.plugin. mavenProject;
+
+ // -- model --
+ private final List<IpfixModelGenerator> modelGenerators = new ArrayList<IpfixModelGenerator>();
+ private final XStream xstream;
+ private TextTemplate txtTemplateIpfixIe;
+
+ public IpfixModelGeneratorMojo() {
+ // -- setup xml reader --
+ xstream = new XStream();
+ xstream.alias("registry", IanaRegistry.class);
+ xstream.alias("record", IanaRecord.class);
+ xstream.alias("xref", String.class);
+ xstream.addImplicitCollection(IanaRegistry.class, "records",
+ IanaRecord.class);
+ xstream.addImplicitCollection(IanaRegistry.class, "children",
+ IanaRegistry.class);
+ xstream.addImplicitCollection(IanaRecord.class, "xrefs");
+ xstream.aliasAttribute(IanaRegistry.class, "id", "id");
+ // -- setup text templates --
+ try {
+ StringWriter writer = new StringWriter();
+ IOUtil.copy(IpfixIeTmpl.class.getResourceAsStream(IpfixIeTmpl.FILE.getName()),
+ writer);
+ txtTemplateIpfixIe = new TextTemplate(writer.toString());
+ } catch (IOException e) {
+ throw new RuntimeException("Error loading template:"+IpfixIeTmpl.FILE.toString() );
+ }
+
+ }
+
+ private void checkPreconditions() throws MojoFailureException {
+ if (txtTemplateIpfixIe == null) {
+ throw new MojoFailureException(
+ "Could not initialize ipfix ie txt template file!");
+ }
+ }
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ checkPreconditions();
+ loadModels();
+ setupGeneratedSourcesDir();
+ }
+
+ private final FilenameFilter xmlFilenameFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".xml");
+ }
+ };
+
+ /**
+ * Search for ipfix xml model files. Format
+ * http://www.iana.org/assignments/ipfix/ipfix.xml
+ *
+ * @throws MojoFailureException
+ */
+ private void loadModels() throws MojoFailureException {
+ getLog().info("== LOAD IPFIX MODELS ==");
+
+ if (!modelDir.exists()) {
+ throw new MojoFailureException(
+ "IPFIX model directory does not exist!: "
+ + modelDir.getAbsolutePath());
+ }
+ getLog().info("Searching models in " + modelDir.getAbsolutePath());
+ for (File file : modelDir.listFiles(xmlFilenameFilter)) {
+ if (file.isFile() && file.canRead()) {
+ getLog().info("Found model: " + file.getName());
+ try {
+ FileInputStream fis = new FileInputStream(file);
+ IanaRegistry registry = (IanaRegistry) xstream.fromXML(fis);
+ modelGenerators.add(new IpfixIeModelGenerator(
+ txtTemplateIpfixIe, registry, targetPackage, targetModelDir));
+ } catch (Exception e) {
+ e.printStackTrace();
+ getLog().error(e.getMessage());
+ }
+ }
+ }
+ }
+
+ private void setupGeneratedSourcesDir() {
+ getLog().info("== SETUP GENERATED SOURCES ==");
+ // -- setup dirs --
+ targetModelDir = new File(buildDir, String.format(
+ "generated-sources%s%s", File.separator, targetPackage.replace(
+ ".", File.separator)));
+ if (targetModelDir.mkdirs()) {
+ getLog().info("Creating " + targetModelDir);
+ }
+ getLog().info("TARGET_MODEL_DIR: " + targetModelDir);
+
+ }
+
+ public static void main(String[] args) {
+ // xstream quick test
+ XStream xstream = new XStream();
+ xstream.alias("registry", IanaRegistry.class);
+ xstream.alias("record", IanaRecord.class);
+ xstream.addImplicitCollection(IanaRegistry.class, "records",
+ IanaRecord.class);
+ IanaRegistry reg = new IanaRegistry();
+ reg.id = "1";
+ reg.records = new ArrayList<IanaRecord>();
+ reg.records.add(new IanaRecord("test"));
+ reg.records.add(new IanaRecord("test"));
+
+ System.out.println(xstream.toXML(reg));
+
+ }
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/TextTemplate.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/TextTemplate.java
new file mode 100644
index 0000000..ff95bd8
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/TextTemplate.java
@@ -0,0 +1,155 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple text template engine using {@link Matcher}.
+ * Tokens are specified by %{sometoken}% . The predefined
+ * tokens are:
+ * <pre>
+ * %{dateTime} current date time
+ *
+ * </pre>
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public final class TextTemplate {
+ // -- constants --
+ private enum PredefinedTags {
+ dateTime
+ }
+ // -- model --
+ private final String template;
+ private final Pattern pattern = Pattern.compile("\\%\\{(.+?)\\}\\%");
+ public abstract class Tag {
+ private final String name;
+ public Tag(String name) {
+ this.name = name;
+ }
+ /**
+ *
+ * @return tag name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @return tag value
+ */
+ public abstract String getValue();
+ }
+ private final Map<String, Tag> mapPredefinedTags = new ConcurrentHashMap<String, Tag>();
+
+ public TextTemplate(String template ){
+ this.template = template;
+ }
+ public TextTemplate(File templateFile) throws IOException {
+ this.template = readFileContents(templateFile);
+ setupPredefinedTags();
+ }
+ private void setupPredefinedTags(){
+ // DateTime
+ registerDynamicTag(new Tag(PredefinedTags.dateTime+"") {
+ @Override
+ public String getValue() {
+ return new Date().toString();
+ }
+ });
+ }
+ public void registerDynamicTag(Tag tag){
+ mapPredefinedTags.put(tag.getName(), tag);
+ }
+
+ public static String readFileContents(File file) throws IOException {
+ StringBuilder buf = new StringBuilder();
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ String line;
+ while ((line = br.readLine()) != null) {
+ buf.append(line);
+ buf.append("\n");
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Generate file using the replacements map
+ *
+ * @param replacements
+ * @param destFile
+ * @throws IOException
+ */
+ public void generateFile(Map<String, String> replacements, File destFile)
+ throws IOException {
+ writeFile(destFile, process(replacements));
+ }
+
+ /**
+ *
+ * From http://stackoverflow.com/questions/959731/how-to-replace-a-set-of-
+ * tokens-in-a-java-string
+ *
+ * @param replacements
+ * @return generated text
+ */
+ private String process(Map<String, String> replacements) {
+ Matcher matcher = pattern.matcher(template);
+
+ // populate the replacements map ...
+ StringBuffer sb = new StringBuffer();
+ while (matcher.find()) {
+ String token = matcher.group(1);
+ String replacement = replacements.get(token);
+ // process predefined tags
+ if(replacement==null){
+ Tag tag = mapPredefinedTags.get(token);
+ if(tag!=null){
+ replacement = tag.getValue();
+ }
+ }
+ if(replacement!=null){
+ matcher.appendReplacement(sb, replacement);
+ }
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+
+ }
+
+ private void writeFile(File dstFile, String contents) throws IOException {
+ BufferedWriter out = new BufferedWriter(new FileWriter(dstFile));
+ out.write(contents);
+ out.close();
+ }
+ @Override
+ public String toString() {
+ return template;
+ }
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.java
new file mode 100644
index 0000000..cd2d0e1
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/java/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.java
@@ -0,0 +1,54 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.mojo.mgen.tmpl;
+
+import java.io.File;
+/**
+ * Text template definitions for generating IPFIX information elements.
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public class IpfixIeTmpl {
+ /**
+ * Defined tokens in the template.
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+ public static enum Tokens {
+ TARGET_PACKAGE,
+ IMPORTS,
+ CODEC_METHODS,
+ CLASS_DOCUMENTATION,
+ IE_ENTERPRISE_NUMBER,
+ IE_ID,
+ IE_CODEC,
+ IE_CLASS_NAME,
+ IE_DATA_TYPES,
+ IE_SEMANTICS,
+ IE_STATUS,
+ IE_NAME,
+ IE_UNITS
+ }
+ /**
+ * IpfixIe.tmpl
+ */
+ public static File FILE = new File(IpfixIeTmpl.class.getResource(
+ IpfixIeTmpl.class.getSimpleName() + ".tmpl").getFile());
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/resources/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.tmpl b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/resources/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.tmpl
new file mode 100644
index 0000000..223b581
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-model-generator/src/main/resources/de/fhg/fokus/net/ipfix/mojo/mgen/tmpl/IpfixIeTmpl.tmpl
@@ -0,0 +1,65 @@
+package %{TARGET_PACKAGE}%;
+// === ipfix-model-generator: auto-generated file - do not edit! ===
+import de.fhg.fokus.net.ipfix.api.IpfixFieldSpecifier;
+import de.fhg.fokus.net.ipfix.api.IpfixIe;
+import de.fhg.fokus.net.ipfix.api.IpfixIeSemantics;
+import de.fhg.fokus.net.ipfix.api.IpfixIeStatus;
+import de.fhg.fokus.net.ipfix.api.IpfixIeUnits;
+import de.fhg.fokus.net.ipfix.api.codec.%{IE_CODEC}%;
+
+%{IMPORTS}%
+
+/**
+ * %{CLASS_DOCUMENTATION}%
+ *
+ */
+public final class %{IE_CLASS_NAME}% extends %{IE_CODEC}% implements IpfixIe {
+ // -- model --
+ private final IpfixFieldSpecifier fieldSpecifier;
+
+ @Override
+ public IpfixFieldSpecifier getFieldSpecifier() {
+ return fieldSpecifier;
+ }
+
+ public %{IE_CLASS_NAME}%() {
+ this.fieldSpecifier = new IpfixFieldSpecifier(%{IE_ENTERPRISE_NUMBER}%).setId(%{IE_ID}%)
+ .setFieldLength(this.fieldLength);
+ }
+ public %{IE_CLASS_NAME}%( int length ) {
+ this.fieldLength = length;
+ this.fieldSpecifier = new IpfixFieldSpecifier(%{IE_ENTERPRISE_NUMBER}%).setId(%{IE_ID}%)
+ .setFieldLength(this.fieldLength);
+ }
+ public %{IE_CLASS_NAME}%( int length, long enterpriseNumber, boolean isScope ) {
+ this.fieldLength = length;
+ this.fieldSpecifier = new IpfixFieldSpecifier(enterpriseNumber).setId(%{IE_ID}%)
+ .setFieldLength(this.fieldLength).setScope(isScope);
+ }
+
+
+ @Override
+ public IpfixIeSemantics getSemantics() {
+ return IpfixIeSemantics.%{IE_SEMANTICS}%;
+ }
+
+ @Override
+ public IpfixIeStatus getStatus() {
+ return IpfixIeStatus.%{IE_STATUS}%;
+ }
+
+ @Override
+ public String getName() {
+ return "%{IE_NAME}%";
+ }
+
+ @Override
+ public int getLength() {
+ return fieldSpecifier.getIeLength();
+ }
+
+ @Override
+ public IpfixIeUnits getUnits() {
+ return IpfixIeUnits.%{IE_UNITS}%;
+ }
+}