Skip to content

Commit

Permalink
feat: configure guest iface address + rename vmm cli args (#35)
Browse files Browse the repository at this point in the history
* feat(virtio): Adding Virtio-net Support to Cloudlet (#22)

* feat(virtio): configure net device
- MMIO Device Discovery by the kernel command line
- irq allocator

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* feat: add simple handler

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* refactor code architecture about devices + add queue/handlers

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* chore: fix traits for generic + refactor code

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* feat: add working device

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* refactor: remove all unwrap

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* fix: cargo clippy

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* refactor: remove unnecessary comments

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

---------

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* feat: configure guest iface address + rename vmm cli args for better understanding

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

* Feat/grpc streams (#31)

* feat: streaming and pty setup

---------

Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr>
Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>

---------

Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr>
Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr>
Co-authored-by: Thomas Mauran <78204354+thomas-mauran@users.noreply.github.com>
Signed-off-by: ESPIE <remi.espie@etu.umontpellier.fr>
  • Loading branch information
2 people authored and remi-espie committed May 1, 2024
1 parent b47f929 commit 577670e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ run:
sudo -E capsh --keep=1 --user=$USER --inh=cap_net_admin --addamb=cap_net_admin -- -c \
'RUST_BACKTRACE=1 '$CARGO_PATH' run --bin vmm -- cli --memory 512 --cpus 1 \
--kernel tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \
--network-host-ip 172.29.0.1 --network-host-netmask 255.255.0.0 \
--iface-host-addr 172.29.0.1 --netmask 255.255.0.0 --iface-guest-addr 172.29.0.2 \
--initramfs=tools/rootfs/initramfs.img'

build-kernel:
Expand Down
10 changes: 7 additions & 3 deletions src/vmm/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ pub struct CliArguments {

/// IPv4 address of the host tap interface.
#[clap(long, env, required = true)]
pub network_host_ip: Ipv4Addr,
pub iface_host_addr: Ipv4Addr,

/// Subnet mask of the host tap interface.
/// Subnet mask for network.
#[clap(long, env, required = true)]
pub network_host_netmask: Ipv4Addr,
pub netmask: Ipv4Addr,

/// IPv4 address of the guest eth0 interface.
#[clap(long, env, required = true)]
pub iface_guest_addr: Ipv4Addr,

/// Verbosity level.
#[command(flatten)]
Expand Down
17 changes: 12 additions & 5 deletions src/vmm/src/core/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ impl Net {
mem: Arc<GuestMemoryMmap>,
device_mgr: Arc<Mutex<IoManager>>,
mmio_cfg: MmioConfig,
ip_addr: Ipv4Addr,
mask: Ipv4Addr,
tap_addr: Ipv4Addr,
netmask: Ipv4Addr,
iface_guest_addr: Ipv4Addr,
irq: u32,
endpoint: RemoteEndpoint<Subscriber>,
vm_fd: Arc<VmFd>,
Expand Down Expand Up @@ -73,7 +74,7 @@ impl Net {

// Set offload flags to match the relevant virtio features of the device (for now,
// statically set in the constructor.
let tap = open_tap(None, Some(ip_addr), Some(mask), &mut None, None, None)
let tap = open_tap(None, Some(tap_addr), Some(netmask), &mut None, None, None)
.map_err(Error::TunTap)?;

// The layout of the header is specified in the standard and is 12 bytes in size. We
Expand All @@ -87,9 +88,15 @@ impl Net {
tap: Arc::new(Mutex::new(tap)),
}));

let param = register_mmio_device(mmio_cfg, device_mgr, irq, None, net.clone())
let vmmio_param = register_mmio_device(mmio_cfg, device_mgr, irq, None, net.clone())
.map_err(Error::Virtio)?;
cmdline_extra_parameters.push(param);
let ip_pnp_param: String = format!(
"ip={}::{}:{}::eth0:off",
iface_guest_addr, tap_addr, netmask
);

cmdline_extra_parameters.push(vmmio_param);
cmdline_extra_parameters.push(ip_pnp_param);

Ok(net)
}
Expand Down
17 changes: 10 additions & 7 deletions src/vmm/src/core/vmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ pub struct VMM {
event_mgr: EventMgr,
vcpus: Vec<Vcpu>,

tap_ip_addr: Ipv4Addr,
tap_netmask: Ipv4Addr,
tap_addr: Ipv4Addr,
netmask: Ipv4Addr,
iface_guest_addr: Ipv4Addr,
net_devices: Vec<Arc<Mutex<Net>>>,
serial: Arc<Mutex<LumperSerial<Stdout>>>,
slip_pty: Arc<Mutex<SlipPty>>,
Expand All @@ -68,7 +69,7 @@ pub struct VMM {

impl VMM {
/// Create a new VMM.
pub fn new(tap_ip_addr: Ipv4Addr, tap_netmask: Ipv4Addr) -> Result<Self> {
pub fn new(tap_addr: Ipv4Addr, netmask: Ipv4Addr, iface_guest_addr: Ipv4Addr) -> Result<Self> {
// Open /dev/kvm and get a file descriptor to it.
let kvm = Kvm::new().map_err(Error::KvmIoctl)?;

Expand Down Expand Up @@ -110,8 +111,9 @@ impl VMM {
)),
slip_pty: Arc::new(Mutex::new(slip_pty)),
epoll,
tap_ip_addr,
tap_netmask,
tap_addr,
netmask,
iface_guest_addr,
net_devices: Vec::new(),
};

Expand Down Expand Up @@ -380,8 +382,9 @@ impl VMM {
mem,
self.device_mgr.clone(),
mmio_cfg,
self.tap_ip_addr,
self.tap_netmask,
self.tap_addr,
self.netmask,
self.iface_guest_addr,
irq,
self.event_mgr.lock().unwrap().remote_endpoint(),
self.vm_fd.clone(),
Expand Down
6 changes: 3 additions & 3 deletions src/vmm/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl VmmServiceTrait for VmmService {
let (tx, rx) = tokio::sync::mpsc::channel(4);

const HOST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 1);
const VM_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 2);
const HOST_NETMASK: Ipv4Addr = Ipv4Addr::new(255, 255, 0, 0);
const GUEST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 2);

// Check if the kernel is on the system, else build it
if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin")
Expand Down Expand Up @@ -77,7 +77,7 @@ impl VmmServiceTrait for VmmService {
initramfs_path.push("./tools/rootfs/initramfs.img");

// // Create a new VMM
let mut vmm = VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?;
let mut vmm = VMM::new(HOST_IP, HOST_NETMASK, GUEST_IP).map_err(VmmErrors::VmmNew)?;

// Configure the VMM parameters might need to be calculated rather than hardcoded
vmm.configure(1, 512, kernel_path, &Some(initramfs_path))
Expand All @@ -96,7 +96,7 @@ impl VmmServiceTrait for VmmService {
tokio::time::sleep(Duration::from_secs(2)).await;
println!("Connecting to Agent service");

WorkloadClient::new(VM_IP, 50051).await
WorkloadClient::new(GUEST_IP, 50051).await
})
.await
.unwrap();
Expand Down
10 changes: 7 additions & 3 deletions src/vmm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_max_level(cli_args.convert_log_to_tracing())
.init();
// Create a new VMM
let mut vmm = VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask)
.map_err(VmmErrors::VmmNew)
.unwrap();
let mut vmm = VMM::new(
cli_args.iface_host_addr,
cli_args.netmask,
cli_args.iface_guest_addr,
)
.map_err(VmmErrors::VmmNew)
.unwrap();

vmm.configure(
cli_args.cpus,
Expand Down

0 comments on commit 577670e

Please sign in to comment.