////////////////////////////////////////////////// // JIST (Java In Simulation Time) Project package driver; import jist.runtime.JistAPI; import jist.swans.Constants; import jist.swans.app.AppHeartbeat; import jist.swans.field.Fading; import jist.swans.field.Field; import jist.swans.field.Mobility; import jist.swans.field.PathLoss; import jist.swans.field.Placement; import jist.swans.field.Spatial; import jist.swans.mac.Mac802_11; import jist.swans.mac.MacAddress; import jist.swans.misc.Location; import jist.swans.misc.Mapper; import jist.swans.misc.Util; import jist.swans.net.NetAddress; import jist.swans.net.NetIp; import jist.swans.net.PacketLoss; import jist.swans.radio.RadioInfo; import jist.swans.radio.RadioNoiseIndep; /** * SWANS demo/test: heartbeating on multiple radios on the same device. * * @author Alex Kogan <sakogan@gmail.com> */ public class testDriver { /** random waypoint pause time. */ public static final int PAUSE_TIME = 30; /** random waypoint granularity. */ public static final int GRANULARITY = 10; /** random waypoint minimum speed. */ public static final int MIN_SPEED = 2; /** random waypoint maximum speed. */ public static final int MAX_SPEED = 10; /** define max number of nodes in the simulation */ private static final int MAX_NODES_NUM = 10000; /** * Initialize simulation node. * * @param i * node number * @param field * simulation field * @param placement * node placement model * @param radioInfoShared * shared radio information * @param protMap * shared protocol map * @param plIn * incoming packet loss model * @param plOut * outgoing packet loss model */ public static void createNode(int i, Field field, Placement placement, RadioInfo.RadioInfoShared radioInfoShared1, RadioInfo.RadioInfoShared radioInfoShared2, Mapper protMap, PacketLoss plIn, PacketLoss plOut) { // create entities int macID1 = i; int macID2 = i + MAX_NODES_NUM; RadioNoiseIndep radio1 = new RadioNoiseIndep(macID1, radioInfoShared1); RadioNoiseIndep radio2 = new RadioNoiseIndep(macID1, radioInfoShared2); Mac802_11 mac1 = new Mac802_11(new MacAddress(macID1), radio1.getRadioInfo()); Mac802_11 mac2 = new Mac802_11(new MacAddress(macID2), radio2.getRadioInfo()); // note that here, IP = macID1, but it is not obligatory NetAddress nodeIP = new NetAddress(i); NetIp net = new NetIp(nodeIP, protMap, plIn, plOut); // NetIp net = new NetIp(new NetAddress(i), protMap, plIn, plOut); // hookup entities Location nodeLocation = placement.getNextLocation(); field.addRadio(radio1.getRadioInfo(), radio1.getProxy(), nodeLocation); field.addRadio(radio2.getRadioInfo(), radio2.getProxy(), nodeLocation, macID1); // start mobility only on the first interface field.startMobility(macID1); radio1.setFieldEntity(field.getProxy()); radio2.setFieldEntity(field.getProxy()); radio1.setMacEntity(mac1.getProxy()); mac1.setRadioEntity(radio1.getProxy()); radio2.setMacEntity(mac2.getProxy()); mac2.setRadioEntity(radio2.getProxy()); byte interfaceId1 = net.addInterface(mac1.getProxy()); mac1.setNetEntity(net.getProxy(), interfaceId1); byte interfaceId2 = net.addInterface(mac2.getProxy()); mac2.setNetEntity(net.getProxy(), interfaceId2); // define these constants in jist.swans.Constants AppHeartbeat app1 = new AppHeartbeat(macID1, (short)901, interfaceId1, nodeIP,true); AppHeartbeat app2 = new AppHeartbeat(macID2, (short)902, interfaceId2, nodeIP, true); net.setProtocolHandler(901, app1.getNetProxy()); net.setProtocolHandler(902, app2.getNetProxy()); app1.setNetEntity(net.getProxy()); app2.setNetEntity(net.getProxy()); app1.getAppProxy().run(null); app2.getAppProxy().run(null); } /** * Initialize simulation field. * * @param nodes * number of nodes * @param length * length of field * @return simulation field */ public static Field createSim(int nodes, int length) { Location.Location2D bounds = new Location.Location2D(length, length); Placement placement = new Placement.Random(bounds); Mobility mobility = new Mobility.RandomWaypoint(bounds, PAUSE_TIME, GRANULARITY, MAX_SPEED, MIN_SPEED); Spatial spatial = new Spatial.HierGrid(bounds, 5); Fading fading = new Fading.None(); PathLoss pathloss = new PathLoss.FreeSpace(); Field field = new Field(spatial, fading, pathloss, mobility, Constants.PROPAGATION_LIMIT_DEFAULT); RadioInfo.RadioInfoShared radioInfoShared1 = RadioInfo.createShared( Constants.FREQUENCY_DEFAULT, Constants.BANDWIDTH_DEFAULT / 54, Constants.TRANSMIT_DEFAULT, -16, Util.fromDB(Constants.SENSITIVITY_DEFAULT), Util.fromDB(Constants.THRESHOLD_DEFAULT), Constants.TEMPERATURE_DEFAULT, Constants.TEMPERATURE_FACTOR_DEFAULT, Constants.AMBIENT_NOISE_DEFAULT, "radio1"); RadioInfo.RadioInfoShared radioInfoShared2 = RadioInfo.createShared( Constants.FREQUENCY_DEFAULT, Constants.BANDWIDTH_DEFAULT, Constants.TRANSMIT_DEFAULT, Constants.GAIN_DEFAULT, Util.fromDB(Constants.SENSITIVITY_DEFAULT), Util.fromDB(Constants.THRESHOLD_DEFAULT), Constants.TEMPERATURE_DEFAULT, Constants.TEMPERATURE_FACTOR_DEFAULT, Constants.AMBIENT_NOISE_DEFAULT, "radio2"); Mapper protMap = new Mapper(Constants.NET_PROTOCOL_MAX); // define these constants in jist.swans.Constants protMap.mapToNext(901); protMap.mapToNext(902); protMap.mapToNext(Constants.NET_PROTOCOL_HEARTBEAT); PacketLoss pl = new PacketLoss.Zero(); for (int i = 0; i < nodes; i++) { createNode(i, field, placement, radioInfoShared1, radioInfoShared2, protMap, pl, pl); } return field; } /** * Benchmark entry point: heartbeat test. * * @param args * command-line parameters */ public static void main(String[] args) { if (args.length < 3) { System.out .println("syntax: swans driver.heartbeat