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
67681394
Commit
67681394
authored
Dec 05, 2016
by
Marc Schiller
Browse files
More advances in models.
parent
421a101d
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java
View file @
67681394
...
...
@@ -24,7 +24,10 @@ import java.util.HashMap;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.linklayer.mac.PhyType
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.impl.linklayer.ModularLinkLayer
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.models.AbstractModel
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.models.ParameterType
;
import
de.tud.kom.p2psim.impl.util.IncrementableHashMap
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
...
...
@@ -34,10 +37,14 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationLi
public
class
ModelBasedSegmentDatabase
extends
AbstractGridBasedTopologyDatabase
implements
LocationListener
{
final
Integer
DEFAULT_SEGMENT_ID
=
new
Integer
(-
1
);
private
HashMap
<
MacAddress
,
Integer
>
currentPositions
=
new
HashMap
<>();
private
IncrementableHashMap
<
Integer
>
segmentSize
=
new
IncrementableHashMap
<>();
IncrementableHashMap
<
Integer
>
usersPerSegment
=
new
IncrementableHashMap
<>();
HashMap
<
ParameterType
,
HashMap
<
Integer
,
AbstractModel
>>
models
=
new
HashMap
<>();
public
ModelBasedSegmentDatabase
()
{
super
(
100
,
true
);
...
...
@@ -50,6 +57,30 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
return
new
ModelBasedEntry
(
segmentID
);
}
public
void
setModel
(
AbstractModel
model
)
{
ParameterType
type
=
model
.
getParameterType
();
if
(
type
==
null
)
{
throw
new
ConfigurationException
(
"Model is not defined for any Parameter Type. Please specify the Type for this Model."
);
}
Integer
segmentID
=
new
Integer
(
model
.
getSegmentID
());
if
(
models
.
containsKey
(
type
))
{
if
(
models
.
get
(
type
).
containsKey
(
segmentID
))
{
throw
new
ConfigurationException
(
"Conflicting models for "
+
type
.
toString
()
+
" and SegementID "
+
segmentID
.
toString
());
}
else
{
models
.
get
(
type
).
put
(
segmentID
,
model
);
}
}
else
{
HashMap
<
Integer
,
AbstractModel
>
tmp
=
new
HashMap
<>();
tmp
.
put
(
segmentID
,
model
);
models
.
put
(
type
,
tmp
);
}
}
@Override
public
void
onLocationChanged
(
Host
host
,
Location
location
)
{
try
{
...
...
@@ -62,17 +93,16 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
if
(
currentPositions
.
containsKey
(
mac
))
{
Integer
oldSegmentID
=
currentPositions
.
get
(
mac
);
// Host changed segment
if
(
oldSegmentID
.
compareTo
(
segmentID
)
!=
0
)
{
segment
Size
.
decrement
(
oldSegmentID
);
segment
Size
.
increment
(
segmentID
);
if
(
oldSegmentID
.
compareTo
(
segmentID
)
!=
0
)
{
u
se
rsPerSe
gment
.
decrement
(
oldSegmentID
);
u
se
rsPerSe
gment
.
increment
(
segmentID
);
currentPositions
.
put
(
mac
,
segmentID
);
}
}
else
{
// New host
currentPositions
.
put
(
mac
,
segmentID
);
segment
Size
.
increment
(
segmentID
);
u
se
rsPerSe
gment
.
increment
(
segmentID
);
}
System
.
out
.
println
(
segmentSize
);
}
catch
(
ComponentNotAvailableException
e
)
{
// TODO Handle unknown host type
}
...
...
@@ -98,8 +128,23 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
if
(!
getConnectivity
())
{
return
1
;
}
// TODO Return Drop Probability based on Model
return
0
;
// TODO Up / Download?
Integer
segmentID
=
new
Integer
(
getSegmentID
());
int
usersInSegment
=
usersPerSegment
.
get
(
segmentID
);
// 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."
);
}
}
@Override
...
...
src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java
0 → 100644
View file @
67681394
/*
* 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
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
public
abstract
class
AbstractModel
{
private
int
segmentID
=
-
1
;
private
ParameterType
type
;
public
void
setSegmentID
(
int
segmentid
)
{
assert
segmentid
>
0
;
this
.
segmentID
=
segmentid
;
}
public
int
getSegmentID
()
{
return
this
.
segmentID
;
}
public
void
setParameterType
(
String
param
)
{
param
=
param
.
toUpperCase
();
try
{
this
.
type
=
ParameterType
.
valueOf
(
param
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
ConfigurationException
(
"The Parameter "
+
param
+
" is unknown. Please select one of "
+
ParameterType
.
printTypes
());
}
if
(
this
.
type
==
null
)
{
throw
new
ConfigurationException
(
"The Parameter "
+
param
+
" is unknown. Please select one of "
+
ParameterType
.
printTypes
());
}
}
public
ParameterType
getParameterType
()
{
return
type
;
}
public
abstract
long
getLong
(
int
users
);
public
abstract
double
getDouble
(
int
users
);
}
src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LinearModel.java
0 → 100644
View file @
67681394
/*
* 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
class
LinearModel
extends
AbstractModel
{
private
long
a
=
0
;
private
long
b
=
0
;
public
void
setA
(
long
a
)
{
this
.
a
=
a
;
}
public
void
setB
(
long
b
)
{
this
.
b
=
b
;
}
@Override
public
long
getLong
(
int
users
)
{
return
this
.
a
*
users
+
this
.
b
;
}
@Override
public
double
getDouble
(
int
users
)
{
return
(
double
)
this
.
a
*
users
+
this
.
b
;
}
}
src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ParameterType.java
0 → 100644
View file @
67681394
/*
* 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
ParameterType
{
BANDWIDTH
(),
DROPRATE
(),
LATENCY
();
public
static
String
printTypes
()
{
ParameterType
[]
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