-
Notifications
You must be signed in to change notification settings - Fork 36
Description of SimpleHandler #21
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
Open
hghai14
wants to merge
2
commits into
codenet:main
Choose a base branch
from
hghai14:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SimpleHandler | ||
codenet marked this conversation as resolved.
Show resolved
Hide resolved
codenet marked this conversation as resolved.
Show resolved
Hide resolved
hghai14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
codenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
**File Path** - vmm-reference/src/devices/src/virtio/net/simple_handler.rs | ||
|
||
SimpleHandler object maintains a pair of queue `RX/TX`. These queues would be used for packets transfer(communication) between VM and `net` device. These queues facilitate in MMIO between guest and devices. | ||
|
||
SimpleHandler is used in the `QueueHandler` in the net device. | ||
|
||
```rs | ||
pub struct SimpleHandler<M: GuestAddressSpace, S: SignalUsedQueue> { | ||
pub driver_notify: S, | ||
pub rxq: Queue<M>, | ||
pub rxbuf_current: usize, | ||
pub rxbuf: [u8; MAX_BUFFER_SIZE], | ||
pub txq: Queue<M>, | ||
pub txbuf: [u8; MAX_BUFFER_SIZE], | ||
pub tap: Tap, | ||
} | ||
``` | ||
- `driver_notify` gets an instance of `SingleFdSignalQueue` which is used in notification to driver about the used queue events. | ||
- `rxq`(for receiving) and `txq`(for transmiting) are instances of rust's `Queue` which is present in the [virtio-queue](https://github.com/rust-vmm/vm-virtio/blob/main/crates/virtio-queue/README.md) interface. It consist of Descriptor tables, Available Ring, Used Ring. Descriptor contains information of length and address of buffer in the guest address space. | ||
- `tap` is an interface which provides virtual machines access to physical network. | ||
|
||
`iter` method of `Queue` consumes over all descriptor heads in queue to return a chain. `DescriptorChain` can be used to parse descriptors provided by the device, which represent input or output memory areas for device I/O. | ||
|
||
## Methods | ||
```rs | ||
pub fn process_rxq(&mut self) -> result::Result<(), Error> | ||
``` | ||
This method invokes `process_tap` methods on self. | ||
<hr> | ||
|
||
```rs | ||
pub fn process_tap(&mut self) -> result::Result<(), Error> | ||
``` | ||
This method reads frames from the tap into the `rxbuf` of simple_handler object. | ||
<hr> | ||
|
||
```rs | ||
fn write_frame_to_guest(&mut self) -> result::Result<bool, Error> | ||
``` | ||
This method is invoked in `process_tap` method. It iters over the `rxq` to check for descriptors for receving. If found any, frames from `rxbuf` are written to the address space specified by descriptors in the `DescriptionChain`. | ||
<hr> | ||
|
||
```rs | ||
pub fn process_txq(&mut self) -> result::Result<(), Error> | ||
``` | ||
For transmission, it gets the descriptors chain by iterating over the `txq`. Here the descriptors points the address space containing the frames that needs to be transmitted. It then calls `send_frame_from_chain` | ||
<hr> | ||
|
||
```rs | ||
fn send_frame_from_chain( | ||
&mut self, | ||
chain: &mut DescriptorChain<M::T>, | ||
) -> result::Result<u32, Error> | ||
``` | ||
It iterates over chain to read data from guest address space into `txbuf`. Using `txbuf` it further writes data into the tap device. | ||
<hr> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can replace hr with markdown syntax for lines. To create a horizontal rule, use three or more asterisks (***), dashes (---), or underscores (___) on a line by themselves. |
||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.