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
ycai
simbricks
Commits
86d70837
Commit
86d70837
authored
Oct 02, 2022
by
GAO Bin
Browse files
mem_switch: add address translation in switch
parent
0db9a96c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
21 deletions
+75
-21
experiments/pyexps/memswitch.py
experiments/pyexps/memswitch.py
+25
-12
sims/net/mem_switch/mem_switch
sims/net/mem_switch/mem_switch
+0
-0
sims/net/mem_switch/mem_switch.cc
sims/net/mem_switch/mem_switch.cc
+50
-9
No files found.
experiments/pyexps/memswitch.py
View file @
86d70837
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from
click
import
command
import
simbricks.orchestration.experiments
as
exp
import
simbricks.orchestration.experiments
as
exp
import
simbricks.orchestration.nodeconfig
as
node
import
simbricks.orchestration.nodeconfig
as
node
import
simbricks.orchestration.simulators
as
sim
import
simbricks.orchestration.simulators
as
sim
...
@@ -28,17 +29,20 @@ experiments = []
...
@@ -28,17 +29,20 @@ experiments = []
num_of_netmem
=
[
1
,
2
,
3
,
4
]
num_of_netmem
=
[
1
,
2
,
3
,
4
]
class
MemTest
(
node
.
AppConfig
):
class
MemTest
(
node
.
AppConfig
):
def
__init__
(
self
,
addr
):
def
__init__
(
self
):
self
.
addr
=
addr
self
.
addr
=
[]
def
run_cmds
(
self
,
node
):
def
run_cmds
(
self
,
node
):
return
[
commands
=
[]
f
'busybox devmem 0x
{
self
.
addr
:
x
}
64 0x42'
,
for
addr
in
self
.
addr
:
f
'busybox devmem 0x
{
self
.
addr
:
x
}
64'
commands
.
append
(
f
'busybox devmem 0x
{
addr
:
x
}
64 0x42'
)
]
commands
.
append
(
f
'busybox devmem 0x
{
addr
:
x
}
64'
)
return
commands
# AS_ID,VADDR_START(include),VADDR_END(not include),MEMNODE_MAC,PHYS_START
# AS_ID,VADDR_START(include),VADDR_END(not include),MEMNODE_MAC,PHYS_START
sw_mem_map
=
[(
0
,
0
,
1073741824
,
'00:00:00:00:00:02'
,
0
)]
sw_mem_map
=
[(
0
,
0
,
1024
*
1024
*
1024
,
'00:00:00:00:00:02'
,
0
),
(
0
,
1024
*
1024
*
1024
,
1024
*
1024
*
1024
*
2
,
'00:00:00:00:00:03'
,
1024
*
1024
*
1024
)]
for
h
in
[
'gk'
]:
for
h
in
[
'gk'
]:
e
=
exp
.
Experiment
(
'memsw-'
+
h
)
e
=
exp
.
Experiment
(
'memsw-'
+
h
)
...
@@ -49,13 +53,21 @@ for h in ['gk']:
...
@@ -49,13 +53,21 @@ for h in ['gk']:
mem
.
addr
=
0x2000000000
#0x2000000000000000
mem
.
addr
=
0x2000000000
#0x2000000000000000
mem
.
mac
=
'00:00:00:00:00:01'
mem
.
mac
=
'00:00:00:00:00:01'
netmem
=
sim
.
NetMem
()
netmem1
=
sim
.
NetMem
()
netmem
.
mac
=
'00:00:00:00:00:02'
netmem1
.
mac
=
'00:00:00:00:00:02'
netmem1
.
name
=
'netmem1'
netmem2
=
sim
.
NetMem
()
netmem2
.
mac
=
'00:00:00:00:00:03'
netmem2
.
name
=
'netmem2'
netmem2
.
addr
=
mem
.
addr
+
netmem1
.
size
node_config
=
node
.
NodeConfig
()
node_config
=
node
.
NodeConfig
()
node_config
.
nockp
=
True
node_config
.
nockp
=
True
node_config
.
app
=
MemTest
(
mem
.
addr
)
node_config
.
app
=
MemTest
()
node_config
.
app
.
addr
.
append
(
mem
.
addr
)
node_config
.
app
.
addr
.
append
(
mem
.
addr
+
netmem1
.
size
)
net
=
sim
.
MemSwitchNet
()
net
=
sim
.
MemSwitchNet
()
for
tp
in
sw_mem_map
:
for
tp
in
sw_mem_map
:
...
@@ -74,7 +86,8 @@ for h in ['gk']:
...
@@ -74,7 +86,8 @@ for h in ['gk']:
host
.
wait
=
True
host
.
wait
=
True
mem
.
set_network
(
net
)
mem
.
set_network
(
net
)
netmem
.
set_network
(
net
)
netmem1
.
set_network
(
net
)
netmem2
.
set_network
(
net
);
e
.
add_memdev
(
mem
)
e
.
add_memdev
(
mem
)
host
.
add_memdev
(
mem
)
host
.
add_memdev
(
mem
)
...
...
sims/net/mem_switch/mem_switch
deleted
100755 → 0
View file @
0db9a96c
File deleted
sims/net/mem_switch/mem_switch.cc
View file @
86d70837
...
@@ -42,9 +42,10 @@
...
@@ -42,9 +42,10 @@
extern
"C"
{
extern
"C"
{
#include <simbricks/network/if.h>
#include <simbricks/network/if.h>
#include <simbricks/nicif/nicif.h>
#include <simbricks/nicif/nicif.h>
#include <simbricks/mem/memop.h>
};
};
//
#define NETSWITCH_DEBUG
#define NETSWITCH_DEBUG
#define NETSWITCH_STAT
#define NETSWITCH_STAT
struct
SimbricksBaseIfParams
netParams
;
struct
SimbricksBaseIfParams
netParams
;
...
@@ -71,7 +72,7 @@ union ether_addr
...
@@ -71,7 +72,7 @@ union ether_addr
}
__attribute__
((
__packed__
));
}
__attribute__
((
__packed__
));
struct
table_entry
{
struct
table_entry
{
int
as_id
;
u
int
64_t
as_id
;
uint64_t
vaddr_start
;
uint64_t
vaddr_start
;
uint64_t
vaddr_end
;
uint64_t
vaddr_end
;
union
ether_addr
node_mac
;
union
ether_addr
node_mac
;
...
@@ -96,6 +97,11 @@ struct MAC {
...
@@ -96,6 +97,11 @@ struct MAC {
}
}
return
true
;
return
true
;
}
}
MAC
operator
=
(
const
uint8_t
*
other
)
const
{
MAC
mac
(
other
);
return
mac
;
}
};
};
namespace
std
{
namespace
std
{
template
<
>
template
<
>
...
@@ -394,9 +400,11 @@ static void switch_pkt(NetPort &port, size_t iport) {
...
@@ -394,9 +400,11 @@ static void switch_pkt(NetPort &port, size_t iport) {
// Get MAC addresses
// Get MAC addresses
MAC
dst
((
const
uint8_t
*
)
pkt_data
),
src
((
const
uint8_t
*
)
pkt_data
+
6
);
MAC
dst
((
const
uint8_t
*
)
pkt_data
),
src
((
const
uint8_t
*
)
pkt_data
+
6
);
// MAC learning
// MAC learning
if
(
!
(
src
==
bcast_addr
))
{
if
(
!
(
src
==
bcast_addr
))
{
mac_table
[
src
]
=
iport
;
mac_table
[
src
]
=
iport
;
}
}
// L2 forwarding
// L2 forwarding
auto
i
=
mac_table
.
find
(
dst
);
auto
i
=
mac_table
.
find
(
dst
);
if
(
i
!=
mac_table
.
end
())
{
if
(
i
!=
mac_table
.
end
())
{
...
@@ -405,6 +413,30 @@ static void switch_pkt(NetPort &port, size_t iport) {
...
@@ -405,6 +413,30 @@ static void switch_pkt(NetPort &port, size_t iport) {
forward_pkt
(
pkt_data
,
pkt_len
,
eport
,
iport
);
forward_pkt
(
pkt_data
,
pkt_len
,
eport
,
iport
);
}
else
{
}
else
{
// Broadcast
// Broadcast
struct
ethhdr
*
eth_hdr
=
(
struct
ethhdr
*
)
pkt_data
;
struct
MemOp
*
memop
=
(
struct
MemOp
*
)(((
const
uint8_t
*
)
pkt_data
)
+
42
);
for
(
size_t
i
=
0
;
i
<
map_table
.
size
();
i
++
)
{
if
(
memop
->
as_id
==
map_table
[
i
].
as_id
&&
memop
->
addr
>=
map_table
[
i
].
vaddr_start
&&
memop
->
addr
<=
map_table
[
i
].
vaddr_end
){
for
(
int
k
=
0
;
k
<
ETH_ALEN
;
k
++
){
eth_hdr
->
h_dest
[
k
]
=
map_table
[
i
].
node_mac
.
ether_addr_octet
[
k
];
}
dst
=
eth_hdr
->
h_dest
;
auto
k
=
mac_table
.
find
(
dst
);
if
(
k
!=
mac_table
.
end
())
{
size_t
eport
=
k
->
second
;
if
(
eport
!=
iport
){
#ifdef NETSWITCH_DEBUG
printf
(
"Forwarding memop to netmem"
);
#endif
forward_pkt
(
pkt_data
,
pkt_len
,
eport
,
iport
);
}
}
else
{
#ifdef NETSWITCH_DEBUG
printf
(
"Dest netmem is not in the mac table, broadcast first
\n
"
);
#endif
for
(
size_t
eport
=
0
;
eport
<
ports
.
size
();
eport
++
)
{
for
(
size_t
eport
=
0
;
eport
<
ports
.
size
();
eport
++
)
{
if
(
eport
!=
iport
)
{
if
(
eport
!=
iport
)
{
// Do not forward to ingress port
// Do not forward to ingress port
...
@@ -412,6 +444,14 @@ static void switch_pkt(NetPort &port, size_t iport) {
...
@@ -412,6 +444,14 @@ static void switch_pkt(NetPort &port, size_t iport) {
}
}
}
}
}
}
break
;
}
if
(
i
==
map_table
.
size
()
-
1
)
{
fprintf
(
stderr
,
"Dest netmem is unavaliable."
);
}
}
}
}
else
if
(
poll
==
NetPort
::
kRxPollSync
)
{
}
else
if
(
poll
==
NetPort
::
kRxPollSync
)
{
#ifdef NETSWITCH_STAT
#ifdef NETSWITCH_STAT
d2n_poll_sync
+=
1
;
d2n_poll_sync
+=
1
;
...
@@ -503,9 +543,10 @@ int main(int argc, char *argv[]) {
...
@@ -503,9 +543,10 @@ int main(int argc, char *argv[]) {
token
=
strtok
(
NULL
,
","
);
token
=
strtok
(
NULL
,
","
);
}
}
printf
(
"as_id: %d vaddr_start: %lu vadd_end: %lu phys_start: %lu
\n
"
,
ent
.
as_id
,
ent
.
vaddr_start
,
ent
.
vaddr_end
,
ent
.
phys_start
);
#ifdef NETSWITCH_DEBUG
printf
(
"as_id: %lu vaddr_start: %lu vadd_end: %lu phys_start: %lu
\n
"
,
ent
.
as_id
,
ent
.
vaddr_start
,
ent
.
vaddr_end
,
ent
.
phys_start
);
printf
(
"mac_byte: %lx
\n
"
,
ent
.
node_mac
.
ether_addr_64
);
printf
(
"mac_byte: %lx
\n
"
,
ent
.
node_mac
.
ether_addr_64
);
#endif
map_table
.
push_back
(
ent
);
map_table
.
push_back
(
ent
);
break
;
break
;
...
...
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