input
stringlengths
10
828
output
stringlengths
5
107
override public void changed connection connection con
called when a connections state changes
public void test message relay abort message m1 new message h1 h2 msg id1 buffer size h1 create new message m1 check creates 1 h1 connect h2 update all nodes assert true mc next assert equals mc type start mc get last type assert false mc next clock advance 1 update all nodes assert false mc next h2 set location far away update all nodes disconnect still transferring assert true mc next assert equals mc type abort mc get last type assert equals h1 mc get last from assert false mc next
tests aborting transfer when connections is disconnected during the
private void update transitive probs map integer meeting probability set p for map entry integer meeting probability set e p entry set meeting probability set my mps this all probs get e get key if my mps null e get value get last update time my mps get last update time this all probs put e get key e get value replicate
updates transitive probability values by replacing the current
public void test abort when ready message m1 new message h2 h1 msg id2 1 h2 create new message m1 check creates 1 h2 connect h1 update all nodes should start transfer assert true mc next assert equals mc type start mc get last type assert false mc next clock advance 10 h2 set location far away transfer should have been finished even if nodes disconnected update all nodes assert true mc next assert equals mc type relay mc get last type assert equals h2 mc get last from assert false mc next
try disconnecting on the same update interval when a transfer should
private void delete acked messages for string id this acked message ids if this has message id is sending id this delete message id false
deletes the messages from the message buffer that are known to be acked
public int get nrof messages return this messages size
returns the number of messages this router has
public int get free buffer size int occupancy 0 if this get buffer size integer max value return integer max value for message m get message collection occupancy m get size return this get buffer size occupancy
returns the amount of free space in the buffer
private void update transferred bytes avg int new value int real count 0 int sum 0 this avg samples this next sample index new value if this next sample index bytes transferred avg samples this next sample index 0 for int i 0 i bytes transferred avg samples i if this avg samples i 0 only values above zero count real count sum this avg samples i if real count 0 this avg transferred bytes sum real count else no samples or all samples are zero this avg transferred bytes 0
updates the average estimate of the number of bytes transferred per
protected int start transfer message m connection con int ret val con start transfer get host m if ret val rcv ok started transfer add to sending connections con else if delete delivered ret val denied old m get to con get other node this get host final recipient has already received the msg delete it this delete message m get id false return ret val
tries to start a transfer of message using a connection
protected dtnhost get host return this host
returns the host this router is in
protected void update regularity int to host address hours since the simulation started int now sim clock get int time 3600 update regularity to host address now
log host encounters and build up regularities data
public void send message string id dtnhost to message m get message id message m2 if m null throw new sim error no message for id id to send at this host m2 m replicate send a replicate of the message to receive message m2 this host
start sending a message to another host
protected message get oldest message boolean exclude msg being sent collection message messages this get message collection list message valid messages new array list message for message m messages if exclude msg being sent is sending m get id continue skip the message s that router is sending valid messages add m collections sort valid messages new max prop comparator this calc threshold return valid messages get valid messages size 1 return last message
returns the next message that should be dropped according to max props
protected boolean can start transfer if this get nrof messages 0 return false if this get connections size 0 return false return true
makes rudimentary checks that we have at least one message and one
public boolean request deliverable messages connection con return false default behavior is to not start subclasses override
requests for deliverable message from this router to be sent trough a
protected int check receiving message m if is transferring return try later busy only one connection at a time if has message m get id is delivered message m return denied old already seen this message reject it if m get ttl 0 m get to get host ttl has expired and this host is not the final recipient return denied ttl remove oldest messages but not the ones being sent if make room for message m get size return denied no space couldn t fit into buffer reject return rcv ok
checks if router wants to start receiving message i
public int receive message message m dtnhost from this put to incoming buffer m from for message listener ml this m listeners ml message transfer started m from get host return rcv ok superclass always accepts messages
try to start receiving a message from another host
protected boolean make room for message int size if size this get buffer size return false message too big for the buffer int free buffer this get free buffer size delete messages from the buffer until there s enough space while free buffer size message m get oldest message true don t remove msgs being sent if m null return false couldn t remove any more messages delete message from the buffer as drop delete message m get id true free buffer m get size return true
removes messages from the buffer oldest first until
protected void drop expired messages message messages get message collection to array new message 0 for int i 0 i messages length i int ttl messages i get ttl if ttl 0 delete message messages i get id true
drops messages whose ttl is less than zero
protected void put to incoming buffer message m dtnhost from this incoming messages put m get id from to string m
puts a message to incoming messages buffer
protected void make room for new message int size make room for message size
tries to make room for a new message
protected message remove from incoming buffer string id dtnhost from return this incoming messages remove id from to string
removes and returns a message with a certain id from the incoming
protected message get oldest message boolean exclude msg being sent collection message messages this get message collection message oldest null for message m messages if exclude msg being sent is sending m get id continue skip the message s that router is sending if oldest null oldest m else if oldest get receive time m get receive time oldest m return oldest
returns the oldest by receive time message in the message buffer
protected void add to messages message m boolean new message this messages put m get id m if new message for message listener ml this m listeners ml new message m
adds a message to the message buffer and informs message listeners
protected message try all messages connection con list message messages for message m messages int ret val start transfer m con if ret val rcv ok return m accepted a message don t try others else if ret val 0 return null should try later don t bother trying others return null no message was accepted
goes trough the messages until the other node accepts one
protected message remove from messages string id message m this messages remove id return m
removes and returns a message from the message buffer
private void init preds this preds new hash map dtnhost double
initializes predictability hash
public void message aborted string id dtnhost from int bytes remaining message incoming remove from incoming buffer id from if incoming null throw new sim error no incoming message for id id to abort in this host for message listener ml this m listeners ml message transfer aborted incoming from this host
this method should be called on the receiving host when a message
protected connection try all messages to all connections list connection connections get connections if connections size 0 this get nrof messages 0 return null list message messages new array list message this get message collection this sort by queue mode messages return try messages to connections messages connections
tries to send all messages that this router is carrying to all
private void update delivery pred for dtnhost host double old value get pred for host double new value old value 1 old value p init preds put host new value
updates delivery predictions for a host
protected connection exchange deliverable messages list connection connections get connections if connections size 0 return null suppress warnings value unchecked tuple message connection t try messages for connected sort by queue mode get messages for connected if t null return t get value started transfer didn t start transfer to any node ask messages from connected for connection con connections if con get other node get host request deliverable messages con return con return null
exchanges deliverable to final recipient messages between this host
public boolean create new message message m m set ttl this msg ttl add to messages m true return true
creates a new message to the router
private void age delivery preds double time diff sim clock get time this last age update seconds in time unit if time diff 0 return double mult math pow gamma time diff for map entry dtnhost double e preds entry set e set value e get value mult this last age update sim clock get time
ages all entries in the delivery predictions
protected void shuffle messages list message messages if messages size 1 return nothing to shuffle random rng new random sim clock get int time collections shuffle messages rng
shuffles a messages list so the messages are in random order
public void delete message string id boolean drop message removed remove from messages id if removed null throw new sim error no message for id id to remove at this host for message listener ml this m listeners ml message deleted removed this host drop
deletes a message from the buffer and informs message listeners
protected void add to sending connections connection con this sending connections add con
adds a connections to sending connections which are monitored in
protected void set energy double range if range length 1 this current energy range 0 else if rng null rng new random int range 0 range 1 this current energy range 0 rng next double range 1 range 0
sets the current energy level into the given range using uniform
protected void reduce energy double amount if sim clock get time this warmup time return com bus update double energy value id amount if this current energy 0 com bus update property energy value id 0 0
updates the current energy so that the given amount is reduced from it
private jcheck box add check box boolean selected boolean end of row jcheck box box new jcheck box box set selected selected if end of row c gridwidth grid bag constraints remainder use rest of the line else c gridwidth 1 default layout set constraints box c add box return box
creates and adds a new checkbox to this panel
public boolean is transferring if this sending connections size 0 return true sending something if this get host get connections size 0 return false not connected list connection connections get connections for int i 0 n connections size i n i connection con connections get i if con is ready for transfer return true a connection isn t ready for new transfer return false
returns true if this router is transferring something at the moment or
public event log control add control string name return add control name true false
adds a new filter pause control with initially show checked
public void add heading string name c gridwidth grid bag constraints remainder add label name set font this heading font
adds a new heading in the control panel
public int compare object o1 object o2 double diff message m1 m2 if o1 instanceof tuple m1 tuple message connection o1 get key m2 tuple message connection o2 get key else if o1 instanceof message m1 message o1 m2 message o2 else throw new sim error invalid type of objects in the list diff m1 get receive time m2 get receive time if diff 0 return 0 return diff 0 1 1
compares two tuples by their messages receiving time
public void show info message message reset this add new jlabel message to string set message info message this revalidate
show information about a message
public boolean is sending string msg id for connection con this sending connections if con get message null continue transmission is finalized if con get message get id equals msg id return true return false
returns true if this router is currently sending a message with
public void module value changed string key object new value this current energy double new value
called by the combus is the energy value is changed
public play field world w this w w this ref graphic new scale reference graphic update field size this set background bg color this overlay graphics collections synchronized list new array list play field graphic this map graphic null this underlay image null this image transform null this auto clear overlay true
creates a playfield
private void draw messages graphics2 d g2 int nrof messages node get nrof messages coord loc node get location draw bar g2 loc nrof messages 10 1 draw bar g2 loc nrof messages 10 2
visualize the messages this node is carrying
protected int compare by queue mode message m1 message m2 switch send queue mode case q mode random return randomly enough but consistently 1 0 or 1 return m1 hash code 2 m2 hash code 2 3 1 case q mode fifo double diff m1 get receive time m2 get receive time if diff 0 return 0 return diff 0 1 1 add more queue modes here default throw new sim error unknown queue mode send queue mode
gives the order of the two given messages as defined by the current
public void update field this repaint
schedule the play field to be drawn
private void draw bar graphics2 d g2 coord loc int nrof int col final int bar height 5 final int bar width 5 final int bar displacement 2 draws a stack of squares next loc for int i 1 i nrof i if i 2 0 use different color for every other msg g2 set color msg color1 else if col 1 g2 set color msg color3 else g2 set color msg color2 g2 fill rect scale loc get x bar displacement bar width col scale loc get y bar displacement i bar height scale bar width scale bar height
draws a bar stack of squares next to a location
public void set scale double scale play field graphic set scale scale this update field size if this image transform null this cur transform new affine transform image transform cur transform scale scale scale cur transform translate this underlay img dx this underlay img dy
sets the zooming scaling factor
private event log control panel create controls event log control panel c new event log control panel c add heading connections con up check c add control up con down check c add control down c add heading messages msg create check c add control created msg transfer start check c add control started relay msg relay check c add control relayed msg delivered check c add control delivered msg remove check c add control removed msg drop check c add control dropped msg abort check c add control aborted return c
creates a control panel for the log
public void set map sim map sim map this map graphic new map graphic sim map this show map graphic true
sets the source for the map graphics and enables map graphics showing
public event log control panel get controls return this controls
returns the control panel that this log uses
public void set show map graphic boolean show this show map graphic show
enables disables showing of map graphics
public void set auto clear overlay boolean clear this auto clear overlay clear
enables or disables the automatic clearing of overlay graphics
public void close sim if sim done system exit 0 this world cancel sim this sim cancelled true
closes the program if simulation is done or cancels it
private void update log view todo optimization check if update is really necessary this remove all for int i 0 i this event panes size i this add event panes get i revalidate
updates the log view
public void clear overlays this overlay graphics clear
removes all overlay graphics stored to be drawn
public void add message transfer dtnhost from dtnhost to auto clear this overlay graphics add new message graphic from to
adds graphics for message transfer
public void set sim time double time long time since update system current time millis this last update if time since update eps avg time double val time this last sim time 1000 time since update string seps value string format 2f 1 s val this seps field set text seps value this last sim time time this last update system current time millis this sim time field set text string format 1f time
sets the simulation time that control panel shows
private void add info button jpanel panel object o string client prop jbutton h button h button new jbutton o to string h button put client property client prop o h button add action listener this h button set font font h button set margin new insets 0 0 0 0 h button set background log button bg panel add h button
adds a new button to a log entry panel and attaches a client
public string to string return get class get simple name of this get host to string with get nrof messages messages
returns a string presentation of this router
public void add path path path auto clear this overlay graphics add new path graphic path this update field
adds a path to the overlay graphics
private void update view double sim time sim clock get time this last update sim time gui controls set sim time sim time update time to control panel this field update field
updates playfield and sim time field
private void auto clear if this auto clear overlay this clear overlays
clears overlay graphics if autoclear is requested
public void set paused boolean paused if paused this play button set icon create image icon icon pause this play button set tool tip text text pause this paused false if sim clock get time this play until time play until time passed disable it this play until time double max value else this play button set icon create image icon icon play this play button set tool tip text text play this paused true this set sim time sim clock get time this pf update field
sets simulation to pause or play
public void set paused boolean paused this gui controls set paused paused
sets the pause of the simulation on off
public coord get graphics position coord loc coord c loc clone c set location play field graphic scale c get x play field graphic scale c get y return c
returns the graphical presentation location for the given world
public void set focus dtnhost host center view at host get location info panel show info host show path host get path show path on the playfield
sets a nodes graphical presentation in the center of the playfield view
private void set nodes int offset nodes panel remove all for int i offset i nodes size i offset max node count i dtnhost h nodes get i jbutton jb new jbutton h to string jb put client property host key h jb add action listener this nodes panel add jb revalidate repaint
sets the right set of nodes to display
public void action performed action event e if e get source instanceof jbutton jbutton source jbutton e get source dtnhost host dtnhost source get client property host key gui set focus host else if e get source group chooser set nodes group chooser get selected index max node count
action listener method for buttons and node set chooser
public boolean show event return this show is selected
returns true if this event type should be shown
public coord get world position coord loc coord c loc clone c set location play field graphic inv scale c get x play field graphic inv scale c get y return c
returns a world location for a given graphical location
public void show path path path field add path path
shows a path on the playfield
public void set show event boolean show this show set selected show
sets ought this event type should be shown return true for
public jscroll pane get play field scroll return this play field scroll
returns a reference of the play field scroll panel
public coord get center view coord jscroll pane sp main get play field scroll double mid x mid y mid x sp get horizontal scroll bar get value sp get viewport get width 2 mid y sp get vertical scroll bar get value sp get viewport get height 2 return this field get world position new coord mid x mid y
returns the world coordinates that are currently in the center
private void update field size dimension min size new dimension play field graphic scale w get size x play field graphic scale w get size y this set minimum size min size this set preferred size min size this set size min size
updates the playfields graphical size to match the worlds size
private void update boolean forced long now system current time millis long diff now this last update rt double dur now start time 1000 0 if forced diff ui up interval simulated seconds second calc double ssps sim clock get time last update 1000 diff print string format 1f d 2f 1 s dur sim clock get int time ssps this last update rt system current time millis this last update sim clock get time
updates user interface if the long enough real time update interval
public void start init model run sim
starts the simulation
public boolean is paused if step if we want to step return false once and reset stepping step false return false if sim clock get time this play until time this set paused true return this paused
has user requested the simulation to be paused
public void center view at coord loc jscroll pane sp main get play field scroll coord g loc this field get graphics position loc int mid x mid y update view update graphics to match the values mid x int g loc get x sp get viewport get width 2 mid y int g loc get y sp get viewport get height 2 sp get horizontal scroll bar set value mid x sp get vertical scroll bar set value mid y
sets certain location to be in the center of the playfield view
public void set print stream print stream out strm out out strm
sets print stream of debug output
public void done for report r this reports r done
runs maintenance jobs that are needed before exiting
public void add nodes collection dtnhost nodes for dtnhost n nodes grid cell c cell from coord n get location c add node n n set cur cell c
adds nodes to overlay grid
public info panel get info panel return this info panel
returns the info panel of the gui
protected void add report report r if r instanceof message listener scen add message listener message listener r if r instanceof connection listener scen add connection listener connection listener r if r instanceof movement listener scen add movement listener movement listener r if r instanceof update listener scen add update listener update listener r this reports add r
adds a new report for simulator
public void set location coord c this x c x this y c y
sets this coordinates location to be equal to other
public boolean is ffw return this is ffw
is fast forward turned on
public void update location dtnhost node grid cell old cell node get cur cell grid cell new cell cell from coord node get location if new cell old cell old cell move node node new cell node set cur cell new cell
checks and updates if necessary nodes position in the grid
public main window get parent frame return this main
returns the parent frame window of the gui
public double distance coord other double dx this x other x double dy this y other y return math sqrt dx dx dy dy
returns the distance to another coordinate
private void wait int ms try thread sleep ms catch interrupted exception e nothing to do here
suspend thread for ms milliseconds
public void connect all near nodes for int i 1 i this rows i for int j 1 j this cols j list dtnhost nodes this cells i j get nodes if nodes size 0 continue skip empty cells grid cell neighbors get neighbor cells i j for int k 0 n nodes size k n k connect nodes in cells nodes get k neighbors
connects all nodes that are in adjacent cells to each other
public double get update interval return this gui update interval
returns the selected update interval of gui
public string to string return string format 2f 2f x y
returns a text representation of the coordinate rounded to 2 decimals
public void mouse clicked mouse event e java awt point p e get point center view at field get world position new coord p x p y
if mouse button is clicked centers view at that location
public coord clone coord clone null try clone coord super clone catch clone not supported exception e e print stack trace system exit 1 return clone
returns a clone of this coordinate