Skip to content

Commit

Permalink
Dump database once at end
Browse files Browse the repository at this point in the history
  • Loading branch information
amrabed committed Jun 9, 2015
1 parent 3d23e4b commit 5dc2c00
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/main/java/edu/vt/rhids/common/Database.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package edu.vt.rhids.common;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

import edu.vt.rhids.input.BoSC;
import edu.vt.rhids.util.Logger;
import edu.vt.rhids.util.Logger.Verbosity;

/**
* Normal-behavior Database
Expand Down Expand Up @@ -102,6 +106,20 @@ public double calculateSimilarity(Database other)
return dot / (norm1 * norm2);
}

public void dump(String id) throws FileNotFoundException
{
final String file = "/var/log/rhids/db-" + id + ".dump";
try (PrintStream out = new PrintStream(file))
{
Logger.log("Dumping database to " + file, Verbosity.MEDIUM);
for (BoSC bosc : keySet())
{
out.println(bosc);
}
Logger.log("Done", Verbosity.MEDIUM);
}
}

@Override
public String toString()
{
Expand Down
35 changes: 16 additions & 19 deletions src/main/java/edu/vt/rhids/main/Classifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

import edu.vt.rhids.common.Database;
Expand Down Expand Up @@ -41,30 +40,28 @@ public boolean trainUnconditionally() throws IOException
BoSC bosc;
String syscall;

try (PrintStream out = new PrintStream("/var/log/rhids/db-" + stats.getEpochSize() + ".dump"))
while (!RHIDS.isDoneTraining())
{
while (!RHIDS.isDoneTraining())
for (int i = 0; i < stats.getEpochSize(); i++)
{
for (int i = 0; i < stats.getEpochSize(); i++)
if ((syscall = SyscallParser.parse(reader)) != null)
{
if ((syscall = SyscallParser.parse(reader)) != null)
{
bosc = window.slide(syscall).getBoSC();
db.add(bosc);
out.println(bosc);
Logger.log(syscall + " => " + window + " => " + bosc, Verbosity.HIGH);
}
else
{
// Failed to train using input file
Logger.signal("Training failed", Verbosity.LOW);
return false;
}
bosc = window.slide(syscall).getBoSC();
db.add(bosc);
Logger.log(syscall + " => " + window + " => " + bosc, Verbosity.HIGH);
}
else
{
// Failed to train using input file
Logger.signal("Training failed", Verbosity.LOW);
db.dump(String.valueOf(stats.getEpochSize()));
return false;
}
Logger.log("Epoch " + stats.getTotalEpochs() + ": Database size is " + db.size(), Verbosity.MEDIUM);
stats.incrementTrainingEpochs();
}
Logger.log("Epoch " + stats.getTotalEpochs() + ": Database size is " + db.size(), Verbosity.MEDIUM);
stats.incrementTrainingEpochs();
}
db.dump(String.valueOf(stats.getEpochSize()));
return true;

// return train();
Expand Down

0 comments on commit 5dc2c00

Please sign in to comment.