Details
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/AnomalyDetectionCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/AnomalyDetectionCapability.java
index 87aa18a..87a62ee 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/AnomalyDetectionCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/AnomalyDetectionCapability.java
@@ -21,34 +21,47 @@
//----------------------------------------------------------------------------
package br.ufrgs.inf.bdinetr.agent;
+import java.util.Iterator;
import java.util.Set;
import bdi4jade.annotation.Parameter;
import bdi4jade.annotation.Parameter.Direction;
import bdi4jade.belief.Belief;
-import bdi4jade.belief.PropositionalBelief;
+import bdi4jade.belief.BeliefSet;
+import bdi4jade.belief.Predicate;
+import bdi4jade.belief.TransientBeliefSet;
import bdi4jade.core.Capability;
import bdi4jade.core.GoalUpdateSet;
+import bdi4jade.event.GoalEvent;
+import bdi4jade.event.GoalListener;
+import bdi4jade.goal.BeliefGoal;
+import bdi4jade.goal.BeliefValueGoal;
+import bdi4jade.goal.Goal;
+import bdi4jade.goal.GoalStatus;
import bdi4jade.goal.GoalTemplateFactory;
import bdi4jade.plan.DefaultPlan;
import bdi4jade.plan.Plan;
+import bdi4jade.plan.Plan.EndState;
import bdi4jade.plan.planbody.BeliefGoalPlanBody;
+import bdi4jade.reasoning.BeliefRevisionStrategy;
import bdi4jade.reasoning.OptionGenerationFunction;
+import br.ufrgs.inf.bdinetr.agent.belief.AnomalousUsageBelief;
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.Role;
import br.ufrgs.inf.bdinetr.domain.predicate.Anomalous;
+import br.ufrgs.inf.bdinetr.domain.predicate.AnomalousUsage;
import br.ufrgs.inf.bdinetr.domain.predicate.Benign;
+import br.ufrgs.inf.bdinetr.domain.predicate.IpRateLimited;
import br.ufrgs.inf.bdinetr.domain.predicate.OverUsageCause;
-import br.ufrgs.inf.bdinetr.domain.predicate.RegularUsage;
import br.ufrgs.inf.bdinetr.domain.predicate.Restricted;
/**
* @author Ingrid Nunes
*/
public class AnomalyDetectionCapability extends RouterAgentCapability implements
- OptionGenerationFunction {
+ BeliefRevisionStrategy, OptionGenerationFunction, GoalListener {
public class AnalyseLinkStatistics extends BeliefGoalPlanBody {
private static final long serialVersionUID = -3493377510830902961L;
@@ -58,40 +71,110 @@ public class AnomalyDetectionCapability extends RouterAgentCapability implements
@Override
public void execute() {
Set<Ip> outliers = role.detectIntrusion(link);
- for (Ip outlier : outliers) {
- belief(new Anomalous(outlier), true);
- belief(new Benign(outlier), null);
- belief(new OverUsageCause(outlier, link), true);
+ BeliefSet<OverUsageCause, Ip> overUsageCause = new TransientBeliefSet<OverUsageCause, Ip>(
+ new OverUsageCause(link));
+ if (outliers != null && !outliers.isEmpty()) {
+ for (Ip outlier : outliers) {
+ belief(new Anomalous(outlier), true);
+ belief(new Benign(outlier), null);
+ overUsageCause.addValue(outlier);
+ }
}
+ addBelief(overUsageCause);
+ addBelief(new AnomalousUsageBelief(new AnomalousUsage(link)));
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setBeliefName(AnomalousUsage anomalousUsage) {
+ this.link = anomalousUsage.getConcept();
+ }
+ }
+
+ public class LimitIPRatePlan extends BeliefGoalPlanBody {
+ private static final long serialVersionUID = -3493377510830902961L;
+
+ private Ip ip;
+ private boolean subgoalDispatched;
- // Exists ip.(OverUsageCause(ip, link) AND not(Restricted(ip)) -->
- // not RegularUsage(link)
- // nExists ip.(OverUsageCause(ip, link) AND not(Restricted(ip)) -->
- // RegularUsage(link)
- boolean exists = false;
- Set<Belief<?, ?>> overUsageCauseBeliefs = getBeliefBase()
- .getBeliefsByType(OverUsageCause.class);
- for (Belief<?, ?> belief : overUsageCauseBeliefs) {
- PropositionalBelief<OverUsageCause> overUsageCause = (PropositionalBelief<OverUsageCause>) belief;
- assert overUsageCause.getValue();
-
- if (link.equals(overUsageCause.getName().getSecond())) {
- PropositionalBelief<Restricted> restricted = (PropositionalBelief<Restricted>) getBeliefBase()
- .getBelief(
- new Restricted(overUsageCause.getName()
- .getFirst()));
- if (restricted == null || !restricted.getValue()) {
- exists = true;
- break;
+ @Override
+ public void execute() {
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new BeliefValueGoal<>(
+ new IpRateLimited(ip), true));
+ this.subgoalDispatched = true;
+ } else {
+ GoalEvent event = getGoalEvent();
+ if (event != null) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal())
+ .getOutputBelief());
+ belief(new Restricted(ip), true);
+
+ Set<Belief<?, ?>> overUsageCauseBeliefs = getBeliefBase()
+ .getBeliefsByType(OverUsageCause.class);
+ Iterator<Belief<?, ?>> it = overUsageCauseBeliefs
+ .iterator();
+ while (it.hasNext()) {
+ BeliefSet<OverUsageCause, Ip> overUsageCause = (BeliefSet<OverUsageCause, Ip>) it
+ .next();
+ if (overUsageCause.hasValue(ip)) {
+ // ip in OverUsageCause(l) --> remove
+ overUsageCause.removeValue(ip);
+ }
+ }
+ } else {
+ setEndState(EndState.FAILED);
}
}
}
- belief(new RegularUsage(link), !exists);
+ }
+
+ @Override
+ protected void init() {
+ this.subgoalDispatched = false;
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(RegularUsage regularUsage) {
- this.link = regularUsage.getConcept();
+ public void setBeliefName(Restricted restricted) {
+ this.ip = restricted.getConcept();
+ }
+ }
+
+ public class RestoreIPRatePlan extends BeliefGoalPlanBody {
+ private static final long serialVersionUID = -3493377510830902961L;
+
+ private Ip ip;
+ private boolean subgoalDispatched;
+
+ @Override
+ public void execute() {
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new BeliefValueGoal<>(
+ new IpRateLimited(ip), false));
+ this.subgoalDispatched = true;
+ } else {
+ GoalEvent event = getGoalEvent();
+ if (event != null) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal())
+ .getOutputBelief());
+ belief(new Restricted(ip), false);
+ belief(new Anomalous(ip), null);
+ } else {
+ setEndState(EndState.FAILED);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void init() {
+ this.subgoalDispatched = false;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setBeliefName(Restricted restricted) {
+ this.ip = restricted.getConcept();
}
}
@@ -99,17 +182,49 @@ public class AnomalyDetectionCapability extends RouterAgentCapability implements
@bdi4jade.annotation.Plan
private Plan analyseLinkStatistics;
+ @bdi4jade.annotation.Plan
+ private Plan limitIpRate;
+ @bdi4jade.annotation.Plan
+ private Plan restoreIpRate;
@bdi4jade.annotation.TransientBelief
private final AnomalyDetection role;
- public AnomalyDetectionCapability(AnomalyDetection anomalyDetection) {
+ public AnomalyDetectionCapability(AnomalyDetection anomalyDetection,
+ GoalRequestPlan beliefGoalRequestPlan) {
this.role = anomalyDetection;
+ setBeliefRevisionStrategy(this);
setOptionGenerationFunction(this);
- analyseLinkStatistics = new DefaultPlan(
- GoalTemplateFactory.hasBeliefOfType(RegularUsage.class),
+ beliefGoalRequestPlan.addGoalTemplate(GoalTemplateFactory
+ .hasBeliefOfTypeWithValue(IpRateLimited.class, true), this,
+ Role.RATE_LIMITER, false);
+ beliefGoalRequestPlan.addGoalTemplate(GoalTemplateFactory
+ .hasBeliefOfTypeWithValue(IpRateLimited.class, false), this,
+ Role.RATE_LIMITER, false);
+ beliefGoalRequestPlan.addGoalTemplate(
+ GoalTemplateFactory.hasBeliefOfType(Benign.class), this,
+ Role.CLASSIFIER, true);
+
+ this.analyseLinkStatistics = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfType(AnomalousUsage.class),
AnalyseLinkStatistics.class);
+ this.limitIpRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(Restricted.class,
+ Boolean.TRUE), LimitIPRatePlan.class);
+ this.restoreIpRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(Restricted.class,
+ Boolean.FALSE), RestoreIPRatePlan.class) {
+ @Override
+ public boolean isContextApplicable(Goal goal) {
+ BeliefGoal<Restricted> bg = (BeliefGoal<Restricted>) goal;
+ Predicate<IpRateLimited> ipRateLimited = (Predicate<IpRateLimited>) getBeliefBase()
+ .getBelief(
+ new IpRateLimited(bg.getBeliefName()
+ .getConcept()));
+ return (ipRateLimited != null && ipRateLimited.getValue());
+ }
+ };
}
@Override
@@ -119,16 +234,40 @@ public class AnomalyDetectionCapability extends RouterAgentCapability implements
Set<Belief<?, ?>> anomalousIpBeliefs = getBeliefBase()
.getBeliefsByType(Anomalous.class);
for (Belief<?, ?> belief : anomalousIpBeliefs) {
- PropositionalBelief<Anomalous> anomalous = (PropositionalBelief<Anomalous>) belief;
+ Predicate<Anomalous> anomalous = (Predicate<Anomalous>) belief;
+ Ip ip = anomalous.getName().getConcept();
if (anomalous.getValue()) {
- PropositionalBelief<Restricted> restricted = (PropositionalBelief<Restricted>) getBeliefBase()
+ Predicate<Benign> benign = (Predicate<Benign>) getBeliefBase()
+ .getBelief(new Benign(ip));
+ if (benign == null) {
+ // Anomalous(ip) AND ~Benign(ip) -->
+ // ?Benign(ip)
+ goal(goalUpdateSet, new Benign(ip), this);
+ }
+
+ Predicate<Restricted> restricted = (Predicate<Restricted>) getBeliefBase()
+ .getBelief(new Restricted(ip));
+ if ((benign == null || !benign.getValue())
+ && (restricted == null || !restricted.getValue())) {
+ // Anomalous(l) AND !(not Benign(l)) AND
+ // !(Restricted(l)) --> AttackPrevented(l)
+ goal(goalUpdateSet, new Restricted(ip), true);
+ }
+ }
+ }
+
+ Set<Belief<?, ?>> restrictedBeliefs = getBeliefBase().getBeliefsByType(
+ Restricted.class);
+ for (Belief<?, ?> belief : restrictedBeliefs) {
+ Predicate<Restricted> restricted = (Predicate<Restricted>) belief;
+ if (restricted.getValue()) {
+ Predicate<Benign> benign = (Predicate<Benign>) getBeliefBase()
.getBelief(
- new Restricted(anomalous.getName().getConcept()));
- if (restricted == null || !restricted.getValue()) {
- goalUpdateSet.generateGoal(createGoal(new Restricted(
- anomalous.getName().getConcept()), true));
- goalUpdateSet.generateGoal(createGoal(new Benign(anomalous
- .getName().getConcept())));
+ new Benign(restricted.getName().getConcept()));
+ if (benign != null && benign.getValue()) {
+ // Restricted(l) AND Benign(l) --> not
+ // Restricted(l)
+ goal(goalUpdateSet, restricted.getName(), false);
}
}
}
@@ -140,6 +279,36 @@ public class AnomalyDetectionCapability extends RouterAgentCapability implements
}
@Override
+ public void goalPerformed(GoalEvent event) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal()).getOutputBelief());
+ }
+ }
+
+ @Override
+ public void reviewBeliefs() {
+ Set<Belief<?, ?>> overUsageCauseBeliefs = getBeliefBase()
+ .getBeliefsByType(OverUsageCause.class);
+ Iterator<Belief<?, ?>> it = overUsageCauseBeliefs.iterator();
+ while (it.hasNext()) {
+ BeliefSet<OverUsageCause, Ip> overUsageCause = (BeliefSet<OverUsageCause, Ip>) it
+ .next();
+ if (overUsageCause.getValue().isEmpty()) {
+ removeBelief(overUsageCause);
+ }
+ Predicate<AnomalousUsage> anomalousUsage = (Predicate<AnomalousUsage>) getBeliefBase()
+ .getBelief(
+ new AnomalousUsage(overUsageCause.getName()
+ .getConcept()));
+ if (anomalousUsage != null
+ && (anomalousUsage.getValue() == null || !anomalousUsage
+ .getValue())) {
+ removeBelief(anomalousUsage);
+ }
+ }
+ }
+
+ @Override
public void setCapability(Capability capability) {
if (!this.equals(capability)) {
throw new IllegalArgumentException(
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/AnomalousUsageBelief.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/AnomalousUsageBelief.java
new file mode 100644
index 0000000..7296744
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/AnomalousUsageBelief.java
@@ -0,0 +1,46 @@
+//----------------------------------------------------------------------------
+// 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.agent.belief;
+
+import bdi4jade.belief.BeliefSet;
+import bdi4jade.belief.DerivedPredicate;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+import br.ufrgs.inf.bdinetr.domain.predicate.AnomalousUsage;
+import br.ufrgs.inf.bdinetr.domain.predicate.OverUsageCause;
+
+public class AnomalousUsageBelief extends DerivedPredicate<AnomalousUsage> {
+
+ private static final long serialVersionUID = 6923761036847007160L;
+
+ public AnomalousUsageBelief(AnomalousUsage anomalousUsage) {
+ super(anomalousUsage);
+ }
+
+ @Override
+ protected Boolean evaluate() {
+ BeliefSet<OverUsageCause, Ip> overUsageCauseBeliefs = (BeliefSet<OverUsageCause, Ip>) getMainBeliefBase()
+ .getBelief(new OverUsageCause(getName().getConcept()));
+ return overUsageCauseBeliefs == null ? false : !overUsageCauseBeliefs
+ .getValue().isEmpty();
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/BenignBelief.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/BenignBelief.java
new file mode 100644
index 0000000..9bce2e6
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/belief/BenignBelief.java
@@ -0,0 +1,57 @@
+//----------------------------------------------------------------------------
+// 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.agent.belief;
+
+import java.util.Set;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.DerivedPredicate;
+import bdi4jade.belief.Predicate;
+import br.ufrgs.inf.bdinetr.domain.predicate.Benign;
+import br.ufrgs.inf.bdinetr.domain.predicate.Threat;
+
+public class BenignBelief extends DerivedPredicate<Benign> {
+
+ private static final long serialVersionUID = 6923761036847007160L;
+
+ public BenignBelief(Benign benign) {
+ super(benign);
+ }
+
+ @Override
+ protected Boolean evaluate() {
+ boolean exists = false;
+ Set<Belief<?, ?>> threatBeliefs = getMainBeliefBase().getBeliefsByType(
+ Threat.class);
+ for (Belief<?, ?> belief : threatBeliefs) {
+ Predicate<Threat> threat = (Predicate<Threat>) belief;
+ assert threat.getValue();
+ if (getName().getConcept().equals(
+ threat.getName().getConcept().getDstIp())) {
+ exists = true;
+ break;
+ }
+ }
+ return !exists;
+ }
+
+}
\ No newline at end of file
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/ClassifierCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/ClassifierCapability.java
index 328f859..01db029 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/ClassifierCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/ClassifierCapability.java
@@ -21,78 +21,64 @@
//----------------------------------------------------------------------------
package br.ufrgs.inf.bdinetr.agent;
+import java.util.Iterator;
import java.util.Set;
import bdi4jade.annotation.Parameter;
import bdi4jade.annotation.Parameter.Direction;
import bdi4jade.belief.Belief;
-import bdi4jade.belief.PropositionalBelief;
+import bdi4jade.belief.Predicate;
import bdi4jade.core.Capability;
import bdi4jade.core.GoalUpdateSet;
import bdi4jade.event.GoalEvent;
-import bdi4jade.goal.BeliefPresentGoal;
+import bdi4jade.goal.BeliefGoal;
+import bdi4jade.goal.BeliefNotPresentGoal;
+import bdi4jade.goal.BeliefValueGoal;
+import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalStatus;
import bdi4jade.goal.GoalTemplateFactory;
import bdi4jade.plan.DefaultPlan;
import bdi4jade.plan.Plan;
import bdi4jade.plan.Plan.EndState;
import bdi4jade.plan.planbody.BeliefGoalPlanBody;
+import bdi4jade.reasoning.BeliefRevisionStrategy;
import bdi4jade.reasoning.OptionGenerationFunction;
-import br.ufrgs.inf.bdinetr.agent.RouterAgent.RootCapability.ExportFlows;
+import br.ufrgs.inf.bdinetr.agent.belief.BenignBelief;
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.Role;
-import br.ufrgs.inf.bdinetr.domain.predicate.Anomalous;
import br.ufrgs.inf.bdinetr.domain.predicate.Benign;
+import br.ufrgs.inf.bdinetr.domain.predicate.FlowExport;
+import br.ufrgs.inf.bdinetr.domain.predicate.FlowRateLimited;
import br.ufrgs.inf.bdinetr.domain.predicate.Threat;
-import br.ufrgs.inf.bdinetr.domain.predicate.ThreatResponded;
/**
* @author Ingrid Nunes
*/
public class ClassifierCapability extends RouterAgentCapability implements
- OptionGenerationFunction {
+ BeliefRevisionStrategy, OptionGenerationFunction {
public class AnalyseIPFlows extends BeliefGoalPlanBody {
private static final long serialVersionUID = -3493377510830902961L;
private Ip ip;
- private boolean flowsExported;
+ private boolean subgoalDispatched;
@Override
public void execute() {
- if (!flowsExported) {
- dispatchSubgoalAndListen(new ExportFlows(ip));
- this.flowsExported = true;
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new FlowExport(ip));
+ this.subgoalDispatched = true;
} else {
GoalEvent event = getGoalEvent();
if (event != null) {
if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
Set<Flow> malicious = role.classifyFlows(ip);
-
for (Flow flow : malicious) {
belief(new Threat(flow), true);
}
-
- // Exists flow.(threat(flow) AND ip = dst(flow)) --> not
- // Benign(ip)
- // nExists flow.(threat(flow) AND ip = dst(flow)) -->
- // Benign(ip)
- boolean exists = false;
- Set<Belief<?, ?>> threatBeliefs = getBeliefBase()
- .getBeliefsByType(Threat.class);
- for (Belief<?, ?> belief : threatBeliefs) {
- PropositionalBelief<Threat> threat = (PropositionalBelief<Threat>) belief;
- assert threat.getValue();
-
- if (ip.equals(threat.getName().getConcept()
- .getDstIp())) {
- exists = true;
- break;
- }
- }
- belief(new Benign(ip), !exists);
+ addBelief(new BenignBelief(new Benign(ip)));
} else {
setEndState(EndState.FAILED);
}
@@ -103,9 +89,8 @@ public class ClassifierCapability extends RouterAgentCapability implements
}
@Override
- public void onStart() {
- super.onStart();
- this.flowsExported = false;
+ public void init() {
+ this.subgoalDispatched = false;
}
@Parameter(direction = Direction.IN)
@@ -114,41 +99,90 @@ public class ClassifierCapability extends RouterAgentCapability implements
}
}
+ public class LimitFlowRatePlan extends BeliefGoalPlanBody {
+ private static final long serialVersionUID = -3493377510830902961L;
+
+ private Flow flow;
+ private boolean subgoalDispatched;
+
+ @Override
+ public void execute() {
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new BeliefValueGoal<>(
+ new FlowRateLimited(flow), true));
+ this.subgoalDispatched = true;
+ } else {
+ GoalEvent event = getGoalEvent();
+ if (event != null) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal())
+ .getOutputBelief());
+ belief(new Threat(flow), null);
+ } else {
+ setEndState(EndState.FAILED);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void init() {
+ this.subgoalDispatched = false;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setBeliefName(Threat threat) {
+ this.flow = threat.getConcept();
+ }
+ }
+
private static final long serialVersionUID = -1705728861020677126L;
@bdi4jade.annotation.Plan
private Plan analyseIpFlows;
+ @bdi4jade.annotation.Plan
+ private Plan limitFlowRate;
@bdi4jade.annotation.TransientBelief
private final Classifier role;
- public ClassifierCapability(Classifier classifier) {
+ public ClassifierCapability(Classifier classifier,
+ GoalRequestPlan beliefGoalRequestPlan) {
this.role = classifier;
+ setBeliefRevisionStrategy(this);
setOptionGenerationFunction(this);
+ beliefGoalRequestPlan.addGoalTemplate(GoalTemplateFactory
+ .hasBeliefOfTypeWithValue(FlowRateLimited.class, true), this,
+ Role.RATE_LIMITER, false);
+ beliefGoalRequestPlan.addGoalTemplate(
+ GoalTemplateFactory.goalOfType(FlowExport.class), this,
+ Role.FLOW_EXPORTER, false);
+
analyseIpFlows = new DefaultPlan(
GoalTemplateFactory.hasBeliefOfType(Benign.class),
- AnalyseIPFlows.class) {
- public boolean isContextApplicable(bdi4jade.goal.Goal goal) {
- BeliefPresentGoal<Benign> bg = (BeliefPresentGoal<Benign>) goal;
- PropositionalBelief<Anomalous> anomalous = (PropositionalBelief<Anomalous>) getBeliefBase()
- .getBelief(
- new Anomalous(bg.getBeliefName().getConcept()));
- return (anomalous != null && anomalous.getValue());
+ AnalyseIPFlows.class);
+ limitFlowRate = new DefaultPlan(
+ GoalTemplateFactory.hasNoBeliefOfType(Threat.class),
+ LimitFlowRatePlan.class) {
+ public boolean isContextApplicable(Goal goal) {
+ BeliefNotPresentGoal<Threat> bg = (BeliefNotPresentGoal<Threat>) goal;
+ Predicate<Threat> threat = (Predicate<Threat>) getBeliefBase()
+ .getBelief(bg.getBeliefName());
+ return (threat != null && threat.getValue());
};
};
}
@Override
public void generateGoals(GoalUpdateSet goalUpdateSet) {
- // Threat(flow) --> goal(ThreatResponded(flow))
+ // Threat(flow) --> ~Threat(flow)
Set<Belief<?, ?>> threatBeliefs = getBeliefBase().getBeliefsByType(
Threat.class);
for (Belief<?, ?> belief : threatBeliefs) {
- PropositionalBelief<Threat> threat = (PropositionalBelief<Threat>) belief;
+ Predicate<Threat> threat = (Predicate<Threat>) belief;
if (threat.getValue()) {
- goalUpdateSet.generateGoal(createGoal(new ThreatResponded(
- threat.getName().getConcept()), true));
+ goal(goalUpdateSet, threat.getName(), (Boolean) null);
}
}
}
@@ -159,6 +193,19 @@ public class ClassifierCapability extends RouterAgentCapability implements
}
@Override
+ public void reviewBeliefs() {
+ Set<Belief<?, ?>> benignBeliefs = getBeliefBase().getBeliefsByType(
+ Benign.class);
+ Iterator<Belief<?, ?>> it = benignBeliefs.iterator();
+ while (it.hasNext()) {
+ Predicate<Benign> benignBelief = (Predicate<Benign>) it.next();
+ if (benignBelief.getValue() == null || benignBelief.getValue()) {
+ removeBelief(benignBelief);
+ }
+ }
+ }
+
+ @Override
public void setCapability(Capability capability) {
if (!this.equals(capability)) {
throw new IllegalArgumentException(
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/FlowExporterCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/FlowExporterCapability.java
index 8407de6..4d7f903 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/FlowExporterCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/FlowExporterCapability.java
@@ -1,17 +1,40 @@
+//----------------------------------------------------------------------------
+// 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.agent;
import bdi4jade.annotation.Parameter;
import bdi4jade.annotation.Parameter.Direction;
-import bdi4jade.goal.GoalTemplateFactory;
import bdi4jade.plan.DefaultPlan;
import bdi4jade.plan.Plan;
import bdi4jade.plan.Plan.EndState;
import bdi4jade.plan.planbody.AbstractPlanBody;
-import br.ufrgs.inf.bdinetr.agent.RouterAgent.RootCapability.ExportFlows;
import br.ufrgs.inf.bdinetr.domain.FlowExporter;
import br.ufrgs.inf.bdinetr.domain.Ip;
import br.ufrgs.inf.bdinetr.domain.Role;
+import br.ufrgs.inf.bdinetr.domain.predicate.FlowExport;
+/**
+ * @author Ingrid Nunes
+ */
public class FlowExporterCapability extends RouterAgentCapability {
public class ExportFlowsPlanBody extends AbstractPlanBody {
@@ -21,7 +44,7 @@ public class FlowExporterCapability extends RouterAgentCapability {
@Override
public void action() {
- role.turnFlowExporterOn();
+ role.turnFlowExporterOn(ip);
setEndState(EndState.SUCCESSFUL);
}
@@ -41,8 +64,7 @@ public class FlowExporterCapability extends RouterAgentCapability {
public FlowExporterCapability(FlowExporter flowExporter) {
this.role = flowExporter;
- exportFlows = new DefaultPlan(
- GoalTemplateFactory.goalOfType(ExportFlows.class),
+ this.exportFlows = new DefaultPlan(FlowExport.class,
ExportFlowsPlanBody.class);
}
@@ -50,4 +72,5 @@ public class FlowExporterCapability extends RouterAgentCapability {
public Role getRole() {
return Role.FLOW_EXPORTER;
}
+
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalRequestPlan.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalRequestPlan.java
new file mode 100644
index 0000000..0880cb8
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalRequestPlan.java
@@ -0,0 +1,354 @@
+//----------------------------------------------------------------------------
+// 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.agent;
+
+import jade.core.AID;
+import jade.core.Agent;
+import jade.core.behaviours.DataStore;
+import jade.domain.DFService;
+import jade.domain.FIPAException;
+import jade.domain.FIPANames.ContentLanguage;
+import jade.domain.FIPAAgentManagement.DFAgentDescription;
+import jade.domain.FIPAAgentManagement.ServiceDescription;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+import jade.proto.states.MsgReceiver;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Predicate;
+import bdi4jade.core.BDIAgent;
+import bdi4jade.core.Capability;
+import bdi4jade.goal.BeliefGoal;
+import bdi4jade.goal.BeliefPresentGoal;
+import bdi4jade.goal.BeliefValueGoal;
+import bdi4jade.goal.Goal;
+import bdi4jade.goal.GoalTemplate;
+import bdi4jade.plan.DefaultPlan;
+import bdi4jade.plan.planbody.AbstractPlanBody;
+import br.ufrgs.inf.bdinetr.domain.Role;
+import br.ufrgs.inf.bdinetr.domain.message.GoalProposal;
+import br.ufrgs.inf.bdinetr.domain.message.GoalRequest;
+import br.ufrgs.inf.bdinetr.domain.message.GoalResponse;
+import br.ufrgs.inf.bdinetr.domain.ontology.BDINetROntology;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class GoalRequestPlan extends DefaultPlan {
+
+ public class PlanBody extends AbstractPlanBody {
+ private static final long serialVersionUID = -1833810388789537049L;
+
+ private int answers;
+ private MessageTemplate mt;
+ private Set<ACLMessage> positiveAnswers;
+ private RequestDescription requestDescription;
+ private int requests;
+ private long requestTime;
+ private State state;
+
+ private void achieveGoal() throws Exception {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (ACLMessage.INFORM == reply.getPerformative()) {
+ log.info("Goal " + getGoal() + " achieved.");
+ if (getGoal() instanceof BeliefGoal) {
+ GoalResponse<?> response = (GoalResponse<?>) myAgent
+ .getContentManager().extractContent(reply);
+
+ Predicate<?> predicate = requestDescription.capability
+ .belief(response.getPredicate(),
+ response.getValue());
+
+ BeliefGoal goal = (BeliefGoal<?>) getGoal();
+ goal.setOutputBelief(predicate);
+ assert goal.isAchieved(requestDescription.capability
+ .getBeliefBase());
+
+ if (requestDescription.subscribe) {
+ myAgent.addBehaviour(new ReceiveUpdatesBehavior(
+ myAgent, mt, requestDescription.capability,
+ predicate));
+ }
+ }
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ setEndState(EndState.FAILED);
+ }
+ this.state = State.Ended;
+ } else {
+ block();
+ }
+ }
+
+ @Override
+ public void action() {
+ try {
+ switch (state) {
+ case Resquesting:
+ request();
+ break;
+ case ReceivingResponses:
+ receiveResponse();
+ break;
+ case Selecting:
+ selectProposal();
+ break;
+ case AchievingGoal:
+ achieveGoal();
+ break;
+ case Ended:
+ break;
+ }
+ } catch (Exception exc) {
+ log.error(exc);
+ exc.printStackTrace();
+ setEndState(EndState.FAILED);
+ }
+ }
+
+ private DFAgentDescription[] getReceivers(Role role) {
+ DFAgentDescription dfd = new DFAgentDescription();
+ ServiceDescription sd = new ServiceDescription();
+ sd.setType(role.name());
+ sd.addLanguages(ContentLanguage.FIPA_SL);
+ sd.addOntologies(BDINetROntology.ONTOLOGY_NAME);
+ dfd.addServices(sd);
+
+ try {
+ return DFService.search(myAgent, dfd);
+ } catch (FIPAException fe) {
+ log.error(myAgent.getLocalName()
+ + " search with DF unsucceeded. Reason: "
+ + fe.getMessage());
+ log.error(fe);
+ fe.printStackTrace();
+ return new DFAgentDescription[0];
+ }
+ }
+
+ @Override
+ public void onStart() {
+ this.state = State.Resquesting;
+ this.requestDescription = getRequestDescription(getGoal());
+ }
+
+ private void receiveResponse() {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ this.answers++;
+ if (ACLMessage.PROPOSE == reply.getPerformative()) {
+ log.info("Agent " + reply.getSender() + " sent a proposal.");
+ positiveAnswers.add(reply);
+ } else {
+ log.info("Agent " + reply.getSender()
+ + " refused the request.");
+ }
+ } else {
+ block(MSG_TIME_OUT);
+ }
+ long timeElapsed = System.currentTimeMillis() - requestTime;
+ if (answers >= requests || timeElapsed >= ANSWER_TIME_OUT) {
+ this.state = State.Selecting;
+ } else {
+ log.info("Waiting for more answers...");
+ }
+ }
+
+ private void request() throws Exception {
+ this.requestTime = System.currentTimeMillis();
+
+ ACLMessage msg = new ACLMessage(ACLMessage.CFP);
+ msg.setLanguage(ContentLanguage.FIPA_SL);
+ msg.setOntology(BDINetROntology.ONTOLOGY_NAME);
+ msg.setConversationId("cin" + requestTime);
+ msg.setReplyWith("cfp" + requestTime);
+
+ Set<AID> receivers = new HashSet<>();
+ for (DFAgentDescription agentDesc : getReceivers(requestDescription.role)) {
+ if (receivers.add(agentDesc.getName())) {
+ msg.addReceiver(agentDesc.getName());
+ }
+ }
+ log.info(receivers);
+
+ GoalRequest request = new GoalRequest();
+ if (getGoal() instanceof BeliefPresentGoal) {
+ BeliefPresentGoal<?> bg = (BeliefPresentGoal<?>) getGoal();
+ request.setPredicate(bg.getBeliefName());
+ } else if (getGoal() instanceof BeliefValueGoal) {
+ BeliefValueGoal<?, Boolean> bg = (BeliefValueGoal<?, Boolean>) getGoal();
+ request.setPredicate(bg.getBeliefName());
+ request.setValue(bg.getValue());
+ } else {
+ request.setPredicate(getGoal());
+ request.setBeliefGoal(false);
+ }
+ request.setSubscribe(requestDescription.subscribe);
+ myAgent.getContentManager().fillContent(msg, request);
+
+ myAgent.send(msg);
+
+ this.mt = MessageTemplate.and(MessageTemplate
+ .MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.requests = receivers.size();
+ this.answers = 0;
+ this.positiveAnswers = new HashSet<>();
+ this.state = State.ReceivingResponses;
+ }
+
+ private void selectProposal() throws Exception {
+ if (positiveAnswers.isEmpty()) {
+ log.info("No positive answers");
+ setEndState(EndState.FAILED);
+ this.state = State.Ended;
+ return;
+ } else {
+ ACLMessage chosenMsg = null;
+ Double lowestCost = null;
+ for (ACLMessage answer : positiveAnswers) {
+ GoalProposal proposal = (GoalProposal) myAgent
+ .getContentManager().extractContent(answer);
+ if (lowestCost == null || lowestCost > proposal.getCost()) {
+ chosenMsg = answer;
+ lowestCost = proposal.getCost();
+ }
+ }
+
+ for (ACLMessage answer : positiveAnswers) {
+ ACLMessage reply = answer.createReply();
+ if (answer == chosenMsg) {
+ reply.setPerformative(ACLMessage.ACCEPT_PROPOSAL);
+ reply.setReplyWith("atp" + System.currentTimeMillis());
+ this.mt = MessageTemplate.and(
+ MessageTemplate.MatchConversationId(reply
+ .getConversationId()), MessageTemplate
+ .MatchInReplyTo(reply.getReplyWith()));
+ log.info("Accepted proposal of agent: "
+ + answer.getSender());
+ } else {
+ reply.setPerformative(ACLMessage.REJECT_PROPOSAL);
+ log.info("Rejected proposal of agent: "
+ + answer.getSender());
+ }
+ this.myAgent.send(reply);
+ }
+ this.state = State.AchievingGoal;
+ }
+ }
+
+ }
+
+ public class ReceiveUpdatesBehavior extends MsgReceiver {
+
+ private static final long serialVersionUID = 1328980796345824527L;
+
+ private Capability capability;
+ private Predicate<?> predicate;
+
+ public ReceiveUpdatesBehavior(Agent agent, MessageTemplate mt,
+ Capability capability, Predicate<?> predicate) {
+ super(agent, mt, INFINITE, new DataStore(),
+ ReceiveUpdatesBehavior.class.getSimpleName());
+ this.capability = capability;
+ this.predicate = predicate;
+ }
+
+ @Override
+ protected void handleMessage(ACLMessage msg) {
+ try {
+ if (ACLMessage.INFORM == msg.getPerformative()) {
+ GoalResponse<?> response = (GoalResponse<?>) myAgent
+ .getContentManager().extractContent(msg);
+ assert capability.getBeliefBase().getBelief(
+ response.getPredicate()) == predicate;
+ if (response.getValue() != null) {
+ log.info(predicate);
+ predicate.setValue(response.getValue());
+ ((BDIAgent) myAgent).restart();
+ } else {
+ log.info("Predicate removed: " + predicate);
+ // capability.getBeliefBase().removeBelief(predicate.getName());
+ myAgent.removeBehaviour(this);
+ }
+ }
+ } catch (Exception exc) {
+ log.error(exc);
+ exc.printStackTrace();
+ myAgent.removeBehaviour(this);
+ }
+ }
+
+ }
+
+ class RequestDescription {
+ RouterAgentCapability capability;
+ Role role;
+ boolean subscribe;
+
+ public RequestDescription(RouterAgentCapability capability, Role role,
+ boolean subscribe) {
+ this.capability = capability;
+ this.role = role;
+ this.subscribe = subscribe;
+ }
+ }
+
+ private enum State {
+ AchievingGoal, Ended, ReceivingResponses, Resquesting, Selecting;
+ }
+
+ public static final int ANSWER_TIME_OUT = 30000;
+ private static final Log log = LogFactory.getLog(GoalRequestPlan.class);
+ public static final int MSG_TIME_OUT = 10000;
+ private Map<GoalTemplate, RequestDescription> requestDescriptions;
+
+ public GoalRequestPlan() {
+ super(PlanBody.class);
+ this.requestDescriptions = new HashMap<>();
+ }
+
+ public void addGoalTemplate(GoalTemplate goalTemplate,
+ RouterAgentCapability capability, Role role, boolean subscribe) {
+ super.addGoalTemplate(goalTemplate);
+ this.requestDescriptions.put(goalTemplate, new RequestDescription(
+ capability, role, subscribe));
+ }
+
+ private RequestDescription getRequestDescription(Goal goal) {
+ for (GoalTemplate goalTemplate : requestDescriptions.keySet()) {
+ if (goalTemplate.match(goal)) {
+ return requestDescriptions.get(goalTemplate);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalResponsePlan.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalResponsePlan.java
new file mode 100644
index 0000000..3375fc4
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/GoalResponsePlan.java
@@ -0,0 +1,277 @@
+//----------------------------------------------------------------------------
+// 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.agent;
+
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+import jade.lang.acl.MessageTemplate.MatchExpression;
+
+import java.util.Date;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.annotation.Parameter;
+import bdi4jade.annotation.Parameter.Direction;
+import bdi4jade.belief.Predicate;
+import bdi4jade.core.Capability;
+import bdi4jade.event.BeliefEvent;
+import bdi4jade.event.BeliefEvent.Action;
+import bdi4jade.event.BeliefListener;
+import bdi4jade.event.GoalEvent;
+import bdi4jade.goal.BeliefGoal;
+import bdi4jade.goal.BeliefPresentGoal;
+import bdi4jade.goal.BeliefValueGoal;
+import bdi4jade.goal.Goal;
+import bdi4jade.goal.GoalStatus;
+import bdi4jade.plan.DefaultPlan;
+import bdi4jade.plan.planbody.AbstractPlanBody;
+import br.ufrgs.inf.bdinetr.domain.message.GoalProposal;
+import br.ufrgs.inf.bdinetr.domain.message.GoalRequest;
+import br.ufrgs.inf.bdinetr.domain.message.GoalResponse;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class GoalResponsePlan extends DefaultPlan {
+
+ public class PlanBody extends AbstractPlanBody implements BeliefListener {
+
+ private static final long serialVersionUID = -4231465068344668721L;
+
+ private ACLMessage acceptProposalMsg;
+ private ACLMessage beliefGoalMsg;
+ private Goal goal;
+ private Boolean lastValue;
+ private MessageTemplate mt;
+ private Capability partCapability;
+ private Predicate<?> predicate;
+ private GoalRequest<?> request;
+ private State state;
+
+ private void achieveBeliefGoal() throws Exception {
+ GoalEvent event = getGoalEvent();
+ if (event == null)
+ return;
+
+ log.info(goal + " finished: " + event.getStatus());
+ ACLMessage reply = acceptProposalMsg.createReply();
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ reply.setPerformative(ACLMessage.INFORM);
+ if (goal instanceof BeliefGoal) {
+ predicate = (Predicate<?>) partCapability.getBeliefBase()
+ .getBelief(((BeliefGoal<?>) goal).getBeliefName());
+ GoalResponse response = new GoalResponse();
+ response.setPredicate(predicate.getName());
+ response.setValue(predicate.getValue());
+ response.setTimestamp(new Date());
+ myAgent.getContentManager().fillContent(reply, response);
+ }
+
+ if (request.getSubscribe()) {
+ partCapability.getBeliefBase().addBeliefListener(this);
+ this.lastValue = predicate.getValue();
+ this.state = State.SendingUpdates;
+ } else {
+ setEndState(EndState.SUCCESSFUL);
+ this.state = State.Ended;
+ }
+ } else {
+ reply.setPerformative(ACLMessage.FAILURE);
+ setEndState(EndState.SUCCESSFUL);
+ this.state = State.Ended;
+ }
+ this.myAgent.send(reply);
+ }
+
+ @Override
+ public void action() {
+ try {
+ switch (state) {
+ case SendingResponse:
+ sendResponse();
+ break;
+ case ReceivingReply:
+ receiveReply();
+ break;
+ case AchievingBeliefGoal:
+ achieveBeliefGoal();
+ break;
+ case SendingUpdates:
+ block();
+ break;
+ case Ended:
+ break;
+ }
+ } catch (Exception exc) {
+ log.error(exc);
+ exc.printStackTrace();
+ setEndState(EndState.FAILED);
+ }
+ }
+
+ @Override
+ public void eventOccurred(BeliefEvent beliefEvent) {
+ if (predicate == beliefEvent.getBelief()) {
+ if (beliefEvent.getAction().equals(Action.BELIEF_REMOVED)) {
+ try {
+ ACLMessage reply = acceptProposalMsg.createReply();
+ reply.setPerformative(ACLMessage.INFORM);
+ GoalResponse response = new GoalResponse();
+ response.setPredicate(predicate.getName());
+ response.setValue(null);
+ response.setTimestamp(new Date());
+ myAgent.getContentManager()
+ .fillContent(reply, response);
+ this.myAgent.send(reply);
+ } catch (Exception exc) {
+ log.error(exc);
+ exc.printStackTrace();
+ }
+
+ partCapability.getBeliefBase().removeBeliefListener(this);
+ this.restart();
+ this.state = State.Ended;
+ setEndState(EndState.SUCCESSFUL);
+ }
+ } else {
+ Boolean currentValue = predicate.getValue();
+ if (currentValue != lastValue) {
+ try {
+ ACLMessage reply = acceptProposalMsg.createReply();
+ reply.setPerformative(ACLMessage.INFORM);
+ GoalResponse response = new GoalResponse();
+ response.setPredicate(predicate.getName());
+ response.setValue(currentValue);
+ response.setTimestamp(new Date());
+ myAgent.getContentManager()
+ .fillContent(reply, response);
+ this.myAgent.send(reply);
+ } catch (Exception exc) {
+ log.error(exc);
+ exc.printStackTrace();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onStart() {
+ this.state = State.SendingResponse;
+ }
+
+ private void receiveReply() {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (ACLMessage.ACCEPT_PROPOSAL == reply.getPerformative()) {
+ dispatchSubgoalAndListen(goal);
+ this.acceptProposalMsg = reply;
+ this.state = State.AchievingBeliefGoal;
+ } else {
+ setEndState(EndState.SUCCESSFUL);
+ log.info("Proposal rejected");
+ this.state = State.Ended;
+ return;
+ }
+ } else {
+ block();
+ }
+ }
+
+ private void sendResponse() throws Exception {
+ log.info(beliefGoalMsg);
+ this.request = (GoalRequest<?>) myAgent.getContentManager()
+ .extractContent(beliefGoalMsg);
+ if (request.getBeliefGoal()) {
+ if (request.getValue() == null) {
+ this.goal = new BeliefPresentGoal(request.getPredicate());
+ } else {
+ this.goal = new BeliefValueGoal(request.getPredicate(),
+ request.getValue());
+ }
+ } else {
+ this.goal = (Goal) request.getPredicate();
+ }
+
+ Boolean canAchieve = false;
+ for (Capability part : getCapability().getPartCapabilities()) {
+ if (part.canAchieve(goal)) {
+ partCapability = part;
+ canAchieve = true;
+ break;
+ }
+ }
+
+ ACLMessage reply = beliefGoalMsg.createReply();
+ reply.setPerformative(canAchieve ? ACLMessage.PROPOSE
+ : ACLMessage.REFUSE);
+ reply.setReplyWith("per" + System.currentTimeMillis());
+
+ // TODO set proposal cost
+ Random r = new Random(System.currentTimeMillis());
+ GoalProposal proposal = new GoalProposal(r.nextDouble());
+ myAgent.getContentManager().fillContent(reply, proposal);
+
+ myAgent.send(reply);
+
+ log.info("Agent " + myAgent + " can achieve " + goal + ": "
+ + canAchieve);
+
+ this.mt = MessageTemplate.and(MessageTemplate
+ .MatchConversationId(reply.getConversationId()),
+ MessageTemplate.MatchInReplyTo(reply.getReplyWith()));
+ this.state = State.ReceivingReply;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setMessage(ACLMessage beliefGoalMsg) {
+ this.beliefGoalMsg = beliefGoalMsg;
+ }
+
+ }
+
+ private enum State {
+ AchievingBeliefGoal, Ended, ReceivingReply, SendingResponse, SendingUpdates;
+ }
+
+ private static final Log log = LogFactory.getLog(GoalResponsePlan.class);
+
+ public GoalResponsePlan() {
+ super(new MessageTemplate(new MatchExpression() {
+ private static final long serialVersionUID = -3581014512390059387L;
+
+ @Override
+ public boolean match(ACLMessage msg) {
+ try {
+ return (ACLMessage.CFP == msg.getPerformative() && msg
+ .getContent().indexOf(
+ GoalRequest.class.getSimpleName()) > 0);
+ } catch (Exception exc) {
+ log.error(exc);
+ return false;
+ }
+ }
+ }), PlanBody.class);
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/LinkMonitorCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/LinkMonitorCapability.java
index e7d0c4d..66b159c 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/LinkMonitorCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/LinkMonitorCapability.java
@@ -24,68 +24,207 @@ package br.ufrgs.inf.bdinetr.agent;
import java.util.HashSet;
import java.util.Set;
+import bdi4jade.annotation.Parameter;
+import bdi4jade.annotation.Parameter.Direction;
import bdi4jade.belief.Belief;
-import bdi4jade.belief.PropositionalBelief;
-import bdi4jade.belief.TransientBelief;
+import bdi4jade.belief.Predicate;
import bdi4jade.core.Capability;
import bdi4jade.core.GoalUpdateSet;
+import bdi4jade.event.GoalEvent;
+import bdi4jade.event.GoalListener;
+import bdi4jade.goal.BeliefGoal;
+import bdi4jade.goal.BeliefValueGoal;
+import bdi4jade.goal.Goal;
+import bdi4jade.goal.GoalStatus;
+import bdi4jade.goal.GoalTemplateFactory;
+import bdi4jade.plan.DefaultPlan;
+import bdi4jade.plan.Plan;
+import bdi4jade.plan.Plan.EndState;
+import bdi4jade.plan.planbody.BeliefGoalPlanBody;
import bdi4jade.reasoning.BeliefRevisionStrategy;
import bdi4jade.reasoning.OptionGenerationFunction;
import br.ufrgs.inf.bdinetr.domain.Link;
import br.ufrgs.inf.bdinetr.domain.LinkMonitor;
import br.ufrgs.inf.bdinetr.domain.Observer;
import br.ufrgs.inf.bdinetr.domain.Role;
+import br.ufrgs.inf.bdinetr.domain.predicate.AnomalousUsage;
import br.ufrgs.inf.bdinetr.domain.predicate.AttackPrevented;
+import br.ufrgs.inf.bdinetr.domain.predicate.LinkRateLimited;
import br.ufrgs.inf.bdinetr.domain.predicate.OverUsage;
-import br.ufrgs.inf.bdinetr.domain.predicate.RegularUsage;
/**
* @author Ingrid Nunes
*/
public class LinkMonitorCapability extends RouterAgentCapability implements
- BeliefRevisionStrategy, OptionGenerationFunction, Observer {
+ BeliefRevisionStrategy, OptionGenerationFunction, GoalListener,
+ Observer {
- public static final double OVER_USAGE_THRESHOLD = 0.8;
+ public class LimitLinkRate extends BeliefGoalPlanBody {
+ private static final long serialVersionUID = -3493377510830902961L;
+
+ private Link link;
+ private boolean subgoalDispatched;
+
+ @Override
+ public void execute() {
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new BeliefValueGoal<>(
+ new LinkRateLimited(link), true));
+ this.subgoalDispatched = true;
+ } else {
+ GoalEvent event = getGoalEvent();
+ if (event != null) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal())
+ .getOutputBelief());
+ belief(new AttackPrevented(link), true);
+ } else {
+ setEndState(EndState.FAILED);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void init() {
+ this.subgoalDispatched = false;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setBeliefName(AttackPrevented attackPrevented) {
+ this.link = attackPrevented.getConcept();
+ }
+ }
+
+ public class RestoreLinkRate extends BeliefGoalPlanBody {
+ private static final long serialVersionUID = -3493377510830902961L;
+
+ private Link link;
+ private boolean subgoalDispatched;
+
+ @Override
+ public void execute() {
+ if (!subgoalDispatched) {
+ dispatchSubgoalAndListen(new BeliefValueGoal<>(
+ new LinkRateLimited(link), false));
+ this.subgoalDispatched = true;
+ } else {
+ GoalEvent event = getGoalEvent();
+ if (event != null) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal())
+ .getOutputBelief());
+ belief(new AttackPrevented(link), false);
+ } else {
+ setEndState(EndState.FAILED);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void init() {
+ this.subgoalDispatched = false;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setBeliefName(AttackPrevented attackPrevented) {
+ this.link = attackPrevented.getConcept();
+ }
+ }
private static final long serialVersionUID = -1705728861020677126L;
+ @bdi4jade.annotation.Plan
+ private Plan limitLinkRate;
@bdi4jade.annotation.TransientBeliefSet
private final Set<Link> linkEvents;
- @bdi4jade.annotation.Belief
- private Belief<String, Double> overUsageThreshold;
+ @bdi4jade.annotation.Plan
+ private Plan restoreLinkRate;
@bdi4jade.annotation.TransientBelief
private LinkMonitor role;
- public LinkMonitorCapability(LinkMonitor linkMonitor) {
+ public LinkMonitorCapability(LinkMonitor linkMonitor,
+ GoalRequestPlan beliefGoalRequestPlan) {
this.role = linkMonitor;
role.attachObserver(this);
+ this.linkEvents = new HashSet<>();
setBeliefRevisionStrategy(this);
setOptionGenerationFunction(this);
- this.linkEvents = new HashSet<>();
- this.overUsageThreshold = new TransientBelief<>("threshold",
- OVER_USAGE_THRESHOLD);
+ beliefGoalRequestPlan.addGoalTemplate(GoalTemplateFactory
+ .hasBeliefOfTypeWithValue(LinkRateLimited.class, true), this,
+ Role.RATE_LIMITER, false);
+ beliefGoalRequestPlan.addGoalTemplate(GoalTemplateFactory
+ .hasBeliefOfTypeWithValue(LinkRateLimited.class, false), this,
+ Role.RATE_LIMITER, false);
+ beliefGoalRequestPlan.addGoalTemplate(
+ GoalTemplateFactory.hasBeliefOfType(AnomalousUsage.class),
+ this, Role.ANOMALY_DETECTION, true);
+
+ this.limitLinkRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(
+ AttackPrevented.class, Boolean.TRUE),
+ LimitLinkRate.class);
+ this.restoreLinkRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(
+ AttackPrevented.class, Boolean.FALSE),
+ RestoreLinkRate.class) {
+ @Override
+ public boolean isContextApplicable(Goal goal) {
+ BeliefGoal<AttackPrevented> bg = (BeliefGoal<AttackPrevented>) goal;
+ Predicate<LinkRateLimited> linkRateLimited = (Predicate<LinkRateLimited>) getBeliefBase()
+ .getBelief(
+ new LinkRateLimited(bg.getBeliefName()
+ .getConcept()));
+ return (linkRateLimited != null && linkRateLimited.getValue());
+ }
+ };
}
@Override
public void generateGoals(GoalUpdateSet goalUpdateSet) {
- // OverUsage(link) AND not AttackPrevented(link) -->
- // goal(AttackPrevented(link)) AND goal(belief(?RegularUsage(link)))
Set<Belief<?, ?>> overUsageBeliefs = getBeliefBase().getBeliefsByType(
OverUsage.class);
for (Belief<?, ?> belief : overUsageBeliefs) {
- PropositionalBelief<OverUsage> overUsage = (PropositionalBelief<OverUsage>) belief;
+ Predicate<OverUsage> overUsage = (Predicate<OverUsage>) belief;
+ Link link = overUsage.getName().getConcept();
if (overUsage.getValue()) {
- PropositionalBelief<AttackPrevented> attackPrevented = (PropositionalBelief<AttackPrevented>) getBeliefBase()
+ Predicate<AnomalousUsage> anomalousUsage = (Predicate<AnomalousUsage>) getBeliefBase()
+ .getBelief(new AnomalousUsage(link));
+ if (anomalousUsage == null) {
+ // OverUsage(l) AND ~AnomalousUsage(l) -->
+ // ?AnomalousUsage(l)
+ goal(goalUpdateSet, new AnomalousUsage(link), this);
+ }
+
+ Predicate<AttackPrevented> attackPrevented = (Predicate<AttackPrevented>) getBeliefBase()
+ .getBelief(new AttackPrevented(link));
+ if ((anomalousUsage == null || anomalousUsage.getValue())
+ && (attackPrevented == null || !attackPrevented
+ .getValue())) {
+ // OverUsage(l) AND !(not AnomalousUsage(l)) AND
+ // !(AttackPrevented(l)) --> AttackPrevented(l)
+ goal(goalUpdateSet, new AttackPrevented(link), Boolean.TRUE);
+ }
+ }
+ }
+
+ Set<Belief<?, ?>> attackPreventedBeliefs = getBeliefBase()
+ .getBeliefsByType(AttackPrevented.class);
+ for (Belief<?, ?> belief : attackPreventedBeliefs) {
+ Predicate<AttackPrevented> attackPrevented = (Predicate<AttackPrevented>) belief;
+ if (attackPrevented.getValue()) {
+ Predicate<AnomalousUsage> anomalousUsage = (Predicate<AnomalousUsage>) getBeliefBase()
.getBelief(
- new AttackPrevented(overUsage.getName()
+ new AnomalousUsage(attackPrevented.getName()
.getConcept()));
- if (attackPrevented == null || !attackPrevented.getValue()) {
- goalUpdateSet.generateGoal(createGoal(new AttackPrevented(
- overUsage.getName().getConcept()), Boolean.TRUE));
- goalUpdateSet.generateGoal(createGoal(new RegularUsage(
- overUsage.getName().getConcept())));
+ // AttackPrevented(l) AND not AnomalousUsage(l) --> not
+ // AttackPrevented(l)
+ if (anomalousUsage != null && !anomalousUsage.getValue()) {
+ goal(goalUpdateSet, attackPrevented.getName(),
+ Boolean.FALSE);
}
}
}
@@ -97,18 +236,23 @@ public class LinkMonitorCapability extends RouterAgentCapability implements
}
@Override
+ public void goalPerformed(GoalEvent event) {
+ if (GoalStatus.ACHIEVED.equals(event.getStatus())) {
+ addBelief(((BeliefGoal<?>) event.getGoal()).getOutputBelief());
+ }
+ }
+
+ @Override
public void reviewBeliefs() {
synchronized (linkEvents) {
for (Link link : linkEvents) {
OverUsage overUsage = new OverUsage(link);
- boolean isOverUsage = role.isOverUsage(link);
-
- if (isOverUsage) {
- PropositionalBelief<OverUsage> overUsageBelief = (PropositionalBelief<OverUsage>) getBeliefBase()
+ if (role.isOverUsage(link)) {
+ Predicate<OverUsage> overUsageBelief = (Predicate<OverUsage>) getBeliefBase()
.getBelief(overUsage);
if (overUsageBelief == null || !overUsageBelief.getValue()) {
belief(overUsage, true);
- belief(new RegularUsage(link), null);
+ belief(new AnomalousUsage(link), null);
}
} else {
belief(overUsage, null);
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RateLimiterCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RateLimiterCapability.java
index 9e0c6a3..054a4e0 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RateLimiterCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RateLimiterCapability.java
@@ -21,47 +21,28 @@
//----------------------------------------------------------------------------
package br.ufrgs.inf.bdinetr.agent;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
import bdi4jade.annotation.Parameter;
import bdi4jade.annotation.Parameter.Direction;
-import bdi4jade.belief.Belief;
-import bdi4jade.belief.PropositionalBelief;
-import bdi4jade.core.Capability;
-import bdi4jade.core.GoalUpdateSet;
+import bdi4jade.belief.Predicate;
import bdi4jade.goal.BeliefGoal;
import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalTemplateFactory;
import bdi4jade.plan.DefaultPlan;
import bdi4jade.plan.Plan;
import bdi4jade.plan.planbody.BeliefGoalPlanBody;
-import bdi4jade.reasoning.OptionGenerationFunction;
-import br.ufrgs.inf.bdinetr.agent.RouterAgent.RootCapability;
import br.ufrgs.inf.bdinetr.domain.Flow;
import br.ufrgs.inf.bdinetr.domain.Ip;
import br.ufrgs.inf.bdinetr.domain.Link;
import br.ufrgs.inf.bdinetr.domain.RateLimiter;
import br.ufrgs.inf.bdinetr.domain.Role;
-import br.ufrgs.inf.bdinetr.domain.Router;
-import br.ufrgs.inf.bdinetr.domain.predicate.Anomalous;
-import br.ufrgs.inf.bdinetr.domain.predicate.AttackPrevented;
-import br.ufrgs.inf.bdinetr.domain.predicate.Benign;
import br.ufrgs.inf.bdinetr.domain.predicate.FlowRateLimited;
-import br.ufrgs.inf.bdinetr.domain.predicate.FullyOperational;
-import br.ufrgs.inf.bdinetr.domain.predicate.OverUsageCause;
-import br.ufrgs.inf.bdinetr.domain.predicate.RateLimited;
-import br.ufrgs.inf.bdinetr.domain.predicate.RegularUsage;
-import br.ufrgs.inf.bdinetr.domain.predicate.Restricted;
-import br.ufrgs.inf.bdinetr.domain.predicate.Threat;
-import br.ufrgs.inf.bdinetr.domain.predicate.ThreatResponded;
+import br.ufrgs.inf.bdinetr.domain.predicate.IpRateLimited;
+import br.ufrgs.inf.bdinetr.domain.predicate.LinkRateLimited;
/**
* @author Ingrid Nunes
*/
-public class RateLimiterCapability extends RouterAgentCapability implements
- OptionGenerationFunction {
+public class RateLimiterCapability extends RouterAgentCapability {
public class LimitFlowRatePlan extends BeliefGoalPlanBody {
private static final long serialVersionUID = -3493377510830902961L;
@@ -72,86 +53,28 @@ public class RateLimiterCapability extends RouterAgentCapability implements
public void execute() {
role.limitFlow(flow, FLOW_LIMIT_RATE);
belief(new FlowRateLimited(flow), true);
- belief(new ThreatResponded(flow), true);
- belief(new Threat(flow), null);
-
- // nExists flow'.(Threat(flow') AND dst(flow) = dst(flow')) -->
- // Benign(dst(flow))
- boolean exists = false;
- Set<Belief<?, ?>> threatBeliefs = getBeliefBase().getBeliefsByType(
- Threat.class);
- for (Belief<?, ?> belief : threatBeliefs) {
- PropositionalBelief<Threat> threat = (PropositionalBelief<Threat>) belief;
- assert threat.getValue();
- if (flow.getDstIp().equals(
- threat.getName().getConcept().getDstIp())) {
- exists = true;
- break;
- }
- }
- if (!exists) {
- belief(new Benign(flow.getDstIp()), true);
- }
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(ThreatResponded threatResponded) {
- this.flow = threatResponded.getConcept();
+ public void setBeliefName(FlowRateLimited flowRateLimited) {
+ this.flow = flowRateLimited.getConcept();
}
}
public class LimitIPRatePlan extends BeliefGoalPlanBody {
private static final long serialVersionUID = -3493377510830902961L;
- @bdi4jade.annotation.Belief(name = RootCapability.ROUTER_BELIEF)
- private Belief<String, Router> device;
private Ip ip;
@Override
public void execute() {
role.limitIp(ip, IP_LIMIT_RATE);
- belief(new RateLimited(ip), true);
- belief(new Restricted(ip), true);
-
- // OverUsageCause(ip, link) --> ~OverUsageCause(ip, link)
- Set<Belief<?, ?>> overUsageCauseBeliefs = getBeliefBase()
- .getBeliefsByType(OverUsageCause.class);
- Set<OverUsageCause> causedByIp = new HashSet<>();
- Iterator<Belief<?, ?>> it = overUsageCauseBeliefs.iterator();
- while (it.hasNext()) {
- PropositionalBelief<OverUsageCause> overUsageCause = (PropositionalBelief<OverUsageCause>) it
- .next();
- if (ip.equals(overUsageCause.getName().getFirst())) {
- assert overUsageCause.getValue();
- causedByIp.add(overUsageCause.getName());
- it.remove();
- belief(overUsageCause.getName(), null);
- }
- }
-
- // nExists ip'.(was OverUsageCause(ip, link) AND OverUsageCause(ip',
- // link)) --> RegularUsage(link))
- for (OverUsageCause overUsageCause : causedByIp) {
- boolean exists = false;
- for (Belief<?, ?> belief : overUsageCauseBeliefs) {
- PropositionalBelief<OverUsageCause> otherOverUsageCause = (PropositionalBelief<OverUsageCause>) belief;
- if (overUsageCause.getSecond().equals(
- otherOverUsageCause.getName().getSecond())) {
- assert !overUsageCause.getFirst().equals(
- otherOverUsageCause.getName().getFirst());
- exists = true;
- break;
- }
- }
- if (!exists) {
- belief(new RegularUsage(overUsageCause.getSecond()), true);
- }
- }
+ belief(new IpRateLimited(ip), true);
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(Restricted restricted) {
- this.ip = restricted.getConcept();
+ public void setBeliefName(IpRateLimited ipRateLimited) {
+ this.ip = ipRateLimited.getConcept();
}
}
@@ -163,34 +86,29 @@ public class RateLimiterCapability extends RouterAgentCapability implements
@Override
public void execute() {
role.limitLink(link, LINK_LIMIT_RATE);
- belief(new FullyOperational(link), false);
- belief(new AttackPrevented(link), true);
+ belief(new LinkRateLimited(link), true);
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(AttackPrevented attackPrevented) {
- this.link = attackPrevented.getConcept();
+ public void setBeliefName(LinkRateLimited linkRateLimited) {
+ this.link = linkRateLimited.getConcept();
}
}
public class RestoreIPRatePlan extends BeliefGoalPlanBody {
private static final long serialVersionUID = -3493377510830902961L;
- @bdi4jade.annotation.Belief(name = RootCapability.ROUTER_BELIEF)
- private Belief<String, Router> device;
private Ip ip;
@Override
public void execute() {
role.unlimitIp(ip);
- belief(new RateLimited(ip), false);
- belief(new Restricted(ip), false);
- belief(new Anomalous(ip), null);
+ belief(new IpRateLimited(ip), false);
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(Restricted restricted) {
- this.ip = restricted.getConcept();
+ public void setBeliefName(IpRateLimited ipRateLimited) {
+ this.ip = ipRateLimited.getConcept();
}
}
@@ -202,13 +120,12 @@ public class RateLimiterCapability extends RouterAgentCapability implements
@Override
public void execute() {
role.unlimitLink(link);
- belief(new FullyOperational(link), true);
- belief(new AttackPrevented(link), null);
+ belief(new LinkRateLimited(link), false);
}
@Parameter(direction = Direction.IN)
- public void setBeliefName(FullyOperational fullyOperational) {
- this.link = fullyOperational.getConcept();
+ public void setBeliefName(LinkRateLimited linkRateLimited) {
+ this.link = linkRateLimited.getConcept();
}
}
@@ -233,96 +150,40 @@ public class RateLimiterCapability extends RouterAgentCapability implements
public RateLimiterCapability(RateLimiter rateLimiter) {
this.role = rateLimiter;
- setOptionGenerationFunction(this);
-
- limitFlowRate = new DefaultPlan(
- GoalTemplateFactory.hasBeliefOfTypeWithValue(
- ThreatResponded.class, Boolean.TRUE),
- LimitFlowRatePlan.class) {
- public boolean isContextApplicable(Goal goal) {
- BeliefGoal<ThreatResponded> bg = (BeliefGoal<ThreatResponded>) goal;
- PropositionalBelief<Threat> threat = (PropositionalBelief<Threat>) getBeliefBase()
- .getBelief(new Threat(bg.getBeliefName().getConcept()));
- return (threat != null && threat.getValue());
- };
- };
- limitIpRate = new DefaultPlan(
- GoalTemplateFactory.hasBeliefOfTypeWithValue(Restricted.class,
- Boolean.TRUE), LimitIPRatePlan.class) {
- public boolean isContextApplicable(Goal goal) {
- BeliefGoal<Restricted> bg = (BeliefGoal<Restricted>) goal;
- PropositionalBelief<Anomalous> anomalous = (PropositionalBelief<Anomalous>) getBeliefBase()
- .getBelief(
- new Anomalous(bg.getBeliefName().getConcept()));
- return (anomalous != null && anomalous.getValue());
- };
- };
- limitLinkRate = new DefaultPlan(
+ this.limitLinkRate = new DefaultPlan(
GoalTemplateFactory.hasBeliefOfTypeWithValue(
- AttackPrevented.class, Boolean.TRUE),
+ LinkRateLimited.class, Boolean.TRUE),
LimitLinkRatePlan.class);
- restoreIpRate = new DefaultPlan(
- GoalTemplateFactory.hasBeliefOfTypeWithValue(Restricted.class,
- Boolean.FALSE), RestoreIPRatePlan.class) {
+ this.restoreLinkRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(
+ LinkRateLimited.class, Boolean.FALSE),
+ RestoreLinkRate.class) {
public boolean isContextApplicable(Goal goal) {
- BeliefGoal<Restricted> bg = (BeliefGoal<Restricted>) goal;
- PropositionalBelief<Benign> benign = (PropositionalBelief<Benign>) getBeliefBase()
- .getBelief(new Benign(bg.getBeliefName().getConcept()));
- PropositionalBelief<RateLimited> rateLimited = (PropositionalBelief<RateLimited>) getBeliefBase()
- .getBelief(
- new RateLimited(bg.getBeliefName().getConcept()));
- return (benign != null && benign.getValue())
- && (rateLimited != null && rateLimited.getValue());
+ BeliefGoal<LinkRateLimited> bg = (BeliefGoal<LinkRateLimited>) goal;
+ Predicate<LinkRateLimited> rateLimited = (Predicate<LinkRateLimited>) getBeliefBase()
+ .getBelief(bg.getBeliefName());
+ return (rateLimited != null && rateLimited.getValue());
};
};
- restoreLinkRate = new DefaultPlan(
+ this.limitIpRate = new DefaultPlan(
GoalTemplateFactory.hasBeliefOfTypeWithValue(
- FullyOperational.class, Boolean.TRUE),
- RestoreLinkRate.class) {
+ IpRateLimited.class, Boolean.TRUE),
+ LimitIPRatePlan.class);
+ this.restoreIpRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(
+ IpRateLimited.class, Boolean.FALSE),
+ RestoreIPRatePlan.class) {
public boolean isContextApplicable(Goal goal) {
- BeliefGoal<FullyOperational> bg = (BeliefGoal<FullyOperational>) goal;
- PropositionalBelief<RegularUsage> regularUsage = (PropositionalBelief<RegularUsage>) getBeliefBase()
- .getBelief(
- new RegularUsage(bg.getBeliefName()
- .getConcept()));
- return (regularUsage != null && regularUsage.getValue());
+ BeliefGoal<IpRateLimited> bg = (BeliefGoal<IpRateLimited>) goal;
+ Predicate<IpRateLimited> rateLimited = (Predicate<IpRateLimited>) getBeliefBase()
+ .getBelief(bg.getBeliefName());
+ return rateLimited != null && rateLimited.getValue();
};
};
- }
-
- @Override
- public void generateGoals(GoalUpdateSet goalUpdateSet) {
- Set<Belief<?, ?>> fullyOperationalBeliefs = getBeliefBase()
- .getBeliefsByType(FullyOperational.class);
- for (Belief<?, ?> belief : fullyOperationalBeliefs) {
- PropositionalBelief<FullyOperational> fullyOperational = (PropositionalBelief<FullyOperational>) belief;
- if (!fullyOperational.getValue()) {
- PropositionalBelief<RegularUsage> regularUsage = (PropositionalBelief<RegularUsage>) getBeliefBase()
- .getBelief(
- new RegularUsage(fullyOperational.getName()
- .getConcept()));
- if (regularUsage != null && regularUsage.getValue()) {
- goalUpdateSet.generateGoal(createGoal(new FullyOperational(
- fullyOperational.getName().getConcept()), true));
- }
-
- }
- }
-
- Set<Belief<?, ?>> restrictedBeliefs = getBeliefBase().getBeliefsByType(
- Restricted.class);
- for (Belief<?, ?> belief : restrictedBeliefs) {
- PropositionalBelief<Restricted> restricted = (PropositionalBelief<Restricted>) belief;
- if (restricted.getValue()) {
- PropositionalBelief<Benign> benign = (PropositionalBelief<Benign>) getBeliefBase()
- .getBelief(
- new Benign(restricted.getName().getConcept()));
- if (benign != null && benign.getValue()) {
- goalUpdateSet.generateGoal(createGoal(new Restricted(
- restricted.getName().getConcept()), false));
- }
- }
- }
+ this.limitFlowRate = new DefaultPlan(
+ GoalTemplateFactory.hasBeliefOfTypeWithValue(
+ FlowRateLimited.class, Boolean.TRUE),
+ LimitFlowRatePlan.class);
}
@Override
@@ -330,12 +191,4 @@ public class RateLimiterCapability extends RouterAgentCapability implements
return Role.RATE_LIMITER;
}
- @Override
- public void setCapability(Capability capability) {
- if (!this.equals(capability)) {
- throw new IllegalArgumentException(
- "This reasoning strategy is already associated with another capability.");
- }
- }
-
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgent.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgent.java
index e499e57..8849110 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgent.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgent.java
@@ -27,9 +27,6 @@ import jade.domain.FIPAException;
import jade.domain.FIPANames.ContentLanguage;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
-import jade.lang.acl.ACLMessage;
-import jade.lang.acl.MessageTemplate;
-import jade.lang.acl.MessageTemplate.MatchExpression;
import java.util.HashSet;
import java.util.Map;
@@ -38,22 +35,17 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import bdi4jade.annotation.Parameter;
-import bdi4jade.annotation.Parameter.Direction;
import bdi4jade.belief.Belief;
import bdi4jade.belief.TransientBelief;
import bdi4jade.core.BDIAgent;
import bdi4jade.core.Capability;
import bdi4jade.core.SingleCapabilityAgent;
-import bdi4jade.goal.BeliefGoal;
import bdi4jade.goal.Goal;
-import bdi4jade.plan.DefaultPlan;
import bdi4jade.plan.Plan;
import bdi4jade.reasoning.AgentPlanSelectionStrategy;
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.Ip;
import br.ufrgs.inf.bdinetr.domain.LinkMonitor;
import br.ufrgs.inf.bdinetr.domain.RateLimiter;
import br.ufrgs.inf.bdinetr.domain.Role;
@@ -68,51 +60,20 @@ public class RouterAgent extends SingleCapabilityAgent implements
public static class RootCapability extends Capability {
- public static class ExportFlows implements Goal {
-
- private static final long serialVersionUID = -7114413010093171144L;
-
- private Ip ip;
-
- public ExportFlows(Ip ip) {
- this.ip = ip;
- }
-
- @Parameter(direction = Direction.IN)
- public Ip getIp() {
- return ip;
- }
-
- }
-
public static final String ROUTER_BELIEF = "router";
private static final long serialVersionUID = -2156730094556459899L;
@bdi4jade.annotation.Plan
- private final Plan requestBeliefGoalPlan;
+ private final GoalRequestPlan beliefGoalRequestPlan;
@bdi4jade.annotation.Plan
- private final Plan respondBeliefGoalPlan;
+ private final GoalResponsePlan beliefGoalResponsePlan;
@bdi4jade.annotation.Belief
private final Belief<String, Router> router;
public RootCapability(Router router) {
this.router = new TransientBelief<>(ROUTER_BELIEF, router);
- this.requestBeliefGoalPlan = new DefaultPlan(BeliefGoal.class,
- RequestBeliefGoalPlanBody.class);
- this.respondBeliefGoalPlan = new DefaultPlan(new MessageTemplate(
- new MatchExpression() {
- private static final long serialVersionUID = -3581014512390059387L;
-
- @Override
- public boolean match(ACLMessage msg) {
- try {
- return (ACLMessage.CFP == msg.getPerformative());
- } catch (Exception exc) {
- log.error(exc);
- return false;
- }
- }
- }), RespondBeliefGoalPlanBody.class);
+ this.beliefGoalRequestPlan = new GoalRequestPlan();
+ this.beliefGoalResponsePlan = new GoalResponsePlan();
}
}
@@ -123,15 +84,19 @@ public class RouterAgent extends SingleCapabilityAgent implements
public RouterAgent(Router router) {
super(new RootCapability(router));
+ RootCapability root = (RootCapability) getCapability();
+
if (router.hasRole(Role.LINK_MONITOR)) {
this.getCapability().addPartCapability(
new LinkMonitorCapability((LinkMonitor) router
- .getRole(Role.LINK_MONITOR)));
+ .getRole(Role.LINK_MONITOR),
+ root.beliefGoalRequestPlan));
}
if (router.hasRole(Role.ANOMALY_DETECTION)) {
this.getCapability().addPartCapability(
new AnomalyDetectionCapability((AnomalyDetection) router
- .getRole(Role.ANOMALY_DETECTION)));
+ .getRole(Role.ANOMALY_DETECTION),
+ root.beliefGoalRequestPlan));
}
if (router.hasRole(Role.RATE_LIMITER)) {
this.getCapability().addPartCapability(
@@ -141,7 +106,8 @@ public class RouterAgent extends SingleCapabilityAgent implements
if (router.hasRole(Role.CLASSIFIER)) {
this.getCapability().addPartCapability(
new ClassifierCapability((Classifier) router
- .getRole(Role.CLASSIFIER)));
+ .getRole(Role.CLASSIFIER),
+ root.beliefGoalRequestPlan));
}
if (router.hasRole(Role.FLOW_EXPORTER)) {
this.getCapability().addPartCapability(
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgentCapability.java b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgentCapability.java
index cf05092..e3e2d14 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgentCapability.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/agent/RouterAgentCapability.java
@@ -24,11 +24,16 @@ package br.ufrgs.inf.bdinetr.agent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import bdi4jade.belief.TransientPropositionalBelief;
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.Predicate;
+import bdi4jade.belief.TransientPredicate;
import bdi4jade.core.Capability;
+import bdi4jade.core.GoalUpdateSet;
+import bdi4jade.event.GoalListener;
+import bdi4jade.goal.BeliefNotPresentGoal;
import bdi4jade.goal.BeliefPresentGoal;
import bdi4jade.goal.Goal;
-import bdi4jade.goal.PropositionalBeliefValueGoal;
+import bdi4jade.goal.PredicateGoal;
import br.ufrgs.inf.bdinetr.domain.Role;
/**
@@ -41,41 +46,65 @@ public abstract class RouterAgentCapability extends Capability {
protected final Log log = LogFactory.getLog(getClass());
- protected void belief(Object proposition, Boolean value) {
+ protected void addBelief(Belief<?, ?> belief) {
+ getBeliefBase().addOrUpdateBelief(belief);
+ log.debug("belief added or updated: " + belief);
+ }
+
+ protected Predicate<?> belief(Object proposition, Boolean value) {
if (value == null) {
- getWholeCapability().getBeliefBase().removeBelief(proposition);
+ getBeliefBase().removeBelief(proposition);
log.debug("belief(~" + proposition + "))");
+ return null;
} else {
- getWholeCapability().getBeliefBase().addOrUpdateBelief(
- new TransientPropositionalBelief(proposition, value));
+ Predicate<?> predicate = new TransientPredicate(proposition, value);
+ getBeliefBase().addOrUpdateBelief(predicate);
log.debug("belief(" + (value ? "" : "not ") + proposition + ")");
+ return predicate;
}
}
- protected Goal createGoal(Object proposition) {
- Goal goal = new BeliefPresentGoal(proposition);
- if (!getMyAgent().hasGoal(goal)) {
- log.debug("goal(?" + proposition + "))");
- }
- return goal;
+ public abstract Role getRole();
+
+ protected void goal(GoalUpdateSet goalUpdateSet, Object proposition) {
+ goal(goalUpdateSet, proposition, (GoalListener) null);
+ }
+
+ protected void goal(GoalUpdateSet goalUpdateSet, Object proposition,
+ Boolean value) {
+ goal(goalUpdateSet, proposition, value, null);
}
- protected Goal createGoal(Object proposition, Boolean value) {
- Goal goal = new PropositionalBeliefValueGoal(proposition, value);
+ protected void goal(GoalUpdateSet goalUpdateSet, Object proposition,
+ Boolean value, GoalListener listener) {
+ Goal goal;
+ if (value == null) {
+ goal = new BeliefNotPresentGoal(proposition);
+ } else {
+ goal = new PredicateGoal(proposition, value);
+ }
if (!getMyAgent().hasGoal(goal)) {
- log.debug("goal(" + (value ? "" : "not ") + proposition + "))");
+ if (value == null) {
+ log.debug("goal(~" + proposition + "))");
+ } else {
+ log.debug("goal(" + (value ? "" : "not ") + proposition + "))");
+ }
+ goalUpdateSet.generateGoal(goal, this, listener);
}
- return goal;
}
- public abstract Role getRole();
-
- protected void goal(Object proposition) {
- getMyAgent().addGoal(this, createGoal(proposition));
+ protected void goal(GoalUpdateSet goalUpdateSet, Object proposition,
+ GoalListener listener) {
+ Goal goal = new BeliefPresentGoal(proposition);
+ if (!getMyAgent().hasGoal(goal)) {
+ log.debug("goal(?" + proposition + "))");
+ goalUpdateSet.generateGoal(goal, this, listener);
+ }
}
- protected void goal(Object proposition, Boolean value) {
- getMyAgent().addGoal(this, createGoal(proposition, value));
+ protected void removeBelief(Belief<?, ?> belief) {
+ getBeliefBase().removeBelief(belief.getName());
+ log.debug("belief removed: " + belief);
}
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java b/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
index bb5099b..3c40ced 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/BDINetRApp.java
@@ -56,8 +56,8 @@ import org.apache.log4j.PropertyConfigurator;
import br.ufrgs.inf.bdinetr.agent.RouterAgent;
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.Role;
+import br.ufrgs.inf.bdinetr.domain.Router;
/**
* @author Ingrid Nunes
@@ -72,13 +72,11 @@ public class BDINetRApp {
.getResource("log4j.properties"));
Set<Router> routers = new HashSet<>();
- routers.add(new Router(new Ip("RouterLM"), Role.LINK_MONITOR
- .getId()));
- routers.add(new Router(new Ip("RouterRLCA"), Role.RATE_LIMITER
- .getId()
- | Role.FLOW_EXPORTER.getId()
- | Role.CLASSIFIER.getId()
- | Role.ANOMALY_DETECTION.getId()));
+ routers.add(new Router(new Ip("RouterLM"), Role.LINK_MONITOR.getId()));
+ routers.add(new Router(new Ip("RouterRL1"), Role.RATE_LIMITER.getId()));
+ routers.add(new Router(new Ip("RouterRL2"), Role.RATE_LIMITER.getId()));
+ routers.add(new Router(new Ip("RouterADFC"), Role.CLASSIFIER.getId()
+ | Role.FLOW_EXPORTER.getId() | Role.ANOMALY_DETECTION.getId()));
Link affectedLink = new Link("AFFECTED_LINK");
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/FlowExporter.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/FlowExporter.java
index 9bfebea..cf1f140 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/FlowExporter.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/FlowExporter.java
@@ -32,7 +32,7 @@ public class FlowExporter extends RouterComponent {
super(router);
}
- public void turnFlowExporterOn() {
+ public void turnFlowExporterOn(Ip ip) {
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalProposal.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalProposal.java
new file mode 100644
index 0000000..cb00082
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalProposal.java
@@ -0,0 +1,55 @@
+//----------------------------------------------------------------------------
+// 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.message;
+
+import jade.content.Concept;
+import jade.content.ContentElement;
+
+import java.io.Serializable;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class GoalProposal implements Serializable, Concept,
+ ContentElement {
+
+ private static final long serialVersionUID = 8629276766179263660L;
+
+ private Double cost;
+
+ public GoalProposal() {
+ this(0.0);
+ }
+
+ public GoalProposal(Double cost) {
+ this.cost = cost;
+ }
+
+ public Double getCost() {
+ return cost;
+ }
+
+ public void setCost(Double cost) {
+ this.cost = cost;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalRequest.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalRequest.java
new file mode 100644
index 0000000..fdb67dc
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalRequest.java
@@ -0,0 +1,96 @@
+//----------------------------------------------------------------------------
+// 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.message;
+
+import jade.content.Concept;
+import jade.content.ContentElement;
+
+import java.io.Serializable;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class GoalRequest<K> implements Serializable, Concept,
+ ContentElement {
+
+ private static final long serialVersionUID = -1823087321617388067L;
+
+ private Boolean beliefGoal;
+ private K predicate;
+ private Boolean subscribe;
+ private Boolean value;
+
+ public GoalRequest() {
+ this.beliefGoal = true;
+ }
+
+ public GoalRequest(K predicate) {
+ this.predicate = predicate;
+ this.value = null;
+ this.subscribe = false;
+ this.beliefGoal = false;
+ }
+
+ public GoalRequest(K predicate, Boolean value) {
+ this(predicate, value, false);
+ }
+
+ public GoalRequest(K predicate, Boolean value, Boolean subscribe) {
+ this.predicate = predicate;
+ this.value = value;
+ this.subscribe = subscribe;
+ this.beliefGoal = true;
+ }
+
+ public Boolean getBeliefGoal() {
+ return beliefGoal;
+ }
+
+ public K getPredicate() {
+ return predicate;
+ }
+
+ public Boolean getSubscribe() {
+ return subscribe;
+ }
+
+ public Boolean getValue() {
+ return value;
+ }
+
+ public void setBeliefGoal(Boolean beliefGoal) {
+ this.beliefGoal = beliefGoal;
+ }
+
+ public void setPredicate(K predicate) {
+ this.predicate = predicate;
+ }
+
+ public void setSubscribe(Boolean subscribe) {
+ this.subscribe = subscribe;
+ }
+
+ public void setValue(Boolean value) {
+ this.value = value;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalResponse.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalResponse.java
new file mode 100644
index 0000000..a78d31e
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/message/GoalResponse.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.message;
+
+import jade.content.Concept;
+import jade.content.ContentElement;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class GoalResponse<K> implements Serializable, Concept,
+ ContentElement {
+
+ private static final long serialVersionUID = -260033218376521461L;
+
+ private K predicate;
+ private Date timestamp;
+ private Boolean value;
+
+ public GoalResponse() {
+
+ }
+
+ public GoalResponse(K predicate) {
+ this(predicate, null);
+ }
+
+ public GoalResponse(K predicate, Boolean value) {
+ this(predicate, value, null);
+ }
+
+ public GoalResponse(K predicate, Boolean value, Date timestamp) {
+ this.predicate = predicate;
+ this.value = value;
+ this.timestamp = timestamp;
+ }
+
+ public K getPredicate() {
+ return predicate;
+ }
+
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ public Boolean getValue() {
+ return value;
+ }
+
+ public void setPredicate(K predicate) {
+ this.predicate = predicate;
+ }
+
+ public void setTimestamp(Date timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public void setValue(Boolean value) {
+ this.value = value;
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDI4JADEOntology.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDI4JADEOntology.java
index 47e188c..bf084e4 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDI4JADEOntology.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDI4JADEOntology.java
@@ -11,15 +11,15 @@ import bdi4jade.belief.AbstractBeliefSet;
import bdi4jade.belief.Belief;
import bdi4jade.belief.BeliefSet;
import bdi4jade.belief.PersistentBelief;
-import bdi4jade.belief.PropositionalBelief;
+import bdi4jade.belief.Predicate;
import bdi4jade.belief.TransientBelief;
import bdi4jade.belief.TransientBeliefSet;
-import bdi4jade.belief.TransientPropositionalBelief;
+import bdi4jade.belief.TransientPredicate;
import bdi4jade.goal.BeliefGoal;
import bdi4jade.goal.BeliefPresentGoal;
import bdi4jade.goal.BeliefSetHasValueGoal;
import bdi4jade.goal.BeliefValueGoal;
-import bdi4jade.goal.PropositionalBeliefValueGoal;
+import bdi4jade.goal.PredicateGoal;
public class BDI4JADEOntology extends Ontology implements BDI4JADEVocabulary {
@@ -58,14 +58,14 @@ public class BDI4JADEOntology extends Ontology implements BDI4JADEVocabulary {
add(new PredicateSchema(BELIEF), Belief.class);
add(new PredicateSchema(BELIEF_SET), BeliefSet.class);
- add(new PredicateSchema(PROPOSITIONAL_BELIEF), PropositionalBelief.class);
+ add(new PredicateSchema(PROPOSITIONAL_BELIEF), Predicate.class);
add(new PredicateSchema(ABSTRACT_BELIEF), AbstractBelief.class);
add(new PredicateSchema(ABSTRACT_BELIEF_SET), AbstractBeliefSet.class);
add(new PredicateSchema(TRANSIENT_BELIEF), TransientBelief.class);
add(new PredicateSchema(TRANSIENT_BELIEF_SET), TransientBeliefSet.class);
add(new PredicateSchema(PERSISTENT_BELIEF), PersistentBelief.class);
- add(new PredicateSchema(TRANSIENT_PROPOSITIONAL_BELIEF), TransientPropositionalBelief.class);
+ add(new PredicateSchema(TRANSIENT_PROPOSITIONAL_BELIEF), TransientPredicate.class);
PredicateSchema cs = (PredicateSchema) getSchema(BELIEF);
cs.add(BELIEF_NAME, (ConceptSchema) getSchema(OBJECT_CONCEPT));
@@ -101,7 +101,7 @@ public class BDI4JADEOntology extends Ontology implements BDI4JADEVocabulary {
add(new PredicateSchema(BELIEF_PRESENT_GOAL), BeliefPresentGoal.class);
add(new PredicateSchema(BELIEF_SET_HAS_VALUE_GOAL), BeliefSetHasValueGoal.class);
add(new PredicateSchema(BELIEF_VAUE_GOAL), BeliefValueGoal.class);
- add(new PredicateSchema(PROPOSITIONAL_BELIEF_VAUE_GOAL), PropositionalBeliefValueGoal.class);
+ add(new PredicateSchema(PROPOSITIONAL_BELIEF_VAUE_GOAL), PredicateGoal.class);
cs = (PredicateSchema) getSchema(BELIEF_GOAL);
cs.add(BELIEF_GOAL_BELIEF_NAME, (ConceptSchema) getSchema(OBJECT_CONCEPT));
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetROntology.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetROntology.java
index fcff540..faefac1 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetROntology.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetROntology.java
@@ -25,23 +25,27 @@ import jade.content.onto.BasicOntology;
import jade.content.onto.Ontology;
import jade.content.onto.OntologyException;
import jade.content.schema.ConceptSchema;
+import jade.content.schema.ObjectSchema;
+import jade.content.schema.PredicateSchema;
import jade.content.schema.PrimitiveSchema;
import br.ufrgs.inf.bdinetr.domain.Flow;
import br.ufrgs.inf.bdinetr.domain.Ip;
import br.ufrgs.inf.bdinetr.domain.Link;
+import br.ufrgs.inf.bdinetr.domain.message.GoalProposal;
+import br.ufrgs.inf.bdinetr.domain.message.GoalRequest;
+import br.ufrgs.inf.bdinetr.domain.message.GoalResponse;
import br.ufrgs.inf.bdinetr.domain.predicate.Anomalous;
+import br.ufrgs.inf.bdinetr.domain.predicate.AnomalousUsage;
import br.ufrgs.inf.bdinetr.domain.predicate.AttackPrevented;
import br.ufrgs.inf.bdinetr.domain.predicate.Benign;
import br.ufrgs.inf.bdinetr.domain.predicate.BinaryPredicate;
+import br.ufrgs.inf.bdinetr.domain.predicate.FlowExport;
import br.ufrgs.inf.bdinetr.domain.predicate.FlowRateLimited;
-import br.ufrgs.inf.bdinetr.domain.predicate.FullyOperational;
+import br.ufrgs.inf.bdinetr.domain.predicate.IpRateLimited;
+import br.ufrgs.inf.bdinetr.domain.predicate.LinkRateLimited;
import br.ufrgs.inf.bdinetr.domain.predicate.OverUsage;
-import br.ufrgs.inf.bdinetr.domain.predicate.OverUsageCause;
-import br.ufrgs.inf.bdinetr.domain.predicate.RateLimited;
-import br.ufrgs.inf.bdinetr.domain.predicate.RegularUsage;
import br.ufrgs.inf.bdinetr.domain.predicate.Restricted;
import br.ufrgs.inf.bdinetr.domain.predicate.Threat;
-import br.ufrgs.inf.bdinetr.domain.predicate.ThreatResponded;
import br.ufrgs.inf.bdinetr.domain.predicate.UnaryPredicate;
/**
@@ -70,10 +74,12 @@ public class BDINetROntology extends Ontology implements BDINetRVocabulary {
}
public BDINetROntology() {
- super(ONTOLOGY_NAME, new Ontology[] { BDI4JADEOntology
- .getInstance() }, new Introspector());
+ super(ONTOLOGY_NAME, new Ontology[] { BasicOntology.getInstance() }, new Introspector());
try {
+ add(new ConceptSchema(OBJECT_CONCEPT), Object.class);
+ add(new PredicateSchema(OBJECT_PREDICATE), Object.class);
+
add(new ConceptSchema(FLOW), Flow.class);
add(new ConceptSchema(IP), Ip.class);
add(new ConceptSchema(LINK), Link.class);
@@ -94,44 +100,66 @@ public class BDINetROntology extends Ontology implements BDINetRVocabulary {
cs.add(LINK_ID, (PrimitiveSchema) getSchema(BasicOntology.STRING));
cs.addSuperSchema((ConceptSchema) getSchema(OBJECT_CONCEPT));
+ add(new ConceptSchema(FLOW_EXPORT), FlowExport.class);
+
+ cs = (ConceptSchema) getSchema(FLOW_EXPORT);
+ cs.add(FLOW_EXPORT_IP, (ConceptSchema) getSchema(IP));
+ cs.addSuperSchema((ConceptSchema) getSchema(OBJECT_CONCEPT));
+
add(new ConceptSchema(UNARY_PREDICATE), UnaryPredicate.class);
add(new ConceptSchema(BINARY_PREDICATE), BinaryPredicate.class);
add(new ConceptSchema(ANOMALOUS), Anomalous.class);
+ add(new ConceptSchema(ANOMALOUS_USAGE), AnomalousUsage.class);
add(new ConceptSchema(ATTACK_PREVENTED), AttackPrevented.class);
add(new ConceptSchema(BENIGN), Benign.class);
add(new ConceptSchema(FLOW_RATE_LIMITED), FlowRateLimited.class);
- add(new ConceptSchema(FULLY_OPERATIONAL), FullyOperational.class);
+ add(new ConceptSchema(IP_RATE_LIMITED), IpRateLimited.class);
+ add(new ConceptSchema(LINK_RATE_LIMITED), LinkRateLimited.class);
add(new ConceptSchema(OVER_USAGE), OverUsage.class);
- add(new ConceptSchema(OVER_USAGE_CAUSE), OverUsageCause.class);
- add(new ConceptSchema(RATE_LIMITED), RateLimited.class);
- add(new ConceptSchema(REGULAR_USAGE), RegularUsage.class);
add(new ConceptSchema(RESTRICTED), Restricted.class);
add(new ConceptSchema(THREAT), Threat.class);
- add(new ConceptSchema(THREAT_RESPONDED), ThreatResponded.class);
- ConceptSchema ps = (ConceptSchema) getSchema(UNARY_PREDICATE);
- ps.add(UNARY_PREDICATE_CONCEPT, (ConceptSchema) getSchema(OBJECT_CONCEPT));
- ps.addSuperSchema((ConceptSchema)getSchema(OBJECT_CONCEPT));
+ cs = (ConceptSchema) getSchema(UNARY_PREDICATE);
+ cs.add(UNARY_PREDICATE_CONCEPT, (ConceptSchema) getSchema(OBJECT_CONCEPT));
+ cs.addSuperSchema((ConceptSchema)getSchema(OBJECT_CONCEPT));
- ((ConceptSchema) getSchema(ANOMALOUS)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(ATTACK_PREVENTED)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(BENIGN)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(FLOW_RATE_LIMITED)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(FULLY_OPERATIONAL)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(OVER_USAGE)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(RATE_LIMITED)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(REGULAR_USAGE)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(RESTRICTED)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(THREAT)).addSuperSchema(ps);
- ((ConceptSchema) getSchema(THREAT_RESPONDED)).addSuperSchema(ps);
+ ((ConceptSchema) getSchema(ANOMALOUS)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(ANOMALOUS_USAGE)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(ATTACK_PREVENTED)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(BENIGN)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(FLOW_RATE_LIMITED)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(IP_RATE_LIMITED)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(LINK_RATE_LIMITED)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(OVER_USAGE)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(RESTRICTED)).addSuperSchema(cs);
+ ((ConceptSchema) getSchema(THREAT)).addSuperSchema(cs);
- ps = (ConceptSchema) getSchema(BINARY_PREDICATE);
- ps.add(BINARY_PREDICATE_FIRST, (ConceptSchema) getSchema(OBJECT_CONCEPT));
- ps.add(BINARY_PREDICATE_SECOND, (ConceptSchema) getSchema(OBJECT_CONCEPT));
- ps.addSuperSchema((ConceptSchema)getSchema(OBJECT_CONCEPT));
+ cs = (ConceptSchema) getSchema(BINARY_PREDICATE);
+ cs.add(BINARY_PREDICATE_FIRST, (ConceptSchema) getSchema(OBJECT_CONCEPT));
+ cs.add(BINARY_PREDICATE_SECOND, (ConceptSchema) getSchema(OBJECT_CONCEPT));
+ cs.addSuperSchema((ConceptSchema)getSchema(OBJECT_CONCEPT));
- ((ConceptSchema) getSchema(OVER_USAGE_CAUSE)).addSuperSchema(ps);
+ add(new PredicateSchema(GOAL_PROPOSAL), GoalProposal.class);
+ add(new PredicateSchema(GOAL_REQUEST), GoalRequest.class);
+ add(new PredicateSchema(GOAL_RESPONSE), GoalResponse.class);
+
+ PredicateSchema ps = (PredicateSchema) getSchema(GOAL_PROPOSAL);
+ ps.add(GOAL_PROPOSAL_COST, (PrimitiveSchema) getSchema(BasicOntology.FLOAT));
+ ps.addSuperSchema((PredicateSchema)getSchema(OBJECT_PREDICATE));
+
+ ps = (PredicateSchema) getSchema(GOAL_REQUEST);
+ ps.add(GOAL_REQUEST_BELIEF_GOAL, (PrimitiveSchema) getSchema(BasicOntology.BOOLEAN));
+ ps.add(GOAL_REQUEST_PREDICATE, (ConceptSchema) getSchema(OBJECT_CONCEPT));
+ ps.add(GOAL_REQUEST_SUBSCRIBE, (PrimitiveSchema) getSchema(BasicOntology.BOOLEAN));
+ ps.add(GOAL_REQUEST_VALUE, (PrimitiveSchema) getSchema(BasicOntology.BOOLEAN), ObjectSchema.OPTIONAL);
+ ps.addSuperSchema((PredicateSchema)getSchema(OBJECT_PREDICATE));
+
+ ps = (PredicateSchema) getSchema(GOAL_RESPONSE);
+ ps.add(GOAL_RESPONSE_PREDICATE, (ConceptSchema) getSchema(OBJECT_CONCEPT));
+ ps.add(GOAL_RESPONSE_TIMESTAMP, (PrimitiveSchema) getSchema(BasicOntology.DATE));
+ ps.add(GOAL_RESPONSE_VALUE, (PrimitiveSchema) getSchema(BasicOntology.BOOLEAN), ObjectSchema.OPTIONAL);
+ ps.addSuperSchema((PredicateSchema)getSchema(OBJECT_PREDICATE));
} catch (OntologyException oe) {
oe.printStackTrace();
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetRVocabulary.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetRVocabulary.java
index 2e5a844..73528fc 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetRVocabulary.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/ontology/BDINetRVocabulary.java
@@ -21,13 +21,17 @@
//----------------------------------------------------------------------------
package br.ufrgs.inf.bdinetr.domain.ontology;
+import java.util.Date;
+
/**
* @author Ingrid Nunes
*/
-public interface BDINetRVocabulary extends BDI4JADEVocabulary {
+public interface BDINetRVocabulary {
/** Concepts **/
+ public static final String OBJECT_CONCEPT = "ObjectConcept";
+
public static final String FLOW = "Flow";
public static final String FLOW_DST_IP = "dstIp";
public static final String FLOW_DST_PORT = "dstPort";
@@ -40,8 +44,9 @@ public interface BDINetRVocabulary extends BDI4JADEVocabulary {
public static final String LINK = "Link";
public static final String LINK_ID = "id";
-
- /** Predicates **/
+
+ public static final String FLOW_EXPORT = "FlowExport";
+ public static final String FLOW_EXPORT_IP = "ip";
public static final String UNARY_PREDICATE = "UnaryPredicate";
public static final String UNARY_PREDICATE_CONCEPT = "concept";
@@ -51,16 +56,32 @@ public interface BDINetRVocabulary extends BDI4JADEVocabulary {
public static final String BINARY_PREDICATE_SECOND = "second";
public static final String ANOMALOUS = "Anomalous";
+ public static final String ANOMALOUS_USAGE = "AnomalousUsage";
public static final String ATTACK_PREVENTED = "AttackPrevented";
public static final String BENIGN = "Benign";
public static final String FLOW_RATE_LIMITED = "FlowRateLimited";
- public static final String FULLY_OPERATIONAL = "FullyOperational";
+ public static final String IP_RATE_LIMITED = "IpRateLimited";
+ public static final String LINK_RATE_LIMITED = "LinkRateLimited";
public static final String OVER_USAGE = "OverUsage";
- public static final String OVER_USAGE_CAUSE = "OverUsageCause";
- public static final String RATE_LIMITED = "RateLimited";
- public static final String REGULAR_USAGE = "RegularUsage";
public static final String RESTRICTED = "Restricted";
public static final String THREAT = "Threat";
- public static final String THREAT_RESPONDED = "ThreatResponded";
+
+ /** Predicates **/
+
+ public static final String OBJECT_PREDICATE = "ObjectPredicate";
+
+ public static final String GOAL_PROPOSAL = "GoalProposal";
+ public static final String GOAL_PROPOSAL_COST = "cost";
+
+ public static final String GOAL_REQUEST = "GoalRequest";
+ public static final String GOAL_REQUEST_BELIEF_GOAL = "beliefGoal";
+ public static final String GOAL_REQUEST_PREDICATE = "predicate";
+ public static final String GOAL_REQUEST_SUBSCRIBE = "subscribe";
+ public static final String GOAL_REQUEST_VALUE = "value";
+
+ public static final String GOAL_RESPONSE = "GoalResponse";
+ public static final String GOAL_RESPONSE_PREDICATE = "predicate";
+ public static final String GOAL_RESPONSE_TIMESTAMP = "timestamp";
+ public static final String GOAL_RESPONSE_VALUE = "value";
}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Anomalous.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Anomalous.java
index 05c8d2d..1ce1a20 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Anomalous.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Anomalous.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Ip;
+/**
+ * @author Ingrid Nunes
+ */
public class Anomalous extends UnaryPredicate<Ip> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AnomalousUsage.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AnomalousUsage.java
new file mode 100644
index 0000000..ba21c81
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AnomalousUsage.java
@@ -0,0 +1,41 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
+
+import br.ufrgs.inf.bdinetr.domain.Link;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class AnomalousUsage extends UnaryPredicate<Link> {
+
+ private static final long serialVersionUID = -5495943806870470494L;
+
+ public AnomalousUsage() {
+
+ }
+
+ public AnomalousUsage(Link link) {
+ super(link);
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AttackPrevented.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AttackPrevented.java
index aab6d4b..82f7a61 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AttackPrevented.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/AttackPrevented.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Link;
+/**
+ * @author Ingrid Nunes
+ */
public class AttackPrevented extends UnaryPredicate<Link> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Benign.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Benign.java
index 91c6f67..880f09f 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Benign.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Benign.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Ip;
+/**
+ * @author Ingrid Nunes
+ */
public class Benign extends UnaryPredicate<Ip> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/BinaryPredicate.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/BinaryPredicate.java
index 1750a10..d88f96b 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/BinaryPredicate.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/BinaryPredicate.java
@@ -1,3 +1,24 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import jade.content.Concept;
@@ -5,6 +26,9 @@ import jade.content.ContentElement;
import java.io.Serializable;
+/**
+ * @author Ingrid Nunes
+ */
public abstract class BinaryPredicate<T, U> implements Serializable, Concept,
ContentElement {
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowExport.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowExport.java
new file mode 100644
index 0000000..9d9e75d
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowExport.java
@@ -0,0 +1,55 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
+
+import bdi4jade.annotation.Parameter;
+import bdi4jade.annotation.Parameter.Direction;
+import bdi4jade.goal.Goal;
+import br.ufrgs.inf.bdinetr.domain.Ip;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class FlowExport implements Goal {
+
+ private static final long serialVersionUID = -7114413010093171144L;
+
+ private Ip ip;
+
+ public FlowExport() {
+
+ }
+
+ public FlowExport(Ip ip) {
+ this.ip = ip;
+ }
+
+ @Parameter(direction = Direction.IN)
+ public Ip getIp() {
+ return ip;
+ }
+
+ public void setIp(Ip ip) {
+ this.ip = ip;
+ }
+
+}
\ No newline at end of file
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowRateLimited.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowRateLimited.java
index 499f729..cd8187e 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowRateLimited.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/FlowRateLimited.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Flow;
+/**
+ * @author Ingrid Nunes
+ */
public class FlowRateLimited extends UnaryPredicate<Flow> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/IpRateLimited.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/IpRateLimited.java
new file mode 100644
index 0000000..9eaf048
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/IpRateLimited.java
@@ -0,0 +1,41 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
+
+import br.ufrgs.inf.bdinetr.domain.Ip;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class IpRateLimited extends UnaryPredicate<Ip> {
+
+ private static final long serialVersionUID = -5495943806870470494L;
+
+ public IpRateLimited() {
+
+ }
+
+ public IpRateLimited(Ip ip) {
+ super(ip);
+ }
+
+}
\ No newline at end of file
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/LinkRateLimited.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/LinkRateLimited.java
new file mode 100644
index 0000000..720260e
--- /dev/null
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/LinkRateLimited.java
@@ -0,0 +1,41 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
+
+import br.ufrgs.inf.bdinetr.domain.Link;
+
+/**
+ * @author Ingrid Nunes
+ */
+public class LinkRateLimited extends UnaryPredicate<Link> {
+
+ private static final long serialVersionUID = -5495943806870470494L;
+
+ public LinkRateLimited() {
+
+ }
+
+ public LinkRateLimited(Link link) {
+ super(link);
+ }
+
+}
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsage.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsage.java
index c793bc2..7b93463 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsage.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsage.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Link;
+/**
+ * @author Ingrid Nunes
+ */
public class OverUsage extends UnaryPredicate<Link> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsageCause.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsageCause.java
index a638eb6..0180a70 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsageCause.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/OverUsageCause.java
@@ -1,9 +1,32 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
-import br.ufrgs.inf.bdinetr.domain.Ip;
import br.ufrgs.inf.bdinetr.domain.Link;
-public class OverUsageCause extends BinaryPredicate<Ip, Link> {
+/**
+ * @author Ingrid Nunes
+ */
+public class OverUsageCause extends UnaryPredicate<Link> {
private static final long serialVersionUID = -5495943806870470494L;
@@ -11,8 +34,8 @@ public class OverUsageCause extends BinaryPredicate<Ip, Link> {
}
- public OverUsageCause(Ip ip, Link link) {
- super(ip, link);
+ public OverUsageCause(Link link) {
+ super(link);
}
}
\ No newline at end of file
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Restricted.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Restricted.java
index cc13a78..2f36fd5 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Restricted.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Restricted.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Ip;
+/**
+ * @author Ingrid Nunes
+ */
public class Restricted extends UnaryPredicate<Ip> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Threat.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Threat.java
index 6cb9503..00169f6 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Threat.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/Threat.java
@@ -1,7 +1,31 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import br.ufrgs.inf.bdinetr.domain.Flow;
+/**
+ * @author Ingrid Nunes
+ */
public class Threat extends UnaryPredicate<Flow> {
private static final long serialVersionUID = -5495943806870470494L;
diff --git a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/UnaryPredicate.java b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/UnaryPredicate.java
index 41c506b..d0bdade 100644
--- a/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/UnaryPredicate.java
+++ b/network-resilience/src/br/ufrgs/inf/bdinetr/domain/predicate/UnaryPredicate.java
@@ -1,3 +1,24 @@
+//----------------------------------------------------------------------------
+// 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.predicate;
import jade.content.Concept;
@@ -5,6 +26,9 @@ import jade.content.ContentElement;
import java.io.Serializable;
+/**
+ * @author Ingrid Nunes
+ */
public abstract class UnaryPredicate<T> implements Serializable, Concept,
ContentElement {