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
7b55311a
Commit
7b55311a
authored
7 years ago
by
Jarrod Pas
Browse files
Options
Downloads
Patches
Plain Diff
Remove old main code
parent
bf192a7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!3
Version 0.2
,
!1
Full rewrite
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+0
-157
0 additions, 157 deletions
main.py
with
0 additions
and
157 deletions
main.py
deleted
100644 → 0
+
0
−
157
View file @
bf192a7e
from
argparse
import
ArgumentParser
from
datetime
import
datetime
import
random
import
sys
import
simpy
import
yaml
from
pydtn
import
Network
,
NodeFactory
from
pydtn.traces
import
types
as
traces
from
pydtn.routers
import
types
as
routers
from
pydtn.communities
import
types
as
communities
def
parse_args
(
args
):
parser
=
ArgumentParser
()
parser
.
add_argument
(
'
--seed
'
,
'
-s
'
,
metavar
=
'
seed
'
,
type
=
int
,
default
=
42
)
parser
.
add_argument
(
'
--trace
'
,
'
-t
'
,
metavar
=
'
type
'
,
default
=
'
random
'
,
choices
=
[
t
for
t
in
traces
])
parser
.
add_argument
(
'
--trace-args
'
,
'
-ta
'
,
metavar
=
'
arg
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
--router
'
,
'
-r
'
,
metavar
=
'
type
'
,
default
=
'
direct
'
,
choices
=
[
t
for
t
in
routers
])
parser
.
add_argument
(
'
--router-args
'
,
'
-ra
'
,
metavar
=
'
arg
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
--community
'
,
'
-c
'
,
metavar
=
'
type
'
,
default
=
'
none
'
,
choices
=
[
t
for
t
in
communities
])
parser
.
add_argument
(
'
--community-args
'
,
'
-ca
'
,
metavar
=
'
arg
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
--node-args
'
,
'
-na
'
,
metavar
=
'
arg
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
--packet-args
'
,
'
-pa
'
,
metavar
=
'
arg
'
,
nargs
=
'
+
'
)
def
list_to_args
(
args
):
if
args
is
None
:
return
{}
else
:
args
=
'
\n
'
.
join
(
args
).
replace
(
'
=
'
,
'
:
'
)
return
yaml
.
safe_load
(
args
)
args
=
parser
.
parse_args
(
args
)
args
.
trace_args
=
list_to_args
(
args
.
trace_args
)
args
.
router_args
=
list_to_args
(
args
.
router_args
)
args
.
community_args
=
list_to_args
(
args
.
community_args
)
args
.
node_args
=
list_to_args
(
args
.
node_args
)
args
.
packet_args
=
list_to_args
(
args
.
packet_args
)
return
args
class
Progress
:
def
__init__
(
self
,
length
,
ticks
,
alpha
):
self
.
length
=
length
self
.
alpha
=
alpha
self
.
tick
=
0
self
.
ticks
=
ticks
self
.
average
=
0
self
.
__start
=
None
self
.
__last_print_len
=
0
@property
def
bar
(
self
):
progress
=
round
(
self
.
tick
/
self
.
ticks
*
self
.
length
)
return
'
[
'
+
'
=
'
*
progress
+
'
'
*
(
self
.
length
-
progress
)
+
'
]
'
@property
def
time
(
self
):
remains
=
(
self
.
ticks
-
self
.
tick
)
*
self
.
average
ranges
=
[
(
'
day
'
,
24
*
60
*
60
),
(
'
hour
'
,
60
*
60
),
(
'
minute
'
,
60
),
(
'
second
'
,
1
),
]
for
unit
,
weight
in
ranges
:
if
remains
>=
weight
:
remains
=
round
(
remains
/
weight
)
plural
=
'
s
'
if
remains
!=
1
else
''
return
f
'
{
remains
}
{
unit
}{
plural
}
'
return
'
0 seconds
'
def
__next__
(
self
):
now
=
datetime
.
now
().
timestamp
()
if
self
.
__start
is
not
None
:
dt
=
now
-
self
.
__start
self
.
average
=
self
.
average
+
self
.
alpha
*
(
dt
-
self
.
average
)
self
.
__start
=
now
self
.
tick
+=
1
if
self
.
tick
>
self
.
ticks
:
raise
StopIteration
print
(
'
\r
'
+
'
'
*
self
.
__last_print_len
,
end
=
'
\r
'
)
line
=
f
'
{
self
.
bar
}
{
self
.
time
}
to go...
'
print
(
line
,
end
=
'
'
,
flush
=
True
)
self
.
__last_print_len
=
len
(
line
)
return
self
.
tick
def
__iter__
(
self
):
return
self
def
main
(
args
):
args
=
parse_args
(
args
)
print
(
args
)
out
=
{
'
seed
'
:
args
.
seed
,
'
router
'
:
args
.
router
,
'
community
'
:
args
.
community
,
}
if
args
.
trace
==
'
csv
'
:
out
[
'
trace
'
]
=
args
.
trace_args
[
'
path
'
]
for
k
,
v
in
out
.
items
():
print
(
f
'
{
k
}
:
{
v
}
'
)
random
.
seed
(
args
.
seed
)
env
=
simpy
.
Environment
()
trace
=
traces
[
args
.
trace
](
**
args
.
trace_args
)
router
=
routers
[
args
.
router
]
community
=
communities
[
args
.
community
](
**
args
.
community_args
)
node_factory
=
NodeFactory
(
router
,
**
args
.
node_args
)
network
=
Network
(
env
,
packets
=
args
.
packet_args
,
node_factory
=
node_factory
,
community
=
community
,
trace
=
trace
)
progress
=
Progress
(
50
,
500
,
0.75
)
while
True
:
try
:
for
tick
in
progress
:
until
=
tick
/
progress
.
ticks
*
trace
.
duration
env
.
run
(
until
=
until
)
print
(
'
Done!
'
)
print
(
str
(
network
.
packets
))
return
0
except
KeyboardInterrupt
:
print
(
'
\n
Bye!
'
)
return
0
if
__name__
==
'
__main__
'
:
exit
(
main
(
sys
.
argv
[
1
:]))
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