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

NetworkModel

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

#summary Chapter 3 of User Manual

=Chapter 3 : Creating the Networkd Model= In this chapter we will explain how to create the different elements and the scenario to put them.

== 3.1 Creating the devices ==

Now we have configured properly the project and the correct package structure, so we can start to program the code. First we program the devices. We only create a generic class of each device. For example: if we have five similar computers in the scenario we only need one class of the device called Computer.class. In this tutorial-module we have one router and five computers, so you can find in model.element.device two classes (Router.class and Computer.class) we explain the Computer.class but the explanation is applicable to any Device.class Open the Compuer.class, we explain the use of each method: First we have to write the constructor, a Device.class constructor always have the same structure, in our class is:

{{{ public Compuer(String id, String initialState, boolean isGateway){ super(id, initialState, isGateway); } }}}

Next you have to define as constants the different properties and states of the device. A device can have all the properties and status that you want. In that case for simplify the explanation our device only have four states and three properties.

{{{ public static final String STATUS_OFF = "OFF"; public static final String STATUS_OK = "OK"; public static final String STATUS_HIGHTEMP = "High Temperature"; public static final String STATUS_DISCONNECTED = "Disconnected"; public static final String PROPERTY_TEMPERATURE = "Temperature"; public static final String PROPERTY_POWER = "Power"; public static final String PROPERTY_ETHERNET_CONNECTION = "Connection"; }}}

Once we have defined the properties and the states of the device we have to initialize the properties and indicate which are the possibles states of the device (take care about this last part because if you dont indicate the states properly, SHANKS will launch and exception if the device enter in a status that is not supported). To do this we have these two methods:

{{{ public void fillInitialProperties(); public void setPossibleStates(); }}}

In the code you have the necessary lines to add the states and put the properties.

Now we have a device with possibles states and initial properties. The next step is indicate which are the relations between the properties and states and how the device change its states if a property is changed and vice versa. To check the properties you have to use these methods:

{{{ public void checkProperties(); }}}

And to check the status you have to use:

{{{ public void checkStatus(); }}}

In the Computer.class you have an example of how to fill these two methods. Once you have coded all these methods, constructor, and constanst a Device class has been completed.

== 3.2 Creating the links ==

In order to connect the differents devices, first you have to code some links, as a Device class, you can create similars links with a simple Link class. The structure of a Link class is similar to a Device class, only have a diferent in a parameter of the constructor, the last parameter in a constructor of a Link class is {{{int capacity}}}, it indicates how many devices can connect this link, if you connect more devices SHANKS will launch an exception. Once you have create all the Links classes you can start to create the scenario.

== 3.3 Creating the Scenario ==

Now we will explain how you can connect the devices and links that you have created in the previous steps. To create the scenario you have to code an Scenario class. In our example this class is called LANScenario and you can find it in the package scenario. In this point we only explain the connection between devices and links, if you want to add some graphics we will explain it in the fifth point of this tutorial and how to add events and failures in the fourth point. An scenario can have differents states, so first you have to write the state constants. In our example we only manage two states:

{{{ public static final String CLOUDY = "CLOUDY"; public static final String SUNNY = "SUNNY"; }}}

The process to add this states to the scenario is the same that in a Device/Link class. Next step is to code the constructor, all Scenario classes have the generic constructor:

{{{ public LANScenario(String id, String initialState, Properties properties) throws ShanksException { super(id, initialState, properties); } }}}

Now we explain you how you can create the components and set relations between them, to achieve this goal you have to fill this method:

{{{ public void addNetworkElements(); }}}

In this method you have to create objects from the Device/Links classes, establish the connections between them and add them to the scenario. Create a device:

{{{ Device computer1 = new Computer("Computer 1", Computer.STATUS_OFF, false); Device router = new Router("Router", Router.STATUS_OK, true); }}}

Create a link:

{{{ Link l1 = new EthernetLink("L1", EthernetLink.STATUS_OK, 2); }}}

Establish a connection:

{{{ l1.connectDevices(router, computer1); }}}

And finally add the components:

{{{ this.addNetworkElement(computer1); }}}

You have to do this always you want to create a new Device and add it to the scenario. When you finish this part you will have a complete scenario. In the next point of this tutorial we explain you how to add events and failures to this scenario.

Clone this wiki locally