Add a four-octet tag to a frame and take one away. Keep every frame legal: the right place, the right size and a fresh FCS.
Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.
A switch port adds a tag to frames going out on a trunk and removes it from frames coming in. Each change rewrites the frame.
Write vlan_insert and vlan_strip. Both take a whole frame with its FCS and return a whole frame with a correct FCS.
The tag is four octets: a tag EtherType tpid, then two octets of tag control tci, high octet first. Treat both as plain numbers here.
The FCS is computed for you by eth_fcs(f, k). Your job is the place, the size and what the FCS covers.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [1039:0] vlan_insert(input [1023:0] f, input int n, input [15:0] tpid, input [15:0] tci);
function automatic [1039:0] vlan_strip(input [1023:0] f, input int n, input [15:0] tpid);
// both return {n_out[15:0], frame[1023:0]}; octet k is frame[8*k +: 8]
function automatic [31:0] eth_fcs(input [1023:0] f, input int k); // given: FCS of octets 0..k-1, first octet in [7:0]
| Function | Rule |
|---|---|
vlan_insert | The four tag octets go right after the source address, before the Length/Type field. Every other octet keeps its order, pad included. A new FCS follows. |
vlan_strip | Only when octets 12 and 13 equal tpid: remove octets 12 to 15. If fewer than 60 octets remain, add zero octets up to 60. A new FCS follows. |
vlan_strip, no tag | Return the frame unchanged. |
| Both | Octets at and above n_out are zero. |
Inputs are 64 to 120 octets long and always carry a correct FCS.
Examples
Example 1
Tag a Minimum Frame- Input
a 64-octet frame
- Output
fcs = 0xba3dafa5, octets_12_to_15 = 0x81002064, frame_octets = 68
The frame grows to 68 octets. Octets 12 to 15 are the tag, and the FCS is new.
Example 2
Tag a Padded Frame- Input
10 data octets, 36 pad octets
- Output
fcs = 0x5e73cc8, octets_12_to_15 = 0x81000005, frame_octets = 68
The pad moves along with the data. Nothing else changes but the tag and the FCS.
Example 3
Strip from 64 Octets- Input
a tagged frame of 64 octets
- Output
fcs = 0xaf48e735, octets_12_to_15 = 0x8003031, frame_octets = 64
Removing the tag leaves 60 octets with the FCS. Four zero octets bring it back to 64.
Constraints and Contract
- Keep both function names, their arguments and their result widths.
- Do not rewrite
eth_fcs. - Field meanings of the tag belong to IEEE 802.1Q and are not graded.
- Off limits: the names
rng,tb,root, names that begin withfx_and the modules of the bench.
Hints
Hint 1
Which octets of the old frame must not reach the new one?
Hint 2
Write the new frame through a fresh vector, octet by octet. Shifting in place is where most bugs hide.
Hint 3
After a strip, how short can the frame get? What is the shortest legal frame?
What the grader checks: The fixture checks six literal cases against an independent model with zlib.crc32. It checks 260 random frames against the same model, through a digest of each whole result. Tag field meanings (priority, VLAN number) belong to IEEE 802.1Q and are not tested.
10 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone