Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Simulate

Álvaro Carrera edited this page Jun 18, 2013 · 1 revision

#summary Chapter four of the Shanks User Manual. #labels Phase-Support

== 3. NETWORK SIMULATION == We have the network elements, failures that affect them and we put all of that on a scenario. What it takes to run a simulation?

To launch the simulation we implement a class that inherits from ShanksSimulation. This class must have a main method to obtain an instance of the scenario we have define, make its set up and perform the simulation step by step.

An implementation of this class present in code below. === 3.1. HAN-Model: Simulation === We are coming to an executable version of the example, now we need just to implement the class that allows us to run our simulation. Next we present the code lines of that class beofre explain it. ==== Textbox 6: HANModelSimulation.java ==== {{{ package es.upm.gsi.tsag.demo.simulation; import java.lang.reflect.InvocationTargetException; […]

public class HANModelSimulation extends ShanksSimulation {

public HANModelSimulation(long seed, Class<? extends Scenario> scenarioClass, String scenarioID, String initialState, Properties properties) throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, UnsupportedNetworkElementStatusException, TooManyConnectionException, UnsupportedScenarioStatusException, DuplicatedIDException, DuplicatedPortrayalIDException, ScenarioNotFoundException, DuplicatedAgentIDException, DuplicatedActionIDException { super(seed, scenarioClass, scenarioID, initialState, properties); }

public static void main(String[] args) { try { Properties scenarioProperties = new Properties(); scenarioProperties.put(Scenario.SIMULATION_GUI, Scenario.NO_GUI); HANModelSimulation tut = new HANModelSimulation( System.currentTimeMillis(), HANScenario.class, "MyHomeAreaNetwork", HANScenario.STATUS_SUNNY, scenarioProperties); tut.start(); do if (!tut.schedule.step(tut)) break; while (tut.schedule.getSteps() < 8001); tut.finish(); } catch (Exception e) { e.printStackTrace(); } }

public void addSteppables() { Steppable steppable = new Steppable() { public void step(SimState sim) { ShanksSimulation simulation = (ShanksSimulation) sim; } }; schedule.scheduleRepeating(Schedule.EPOCH, 3, steppable, 500); } }

}}}

TODO: Explain it!!!

Clone this wiki locally