Skip to content

[sled-agent] Add ability to allocate guest-visible NICs#186

Merged
smklein merged 42 commits into
mainfrom
pass-nics-and-use-em
Sep 7, 2021
Merged

[sled-agent] Add ability to allocate guest-visible NICs#186
smklein merged 42 commits into
mainfrom
pass-nics-and-use-em

Conversation

@smklein

@smklein smklein commented Aug 4, 2021

Copy link
Copy Markdown
Collaborator

[Nexus]

  • Expands "InstanceRuntimeState" into "InstanceHardware", such that it also includes space for devices (to start with, NICs).

[Sled Agent]

  • Adds a Vnic structure, which uses RAII semantics to deallocate the VNIC when it goes out of scope.
  • Constructs VNICs as requested by Nexus, places them in Propolis' Zone, and requests them from Propolis' API.

At the moment, this PR does not actually request NICs from Nexus -> Sled Agent -> Propolis -- but the wiring is added such that this is now possible, if requested by Nexus

bnaecker and others added 30 commits July 19, 2021 12:11
- Adds the `VPC`, `VPCSubnet` and `VNIC` types, including internal
control plane representations, client views, and database types.
- Implements some required traits for generating JSON schema and
serializing to/from PostgreSQL wire formats. Note that the MAC address
type is serialized in the database as a string, as CockroachDB doesn't
currently support the PostgreSQL MACADDR type.
Base automatically changed from instance-hw to main September 1, 2021 17:47
@smklein smklein requested a review from bnaecker September 1, 2021 22:01
@smklein smklein marked this pull request as ready for review September 1, 2021 22:01
@smklein smklein changed the title Pass nics and use em [sled-agent] Add ability to allocate guest-visible NICs Sep 1, 2021
@jclulow

jclulow commented Sep 3, 2021

Copy link
Copy Markdown
Collaborator

I think we must have exercised this stuff during the demo? At least in some form.

/*
* XXX Demo hack NIC.
*/
let mac = macaddr::MacAddr6::new(
0xaa,
0x00,
0x04,
0x00,
0xff,
ip_reservation as u8,
);
let nic = omicron_common::api::external::NetworkInterface {
mac: omicron_common::api::external::MacAddr(mac),
ip: format!("172.20.14.{}", ip_reservation).parse().unwrap(),
subnet_id: Uuid::new_v4(),
vpc_id: Uuid::new_v4(),
identity: omicron_common::api::external::IdentityMetadata {
id: Uuid::new_v4(),
name: omicron_common::api::external::Name::try_from(
"bestvnic".to_string(),
)
.unwrap(),
description: "".to_string(),
time_created: Utc::now(),
time_modified: Utc::now(),
},
};
// TODO: Populate this with an appropriate NIC.
// See also: instance_set_runtime in nexus.rs for a similar construction.
Ok(InstanceHardware {
runtime: instance.runtime().into(),
nics: vec![nic],

This created the right NICs, at least!

I wonder if we could add, at least for now, the ability to have the guest NIC be on a VLAN (which could just come from the config file) for the lab environment:

/// Creates a new VNIC atop a physical device.
pub fn create_vnic(
physical: &PhysicalLink,
vnic_name: &str,
mac: Option<MacAddr>,
vlan: Option<u16>,
) -> Result<(), Error> {
let mut command = std::process::Command::new(PFEXEC);
let mut args = vec![
DLADM.to_string(),
"create-vnic".to_string(),
"-t".to_string(),
"-l".to_string(),
physical.0.to_string(),
];
if let Some(mac) = mac {
args.push("-m".to_string());
args.push(mac.0.to_string());
}
if let Some(vlan) = vlan {
args.push("-v".to_string());
args.push(vlan.to_string());
}
args.push(vnic_name.to_string());
let cmd = command.args(&args);
execute(cmd)?;
Ok(())
}

impl Vnic {
// Creates a new NIC, intended for usage by the guest.
fn new_guest(
allocator: &IdAllocator,
physical_dl: &PhysicalLink,
mac: Option<MacAddr>,
) -> Result<Self, Error> {
let name = guest_vnic_name(allocator.next());
Dladm::create_vnic(physical_dl, &name, mac, Some(2014))?; /* XXX */
Ok(Vnic { name, deleted: false })
}

@smklein

smklein commented Sep 7, 2021

Copy link
Copy Markdown
Collaborator Author

I think we must have exercised this stuff during the demo? At least in some form.
This created the right NICs, at least!

Yeah! I pulled this branch into demo_m2, so it was definitely used there.

I wonder if we could add, at least for now, the ability to have the guest NIC be on a VLAN (which could just come from the config file) for the lab environment

Sure thing! I just added the "--vlan" argument which can be plumbed into the sled agent (admittedly, so far, no one is passing this argument). Perhaps we could add it as an SMF property? Or somehow in the invocation in the service_bundle.dtd file?

Regardless, this has been added.

@smklein

smklein commented Sep 7, 2021

Copy link
Copy Markdown
Collaborator Author

This branch is ready to go, blocked on: oxidecomputer/propolis#43

@smklein smklein merged commit 63236de into main Sep 7, 2021
@smklein smklein deleted the pass-nics-and-use-em branch September 7, 2021 19:27
citrus-it pushed a commit to citrus-it/omicron that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants