Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement L2 learning to avoid flooding #1

Open
AkihiroSuda opened this issue May 10, 2022 · 0 comments
Open

Implement L2 learning to avoid flooding #1

AkihiroSuda opened this issue May 10, 2022 · 0 comments
Labels
enhancement New feature or request kind/performance

Comments

@AkihiroSuda
Copy link
Member

AkihiroSuda commented May 10, 2022

socket_vmnet should learn the MAC addresses of the VMs, set the MAC addresses to the struct conn objects, and avoid flooding when possible.

socket_vmnet/main.c

Lines 85 to 89 in 8b16e51

struct conn {
// TODO: uint8_t mac[6];
int socket_fd;
struct conn *next;
} _conn;

socket_vmnet/main.c

Lines 180 to 205 in 8b16e51

for (struct conn *conn = conns; conn != NULL; conn = conn->next) {
// FIXME: avoid flooding
DEBUGF("[Handler i=%d] Sending to the socket %d: 4 + %ld bytes [Dest "
"%02X:%02X:%02X:%02X:%02X:%02X]",
i, conn->socket_fd, pdv[i].vm_pkt_size, dest_mac[0], dest_mac[1],
dest_mac[2], dest_mac[3], dest_mac[4], dest_mac[5]);
uint32_t header_be = htonl(pdv[i].vm_pkt_size);
struct iovec iov[2] = {
{
.iov_base = &header_be,
.iov_len = 4,
},
{
.iov_base = pdv[i].vm_pkt_iov[0].iov_base,
.iov_len = pdv[i].vm_pkt_size, // not vm_pkt_iov[0].iov_len
},
};
ssize_t written = writev(conn->socket_fd, iov, 2);
DEBUGF("[Handler i=%d] Sent to the socket: %ld bytes (including uint32be "
"header)",
i, written);
if (written < 0) {
perror("writev");
goto done;
}
}

socket_vmnet/main.c

Lines 512 to 542 in 8b16e51

// Flood the packet to other VMs in the same network too.
// (Not handled by vmnet)
// FIXME: avoid flooding
dispatch_semaphore_wait(state->sem, DISPATCH_TIME_FOREVER);
struct conn *conns = state->conns;
dispatch_semaphore_signal(state->sem);
for (struct conn *conn = conns; conn != NULL; conn = conn->next) {
if (conn->socket_fd == accept_fd)
continue;
DEBUGF("[Socket-to-Socket i=%lld] Sending from socket %d to socket %d: "
"4 + %d bytes",
i, accept_fd, conn->socket_fd, header);
struct iovec iov[2] = {
{
.iov_base = &header_be,
.iov_len = 4,
},
{
.iov_base = buf,
.iov_len = header,
},
};
ssize_t written = writev(conn->socket_fd, iov, 2);
DEBUGF("[Socket-to-Socket i=%lld] Sent from socket %d to socket %d: %ld "
"bytes (including uint32be header)",
i, accept_fd, conn->socket_fd, written);
if (written < 0) {
perror("writev");
continue;
}
}

@AkihiroSuda AkihiroSuda added enhancement New feature or request kind/performance labels May 10, 2022
@AkihiroSuda AkihiroSuda pinned this issue Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kind/performance
Projects
None yet
Development

No branches or pull requests

1 participant