Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
2b338a53
Commit
2b338a53
authored
Dec 14, 2016
by
Marc Schiller
Browse files
Finished ModelBased Database.
parent
39271d13
Changes
3
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java
View file @
2b338a53
...
...
@@ -26,14 +26,17 @@ import java.util.HashSet;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.models.AbstractModel
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.models.Direction
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.models.ParameterType
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
public
class
ModelBasedSegmentDatabase
extends
AbstractGridBasedTopologyDatabase
{
public
class
ModelBasedSegmentDatabase
extends
AbstractGridBasedTopologyDatabase
{
final
Integer
DEFAULT_SEGMENT_ID
=
new
Integer
(-
1
);
HashMap
<
ParameterType
,
HashMap
<
Integer
,
AbstractModel
>>
models
=
new
HashMap
<>();
// Models[Type][SegID][Up/Down/Both]
HashMap
<
ParameterType
,
HashMap
<
Integer
,
HashMap
<
Direction
,
AbstractModel
>>>
models
=
new
HashMap
<>();
public
ModelBasedSegmentDatabase
()
{
super
(
100
,
true
);
...
...
@@ -52,21 +55,90 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
"Model is not defined for any Parameter Type. Please specify the Type for this Model."
);
}
Direction
dir
=
model
.
getDirection
();
if
(
dir
==
null
)
{
throw
new
ConfigurationException
(
"Model is not defined for any Direction. Please specify the Direction for this Model."
);
}
Integer
segmentID
=
new
Integer
(
model
.
getSegmentID
());
if
(
models
.
containsKey
(
type
))
{
// There is already this Type
if
(
models
.
get
(
type
).
containsKey
(
segmentID
))
{
// There is already this SegID
if
(
models
.
get
(
type
).
get
(
segmentID
).
containsKey
(
dir
)
||
(
dir
.
equals
(
Direction
.
BOTH
)
&&
(
models
.
get
(
type
)
.
get
(
segmentID
).
containsKey
(
Direction
.
UPLOAD
)
||
models
.
get
(
type
).
get
(
segmentID
)
.
containsKey
(
Direction
.
DOWNLOAD
))))
{
// There is already a model defined
throw
new
ConfigurationException
(
"Conflicting models for "
+
type
.
toString
()
+
" and SegementID "
+
segmentID
.
toString
());
"Conflicting Models for SegmentID "
+
segmentID
+
", Type "
+
type
.
toString
()
+
" and Direction "
+
dir
.
toString
());
}
else
{
// Add new model
models
.
get
(
type
).
get
(
segmentID
).
put
(
dir
,
model
);
}
}
else
{
models
.
get
(
type
).
put
(
segmentID
,
model
);
// Add new SegmentID
// Direction => Model
HashMap
<
Direction
,
AbstractModel
>
tmp1
=
new
HashMap
<>();
tmp1
.
put
(
dir
,
model
);
models
.
get
(
type
).
put
(
segmentID
,
tmp1
);
}
}
else
{
HashMap
<
Integer
,
AbstractModel
>
tmp
=
new
HashMap
<>();
tmp
.
put
(
segmentID
,
model
);
models
.
put
(
type
,
tmp
);
// Add new model
// Direction => Model
HashMap
<
Direction
,
AbstractModel
>
tmp1
=
new
HashMap
<>();
tmp1
.
put
(
dir
,
model
);
// SegID => [Direction => Model]
HashMap
<
Integer
,
HashMap
<
Direction
,
AbstractModel
>>
tmp2
=
new
HashMap
<>();
tmp2
.
put
(
segmentID
,
tmp1
);
models
.
put
(
type
,
tmp2
);
}
}
AbstractModel
getModel
(
int
segID
,
ParameterType
type
,
Boolean
isUpload
)
{
Integer
segmentID
=
new
Integer
(
segID
);
if
(!
this
.
models
.
containsKey
(
type
))
{
throw
new
ConfigurationException
(
"No Model is defined for "
+
type
+
"."
);
}
if
(!
this
.
models
.
get
(
type
).
containsKey
(
segmentID
))
{
segmentID
=
DEFAULT_SEGMENT_ID
;
}
if
(!
this
.
models
.
get
(
type
).
containsKey
(
segmentID
))
{
throw
new
ConfigurationException
(
"No Model is defined for Type "
+
type
+
" and Segment ID "
+
segmentID
+
"."
);
}
Direction
dir
=
Direction
.
DOWNLOAD
;
if
(
isUpload
)
{
dir
=
Direction
.
UPLOAD
;
}
if
(!
this
.
models
.
get
(
type
).
get
(
segmentID
).
containsKey
(
dir
))
{
dir
=
Direction
.
BOTH
;
}
if
(!
this
.
models
.
get
(
type
).
get
(
segmentID
).
containsKey
(
dir
))
{
throw
new
ConfigurationException
(
"No Model is defined for Type "
+
type
+
", Segment ID "
+
segmentID
+
" and Direction "
+
dir
+
"."
);
}
return
this
.
models
.
get
(
type
).
get
(
segmentID
).
get
(
dir
);
}
public
class
ModelBasedEntry
implements
FiveGTopologyDatabase
.
Entry
{
...
...
@@ -88,12 +160,10 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
public
void
onHostLeavesSegment
(
MacAddress
hostAddr
)
{
this
.
hostsInSegment
.
remove
(
hostAddr
);
System
.
out
.
println
(
this
.
segment
+
": "
+
this
.
hostsInSegment
.
size
());
}
public
void
onHostEntersSegment
(
MacAddress
hostAddr
)
{
this
.
hostsInSegment
.
add
(
hostAddr
);
System
.
out
.
println
(
this
.
segment
+
": "
+
this
.
hostsInSegment
.
size
());
}
@Override
...
...
@@ -101,23 +171,9 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
if
(!
isAvailable
)
{
return
1
;
}
// TODO Up / Download?
Integer
segmentID
=
new
Integer
(
getSegmentID
());
int
usersInSegment
=
this
.
hostsInSegment
.
size
();
// Is there a Model for Droprate?
if
(
models
.
containsKey
(
ParameterType
.
DROPRATE
))
{
// Is there a specific model for this segment
if
(
models
.
get
(
ParameterType
.
DROPRATE
).
containsKey
(
segmentID
))
{
return
models
.
get
(
ParameterType
.
DROPRATE
).
get
(
segmentID
).
getDouble
(
usersInSegment
);
}
else
{
return
models
.
get
(
ParameterType
.
DROPRATE
).
get
(
DEFAULT_SEGMENT_ID
).
getDouble
(
usersInSegment
);
}
}
else
{
throw
new
ConfigurationException
(
"No Model is defined for Droprate."
);
}
return
getModel
(
new
Integer
(
getSegmentID
()),
ParameterType
.
DROPRATE
,
isUpload
)
.
getDouble
(
this
.
hostsInSegment
.
size
());
}
@Override
...
...
@@ -125,8 +181,9 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
if
(!
isAvailable
)
{
return
9999
*
Time
.
MILLISECOND
;
}
// TODO Return Latency based on Model
return
0
;
return
getModel
(
new
Integer
(
getSegmentID
()),
ParameterType
.
LATENCY
,
isUpload
)
.
getLong
(
this
.
hostsInSegment
.
size
());
}
@Override
...
...
@@ -134,8 +191,9 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
if
(!
isAvailable
)
{
return
0
;
}
// TODO Return Bandwidth based on Model
return
0
;
return
getModel
(
new
Integer
(
getSegmentID
()),
ParameterType
.
BANDWIDTH
,
isUpload
)
.
getLong
(
this
.
hostsInSegment
.
size
());
}
@Override
...
...
src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java
View file @
2b338a53
...
...
@@ -27,6 +27,8 @@ public abstract class AbstractModel {
private
ParameterType
type
;
private
Direction
dir
=
Direction
.
BOTH
;
public
void
setSegmentID
(
int
segmentid
)
{
assert
segmentid
>
0
;
this
.
segmentID
=
segmentid
;
...
...
@@ -56,6 +58,26 @@ public abstract class AbstractModel {
return
type
;
}
public
void
setDirection
(
String
param
)
{
param
=
param
.
toUpperCase
();
try
{
this
.
dir
=
Direction
.
valueOf
(
param
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
ConfigurationException
(
"Direction "
+
param
+
" is unknown. Please select one of "
+
Direction
.
printTypes
());
}
if
(
this
.
type
==
null
)
{
throw
new
ConfigurationException
(
"Direction "
+
param
+
" is unknown. Please select one of "
+
Direction
.
printTypes
());
}
}
public
Direction
getDirection
()
{
return
dir
;
}
public
abstract
long
getLong
(
int
users
);
public
abstract
double
getDouble
(
int
users
);
...
...
src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/Direction.java
0 → 100644
View file @
2b338a53
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.topology.views.fiveg.models
;
public
enum
Direction
{
BOTH
(),
UPLOAD
(),
DOWNLOAD
();
public
static
String
printTypes
()
{
Direction
[]
types
=
values
();
String
out
=
""
;
for
(
int
i
=
0
;
i
<
types
.
length
;
i
++)
{
if
(
i
>
0
)
{
out
+=
", "
;
}
out
+=
types
[
i
].
name
();
}
return
out
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment