Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pydtnsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
discus
pydtnsim
Commits
80884444
Commit
80884444
authored
7 years ago
by
Jarrod Pas
Browse files
Options
Downloads
Patches
Plain Diff
Cleans up node transmission code
parent
361c79c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Version 0.2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pydtn/buffer.py
+2
-1
2 additions, 1 deletion
pydtn/buffer.py
pydtn/node.py
+65
-22
65 additions, 22 deletions
pydtn/node.py
with
67 additions
and
23 deletions
pydtn/buffer.py
+
2
−
1
View file @
80884444
...
@@ -16,8 +16,9 @@ class Buffer:
...
@@ -16,8 +16,9 @@ class Buffer:
if
self
.
used
<
self
.
capacity
:
if
self
.
used
<
self
.
capacity
:
self
.
used
+=
1
self
.
used
+=
1
self
.
buffer
[
packet
]
=
None
self
.
buffer
[
packet
]
=
None
return
True
else
:
else
:
r
aise
Exception
(
'
buffer full
'
)
r
eturn
False
def
remove
(
self
,
packet
):
def
remove
(
self
,
packet
):
self
.
used
-=
1
self
.
used
-=
1
...
...
This diff is collapsed.
Click to expand it.
pydtn/node.py
+
65
−
22
View file @
80884444
...
@@ -33,35 +33,51 @@ class Node(TickProcess):
...
@@ -33,35 +33,51 @@ class Node(TickProcess):
self
.
transfer_queue
=
Store
(
self
.
env
)
self
.
transfer_queue
=
Store
(
self
.
env
)
def
route_packets
(
self
):
def
route_packet
(
self
,
packet
):
packets_to_delete
=
[]
'''
Applies the routing heuristic to packet and queues packet for
transfer if requested
for
packet
in
self
.
buffer
:
Returns:
# remove expired packets from buffer
True - if the packet should be deleted from the buffer
if
packet
.
expired
(
self
.
env
.
now
):
False - otherwise
packets_to_delete
.
append
(
packet
)
'''
continue
# ask the router what to do
# check if packet has expired
targets
,
reason
,
delete
=
self
.
router
(
packet
)
if
packet
.
expired
(
self
.
env
.
now
):
return
True
# check if there are targets to send to
# ask the router what to do
if
targets
is
None
:
targets
,
reason
,
delete
=
self
.
router
(
packet
)
continue
# allow for targets to be iterable or single item
# check if there are targets to send to
if
not
isinstance
(
targets
,
Iterable
):
if
targets
is
None
:
targets
=
[
targets
]
return
False
# allow for targets to be iterable or single item
if
not
isinstance
(
targets
,
Iterable
):
targets
=
[
targets
]
# add the packet to the transfer queue
self
.
transfer_queue
.
put
((
packet
,
targets
,
reason
))
return
delete
def
route_packets
(
self
):
'''
Applies the routing heuristic to all packets in the buffer and
queues transfers if requested. Additionally, removes packets
from the buffer if the packet has exipred or if the router
requests the packet to be removed.
'''
# add the packet to the transfer queue
packets_to_delete
=
[]
self
.
transfer_queue
.
put
((
packet
,
targets
,
reason
))
#self.send(targets, packet, reason)
# if the router requested deletion from the buffer do it
for
packet
in
self
.
buffer
:
delete
=
self
.
route_packet
(
packet
)
if
delete
:
if
delete
:
packets_to_delete
.
append
(
packet
)
packets_to_delete
.
append
(
packet
)
for
packet
in
packets_to_delete
:
for
packet
in
packets_to_delete
:
self
.
buffer
.
remove
(
packet
)
self
.
buffer
.
remove
(
packet
)
...
@@ -70,6 +86,8 @@ class Node(TickProcess):
...
@@ -70,6 +86,8 @@ class Node(TickProcess):
while
True
:
while
True
:
packet
,
targets
,
reason
=
yield
self
.
transfer_queue
.
get
()
packet
,
targets
,
reason
=
yield
self
.
transfer_queue
.
get
()
failed
=
False
# simulate transfer delay of packet
# simulate transfer delay of packet
delay
=
packet
.
size
/
self
.
bandwidth
delay
=
packet
.
size
/
self
.
bandwidth
yield
self
.
env
.
timeout
(
delay
)
yield
self
.
env
.
timeout
(
delay
)
...
@@ -78,19 +96,44 @@ class Node(TickProcess):
...
@@ -78,19 +96,44 @@ class Node(TickProcess):
# simulates broadcast
# simulates broadcast
for
target
in
targets
:
for
target
in
targets
:
# try sending packet
# try sending packet
if
self
.
network
.
send_link
(
self
,
target
,
packet
):
if
self
.
send
(
target
,
packet
):
success
.
append
(
target
)
success
.
append
(
target
)
self
.
router
.
on_send_success
(
target
,
packet
)
self
.
router
.
on_send_success
(
target
,
packet
)
else
:
else
:
failed
=
True
self
.
router
.
on_send_failure
(
target
,
packet
)
self
.
router
.
on_send_failure
(
target
,
packet
)
packet
.
send
(
self
,
success
,
reason
=
reason
)
packet
.
send
(
self
,
success
,
reason
=
reason
)
if
failed
:
delete
=
self
.
route_packet
(
packet
)
if
delete
:
self
.
buffer
.
remove
(
packet
)
def
send
(
self
,
target
,
packet
):
'''
Instantly sends a packet to a target if they are connected.
Returns:
True - if successful
False - otherwise
'''
if
self
.
connected_to
(
target
):
return
target
.
recv
(
packet
)
else
:
return
False
def
recv
(
self
,
packet
):
def
recv
(
self
,
packet
):
'''
Tells the node to recieve a packet.
Returns:
True - if the node was able to recieved the packet.
False - otherwise, triggered by buffer being full.
'''
if
packet
.
destination
==
self
:
if
packet
.
destination
==
self
:
packet
.
recv
()
packet
.
recv
()
return
True
else
:
else
:
self
.
buffer
.
add
(
packet
)
return
self
.
buffer
.
add
(
packet
)
@property
@property
def
community
(
self
):
def
community
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment