Details
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java b/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
index d05796d..cc9feea 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
@@ -21,18 +21,6 @@
//----------------------------------------------------------------------------
package br.ufrgs.inf.bdinetr;
-import jade.BootProfileImpl;
-import jade.core.Profile;
-import jade.core.ProfileImpl;
-import jade.core.Specifier;
-import jade.core.event.NotificationService;
-import jade.core.messaging.TopicManagementHelper;
-import jade.core.messaging.TopicManagementService;
-import jade.tools.rma.rma;
-import jade.wrapper.AgentContainer;
-import jade.wrapper.AgentController;
-import jade.wrapper.PlatformController;
-
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -59,7 +47,19 @@ import br.ufrgs.inf.bdinetr.domain.Observable;
import br.ufrgs.inf.bdinetr.domain.Role;
import br.ufrgs.inf.bdinetr.domain.Router;
import br.ufrgs.inf.bdinetr.domain.dummy.DummyRouterComponentFactory;
+import br.ufrgs.inf.bdinetr.domain.escape.EscapeRouterComponentFactory;
import br.ufrgs.inf.bdinetr.domain.omnet.OMNeTRouterComponentFactory;
+import jade.BootProfileImpl;
+import jade.core.Profile;
+import jade.core.ProfileImpl;
+import jade.core.Specifier;
+import jade.core.event.NotificationService;
+import jade.core.messaging.TopicManagementHelper;
+import jade.core.messaging.TopicManagementService;
+import jade.tools.rma.rma;
+import jade.wrapper.AgentContainer;
+import jade.wrapper.AgentController;
+import jade.wrapper.PlatformController;
/**
* @author Ingrid Nunes
@@ -67,7 +67,7 @@ import br.ufrgs.inf.bdinetr.domain.omnet.OMNeTRouterComponentFactory;
public class BDINetRApp {
enum SimulationType {
- OMNeT, SIMPLE_NETWORK, COMPLEX_NETWORK
+ OMNeT, SIMPLE_NETWORK, COMPLEX_NETWORK, ESCAPE
};
private static final Set<Link> AFFECTED_LINKS;
@@ -75,8 +75,7 @@ public class BDINetRApp {
private static final SimulationType SIMULATION_TYPE = SimulationType.SIMPLE_NETWORK;
static {
- PropertyConfigurator.configure(BDINetRApp.class
- .getResource("log4j.properties"));
+ PropertyConfigurator.configure(BDINetRApp.class.getResource("log4j.properties"));
NETWORK = new Network();
AFFECTED_LINKS = new HashSet<>();
@@ -85,49 +84,51 @@ public class BDINetRApp {
switch (SIMULATION_TYPE) {
case OMNeT:
factory = new OMNeTRouterComponentFactory();
- NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.idsModule"),
- "ids_one", Role.ANOMALY_DETECTION.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.linkMonitor"),
- "linkmonitor_one", Role.LINK_MONITOR.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.classifier"),
- "classifier_one", Role.CLASSIFIER.getId(), factory));
- NETWORK.addRouter(new Router(
- new Ip("Inet.sas1.core0.flowExporter"), "flowexporter_one",
+ NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.idsModule"), "ids_one", Role.ANOMALY_DETECTION.getId(),
+ factory));
+ NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.linkMonitor"), "linkmonitor_one",
+ Role.LINK_MONITOR.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.classifier"), "classifier_one",
+ Role.CLASSIFIER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.flowExporter"), "flowexporter_one",
Role.FLOW_EXPORTER.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.rateLimiter"),
- "ratelimiter_one", Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Inet.sas1.core0.rateLimiter"), "ratelimiter_one",
+ Role.RATE_LIMITER.getId(), factory));
break;
case SIMPLE_NETWORK:
factory = new DummyRouterComponentFactory();
- NETWORK.addRouter(new Router(new Ip("LC+RL"), Role.LINK_MONITOR
- .getId() | Role.RATE_LIMITER.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("IPC+RL"),
- Role.ANOMALY_DETECTION.getId() | Role.RATE_LIMITER.getId(),
- factory));
- NETWORK.addRouter(new Router(new Ip("FC+RL"), Role.CLASSIFIER
- .getId() | Role.RATE_LIMITER.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("FE"), Role.FLOW_EXPORTER
- .getId(), factory));
+ NETWORK.addRouter(
+ new Router(new Ip("LC+RL"), Role.LINK_MONITOR.getId() | Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(
+ new Router(new Ip("IPC+RL"), Role.ANOMALY_DETECTION.getId() | Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(
+ new Router(new Ip("FC+RL"), Role.CLASSIFIER.getId() | Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("FE"), Role.FLOW_EXPORTER.getId(), factory));
AFFECTED_LINKS.add(new Link("AFFECTED_LINK"));
break;
case COMPLEX_NETWORK:
factory = new DummyRouterComponentFactory();
- NETWORK.addRouter(new Router(new Ip("RouterLM"), Role.LINK_MONITOR
- .getId(), factory));
- NETWORK.addRouter(new Router(new Ip("RouterRL"), Role.RATE_LIMITER
- .getId(), factory));
- NETWORK.addRouter(new Router(new Ip("RouterAD"),
- Role.ANOMALY_DETECTION.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("RouterCL"), Role.CLASSIFIER
- .getId(), factory));
- NETWORK.addRouter(new Router(new Ip("RouterCL+FE"), Role.CLASSIFIER
- .getId() | Role.FLOW_EXPORTER.getId(), factory));
- NETWORK.addRouter(new Router(new Ip("RouterFE"), Role.FLOW_EXPORTER
- .getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("RouterLM"), Role.LINK_MONITOR.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("RouterRL"), Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("RouterAD"), Role.ANOMALY_DETECTION.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("RouterCL"), Role.CLASSIFIER.getId(), factory));
+ NETWORK.addRouter(
+ new Router(new Ip("RouterCL+FE"), Role.CLASSIFIER.getId() | Role.FLOW_EXPORTER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("RouterFE"), Role.FLOW_EXPORTER.getId(), factory));
AFFECTED_LINKS.add(new Link("AFFECTED_LINK"));
break;
+ case ESCAPE:
+ factory = new EscapeRouterComponentFactory();
+ NETWORK.addRouter(new Router(new Ip("Link Monitor"), Role.LINK_MONITOR.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Rate Limiter"), Role.RATE_LIMITER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Anomaly Detection"), Role.ANOMALY_DETECTION.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Classifier"), Role.CLASSIFIER.getId(), factory));
+ NETWORK.addRouter(new Router(new Ip("Flow Exporter"), Role.FLOW_EXPORTER.getId(), factory));
+
+ // AFFECTED_LINKS.add(new Link("AFFECTED_LINK"));
+ break;
}
Set<Router> routers = NETWORK.getRouters();
@@ -136,8 +137,7 @@ public class BDINetRApp {
for (Router router2 : routers) {
if (router2.hasRole(Role.LINK_MONITOR)) {
((Observable) router1.getRole(Role.RATE_LIMITER))
- .addObserver(((Observer) router2
- .getRole(Role.LINK_MONITOR)));
+ .addObserver(((Observer) router2.getRole(Role.LINK_MONITOR)));
}
}
}
@@ -162,8 +162,7 @@ public class BDINetRApp {
this.bootProfile = new ProfileImpl();
bootProfile.setParameter(Profile.GUI, "truw");
- bootProfile.setParameter(BootProfileImpl.PLATFORM_ID,
- BDINetRApp.class.getSimpleName());
+ bootProfile.setParameter(BootProfileImpl.PLATFORM_ID, BDINetRApp.class.getSimpleName());
bootProfile.setParameter(Profile.DETECT_MAIN, "false");
jade.util.leap.List result = new jade.util.leap.ArrayList();
@@ -184,14 +183,12 @@ public class BDINetRApp {
log.info("Plataform parameters: " + bootProfile);
this.runtime = jade.core.Runtime.instance();
- PlatformController controller = runtime
- .createMainContainer(bootProfile);
+ PlatformController controller = runtime.createMainContainer(bootProfile);
for (Router router : NETWORK.getRouters()) {
try {
- AgentController ac = ((AgentContainer) controller)
- .acceptNewAgent(router.getId(),
- NETWORK.getAgent(router));
+ AgentController ac = ((AgentContainer) controller).acceptNewAgent(router.getId(),
+ NETWORK.getAgent(router));
ac.start();
} catch (Exception e) {
log.error(e);
@@ -227,8 +224,7 @@ public class BDINetRApp {
for (Link link : AFFECTED_LINKS) {
for (Router router : NETWORK.getRouters()) {
if (router.hasRole(Role.LINK_MONITOR)) {
- LinkMonitor lm = (LinkMonitor) router
- .getRole(Role.LINK_MONITOR);
+ LinkMonitor lm = (LinkMonitor) router.getRole(Role.LINK_MONITOR);
lm.setOverUsage(link, true);
}
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/AbstractRouterComponent.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/AbstractRouterComponent.java
new file mode 100644
index 0000000..c8d220d
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/AbstractRouterComponent.java
@@ -0,0 +1,41 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes, Frederico Schardong
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.util.Observable;
+
+import br.ufrgs.inf.bdinetr.domain.Router;
+import br.ufrgs.inf.bdinetr.domain.RouterComponent;
+
+/**
+ * @author Ingrid Nunes, Frederico Schardong
+ */
+public abstract class AbstractRouterComponent extends Observable implements
+ RouterComponent {
+
+ protected final Router router;
+
+ public AbstractRouterComponent(Router router) {
+ this.router = router;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeAnomalyDetection.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeAnomalyDetection.java
new file mode 100644
index 0000000..e84e729
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeAnomalyDetection.java
@@ -0,0 +1,87 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Set;
+
+import br.ufrgs.inf.bdinetr.domain.AnomalyDetection;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+import br.ufrgs.inf.bdinetr.domain.Link;
+import br.ufrgs.inf.bdinetr.domain.Router;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.AnomalousEvent;
+
+/**
+ * @author Alberto Egon and Ingrid Nunes
+ */
+public class EscapeAnomalyDetection extends EscapeRouterComponent implements
+ AnomalyDetection, Observer {
+
+ private final Set<AnomalousEvent> events;
+
+ public EscapeAnomalyDetection(Router router) {
+ super(router);
+ this.events = new HashSet<>();
+ EventBroker.getInstance().addObserver(this);
+ }
+
+ @Override
+ public Set<Ip> detectIntrusion(Link link) {
+ Object[] params = new Object[2];
+ params[0] = router.getIp().getAddress();
+ params[1] = "on";
+ invoke("togglereport", params);
+
+ synchronized (events) {
+ while (events.isEmpty()) {
+ try {
+ events.wait();
+ } catch (InterruptedException e) {
+ log.warn(e);
+ }
+ }
+
+ Set<Ip> outliers = new HashSet<>();
+ Iterator<AnomalousEvent> it = events.iterator();
+ while (it.hasNext()) {
+ AnomalousEvent event = it.next();
+ outliers.add(event.getIp());
+ it.remove();
+ }
+ return outliers;
+ }
+ }
+
+ @Override
+ public synchronized void update(Observable o, Object arg) {
+ if (arg instanceof AnomalousEvent) {
+ synchronized (events) {
+ events.add((AnomalousEvent) arg);
+ events.notifyAll();
+ }
+ }
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeClassifier.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeClassifier.java
new file mode 100644
index 0000000..1235a45
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeClassifier.java
@@ -0,0 +1,94 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Set;
+
+import br.ufrgs.inf.bdinetr.domain.Classifier;
+import br.ufrgs.inf.bdinetr.domain.Flow;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+import br.ufrgs.inf.bdinetr.domain.Router;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.ThreatEvent;
+
+/**
+ * @author Alberto Egon and Ingrid Nunes
+ */
+public class EscapeClassifier extends EscapeRouterComponent implements
+ Classifier, Observer {
+
+ private static final long WAITING_TIME = 70000; // 70s
+
+ private final Set<ThreatEvent> events;
+
+ public EscapeClassifier(Router router) {
+ super(router);
+ this.events = new HashSet<>();
+ EventBroker.getInstance().addObserver(this);
+ }
+
+ @Override
+ public Set<Flow> classifyFlows(Ip ip) {
+ synchronized (events) {
+ long begin = System.currentTimeMillis();
+ long elapsed = System.currentTimeMillis() - begin;
+ while (events.isEmpty() || (elapsed < WAITING_TIME)) {
+ try {
+ log.info("Elapsed time: " + elapsed + " - Events empty: "
+ + events.isEmpty());
+ long timeout = (WAITING_TIME - elapsed) < 0 ? 0
+ : WAITING_TIME - elapsed;
+ events.wait(timeout);
+ elapsed = System.currentTimeMillis() - begin;
+ } catch (InterruptedException e) {
+ log.warn(e);
+ }
+ }
+
+ log.info("Finished receiving Threat events. Elapsed time: "
+ + elapsed);
+
+ Set<Flow> flows = new HashSet<>();
+ Iterator<ThreatEvent> it = events.iterator();
+ while (it.hasNext()) {
+ ThreatEvent event = it.next();
+ flows.add(event.getFlow());
+ it.remove();
+ }
+ return flows;
+ }
+ }
+
+ @Override
+ public synchronized void update(Observable o, Object arg) {
+ if (arg instanceof ThreatEvent) {
+ synchronized (events) {
+ events.add((ThreatEvent) arg);
+ events.notifyAll();
+ }
+ }
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeFlowExporter.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeFlowExporter.java
new file mode 100644
index 0000000..fb26d26
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeFlowExporter.java
@@ -0,0 +1,42 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes, Frederico Schardong
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import br.ufrgs.inf.bdinetr.domain.FlowExporter;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+import br.ufrgs.inf.bdinetr.domain.Router;
+
+/**
+ * @author Ingrid Nunes, Frederico Schardong
+ */
+public class EscapeFlowExporter extends AbstractRouterComponent implements FlowExporter {
+
+ public EscapeFlowExporter(Router router) {
+ super(router);
+ }
+
+ @Override
+ public void turnFlowExporterOn(Ip ip) {
+
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeLinkMonitor.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeLinkMonitor.java
new file mode 100644
index 0000000..c8fb2ef
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeLinkMonitor.java
@@ -0,0 +1,90 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Set;
+
+import br.ufrgs.inf.bdinetr.domain.LimitLinkEvent;
+import br.ufrgs.inf.bdinetr.domain.Link;
+import br.ufrgs.inf.bdinetr.domain.LinkMonitor;
+import br.ufrgs.inf.bdinetr.domain.Router;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.OverUsageEvent;
+
+/**
+ * @author Alberto Egon and Ingrid Nunes
+ */
+public class EscapeLinkMonitor extends EscapeRouterComponent implements
+ LinkMonitor, Observer {
+
+ private final Map<Link, Boolean> overUsageLinks;
+ private boolean received;
+
+ public EscapeLinkMonitor(Router router) {
+ super(router);
+ this.overUsageLinks = new HashMap<>();
+ EventBroker.getInstance().addObserver(this);
+ this.received = false;
+ }
+
+ @Override
+ public Set<Link> getLinks() {
+ return overUsageLinks.keySet();
+ }
+
+ @Override
+ public boolean isOverUsage(Link link) {
+ Boolean overUsage = this.overUsageLinks.get(link);
+ if (overUsage == null)
+ overUsage = false;
+ return overUsage;
+ }
+
+ @Override
+ public void removeLink(Link link) {
+ this.overUsageLinks.remove(link);
+ }
+
+ @Override
+ public void setOverUsage(Link link, boolean overUsage) {
+ this.overUsageLinks.put(link, overUsage);
+ setChanged();
+ notifyObservers(link);
+ }
+
+ @Override
+ public synchronized void update(Observable o, Object arg) {
+ if (arg instanceof OverUsageEvent && !received) {
+ setOverUsage(((OverUsageEvent) arg).getLink(), true);
+ this.received = true;
+ } else if (arg instanceof LimitLinkEvent) {
+ LimitLinkEvent event = (LimitLinkEvent) arg;
+ if (this.isOverUsage(event.getLink())) {
+ this.setOverUsage(event.getLink(), false);
+ }
+ }
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRateLimiter.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRateLimiter.java
new file mode 100644
index 0000000..f86a2bf
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRateLimiter.java
@@ -0,0 +1,84 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes, Frederico Schardong
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import br.ufrgs.inf.bdinetr.domain.Flow;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+import br.ufrgs.inf.bdinetr.domain.LimitLinkEvent;
+import br.ufrgs.inf.bdinetr.domain.Link;
+import br.ufrgs.inf.bdinetr.domain.Observable;
+import br.ufrgs.inf.bdinetr.domain.RateLimiter;
+import br.ufrgs.inf.bdinetr.domain.Router;
+
+/**
+ * @author Ingrid Nunes, Frederico Schardong
+ */
+public class EscapeRateLimiter extends AbstractRouterComponent implements
+ RateLimiter, Observable {
+
+ private final Map<Flow, Integer> rateLimitedflows;
+ private final Map<Ip, Integer> rateLimitedIps;
+ private final Map<Link, Integer> rateLimitedLinks;
+
+ public EscapeRateLimiter(Router router) {
+ super(router);
+ this.rateLimitedLinks = new HashMap<>();
+ this.rateLimitedIps = new HashMap<>();
+ this.rateLimitedflows = new HashMap<>();
+ }
+
+ @Override
+ public void limitFlow(Flow flow, int rate) {
+ this.rateLimitedflows.put(flow, rate);
+ }
+
+ @Override
+ public void limitIp(Ip ip, int rate) {
+ this.rateLimitedIps.put(ip, rate);
+ }
+
+ @Override
+ public void limitLink(Link link, int rate) {
+ this.rateLimitedLinks.put(link, rate);
+ setChanged();
+ notifyObservers(new LimitLinkEvent(link));
+ }
+
+ @Override
+ public void unlimitFlow(Flow flow) {
+ this.rateLimitedflows.remove(flow);
+ }
+
+ @Override
+ public void unlimitIp(Ip ip) {
+ this.rateLimitedIps.remove(ip);
+ }
+
+ @Override
+ public void unlimitLink(Link link) {
+ this.rateLimitedLinks.remove(link);
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponent.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponent.java
new file mode 100644
index 0000000..e795682
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponent.java
@@ -0,0 +1,84 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Observable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+
+import br.ufrgs.inf.bdinetr.domain.Router;
+import br.ufrgs.inf.bdinetr.domain.RouterComponent;
+
+/**
+ * @author Alberto Egon and Ingrid Nunes
+ */
+public abstract class EscapeRouterComponent extends Observable implements
+ RouterComponent {
+
+ private static final String OMNeT_ADDRESS = "http://localhost:8080/RPC2";
+
+ private final XmlRpcClient adaptorRPC;
+ protected final Log log;
+ protected final Router router;
+
+ public EscapeRouterComponent(Router router) {
+ this.router = router;
+ this.log = LogFactory.getLog(getClass());
+
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+
+ try {
+ config.setServerURL(new URL(OMNeT_ADDRESS));
+ } catch (MalformedURLException mue) {
+ mue.printStackTrace();
+ }
+
+ this.adaptorRPC = new XmlRpcClient();
+ this.adaptorRPC.setConfig(config);
+ }
+
+ public Object invoke(String remoteOp, Object[] args) {
+ log.info("Invoking operation: " + remoteOp);
+ for (int i = 0; i < args.length; i++) {
+ log.info("args[" + i + "] = " + args[i]);
+ }
+
+ Object result = null;
+
+ try {
+ result = this.adaptorRPC.execute(router.getType() + "." + remoteOp,
+ args);
+ } catch (XmlRpcException xre) {
+ xre.printStackTrace();
+ }
+
+ log.info("Done");
+ return result;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponentFactory.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponentFactory.java
new file mode 100644
index 0000000..5a7db6e
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EscapeRouterComponentFactory.java
@@ -0,0 +1,62 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes, Frederico Schardong
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import br.ufrgs.inf.bdinetr.domain.AbstractRouterComponentFactory;
+import br.ufrgs.inf.bdinetr.domain.AnomalyDetection;
+import br.ufrgs.inf.bdinetr.domain.Classifier;
+import br.ufrgs.inf.bdinetr.domain.FlowExporter;
+import br.ufrgs.inf.bdinetr.domain.LinkMonitor;
+import br.ufrgs.inf.bdinetr.domain.RateLimiter;
+import br.ufrgs.inf.bdinetr.domain.Router;
+
+/**
+ * @author Ingrid Nunes, Frederico Schardong
+ */
+public class EscapeRouterComponentFactory extends AbstractRouterComponentFactory {
+
+ @Override
+ public AnomalyDetection createAnomalyDetection(Router router) {
+ return new EscapeAnomalyDetection(router);
+ }
+
+ @Override
+ public Classifier createClassifier(Router router) {
+ return new EscapeClassifier(router);
+ }
+
+ @Override
+ public FlowExporter createFlowExporter(Router router) {
+ return new EscapeFlowExporter(router);
+ }
+
+ @Override
+ public LinkMonitor createLinkMonitor(Router router) {
+ return new EscapeLinkMonitor(router);
+ }
+
+ @Override
+ public RateLimiter createRateLimiter(Router router) {
+ return new EscapeRateLimiter(router);
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EventBroker.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EventBroker.java
new file mode 100644
index 0000000..cc20b12
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/escape/EventBroker.java
@@ -0,0 +1,123 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+package br.ufrgs.inf.bdinetr.domain.escape;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Observable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import br.ufrgs.inf.bdinetr.domain.omnet.event.AnomalousEvent;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.OMNeTEvent;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.OverUsageEvent;
+import br.ufrgs.inf.bdinetr.domain.omnet.event.ThreatEvent;
+
+/**
+ * @author Alberto Egon and Ingrid Nunes
+ */
+public class EventBroker extends Observable {
+
+ private class BrokerThread extends Thread {
+
+ Socket eventSource = null;
+
+ public BrokerThread(Socket s) {
+ eventSource = s;
+ }
+
+ public void run() {
+ try {
+ // read the event via the socket
+ BufferedReader in = new BufferedReader(new InputStreamReader(
+ eventSource.getInputStream()));
+ String inputLine = in.readLine();
+ log.info("Read event from socket = " + inputLine);
+
+ OMNeTEvent event = null;
+ if (inputLine.startsWith(OverUsageEvent.NAME)) {
+ event = new OverUsageEvent(inputLine);
+ } else if (inputLine.startsWith(AnomalousEvent.NAME)) {
+ event = new AnomalousEvent(inputLine);
+ } else if (inputLine.startsWith(ThreatEvent.NAME)) {
+ event = new ThreatEvent(inputLine);
+ }
+
+ // notify observers
+ if (event != null) {
+ setChanged();
+ notifyObservers(event);
+ }
+
+ // close stuff
+ in.close();
+ eventSource.close();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+
+ private static EventBroker INSTANCE;
+ private static final Log log = LogFactory.getLog(EventBroker.class);
+ private static final int SOCKET_PORT = 4444;
+
+ public synchronized static EventBroker getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new EventBroker();
+ }
+ return INSTANCE;
+ }
+
+ private ServerSocket serverSocket = null;
+
+ public EventBroker() {
+ try {
+ // creates the server socket
+ serverSocket = new ServerSocket(SOCKET_PORT);
+ log.info("EventBroker is ready...");
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+
+ // creates a thread that will keep the socket open and will spawn new
+ // threads for handling each new connection
+ (new Thread() {
+ public void run() {
+ while (true) {
+ try {
+ Socket eventSource = serverSocket.accept();
+ // FIXME events order?
+ new BrokerThread(eventSource).start();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+ }).start();
+ }
+
+}