# Incorrect parameter as register index in link\_monitor tutorial

**URL:** <https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243>\
**Category:** Getting Started with P4\
**Created:** [February 16, 2022, 4:29pm UTC](https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243 "2022-02-16T16:29:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sorosuh](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@sorosuh](https://forum.p4.org/u/sorosuh)\
**Post date:** [February 16, 2022, 4:29pm UTC](https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243/1 "2022-02-16T16:29:06Z")

</div>

I found that in link\_monitor, one of the exercises in tutorials repository, when you are reading from/writing to registers, you use `standard_metadata.egress_port` as an index. Based on the [v1model.p4](https://github.com/p4lang/p4c/blob/a89bac3c774f07622ce69552d7ff7d9c1345daeb/p4include/v1model.p4#L351), I think using `standard_metadata.egress_port` as index makes no sense!  
You can find the problem I referred above [here](https://github.com/p4lang/tutorials/blob/ccc56938075eefd5ea36c083cf53de9fb55c933a/exercises/link_monitor/solution/link_monitor.p4#L220).

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [February 16, 2022, 4:41pm UTC](https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243/2 "2022-02-16T16:41:33Z")

</div>

I have only skimmed that part of the P4 program you linked very quickly, and not tried to read and understand the entire tutorials exercise it is part of, but it appears to be using a P4 register array, with one element per output port on the switch, where each element is updated so that it is always equal to the total number of bytes of all packets sent to that output port.

Does that match your understanding of what it is trying to do? Can you ask a more specific question about why it does not make any sense?

---

<div class="post-metadata">

**Author:** ![sorosuh](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@sorosuh](https://forum.p4.org/u/sorosuh)\
**Post date:** [February 16, 2022, 5:09pm UTC](https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243/3 "2022-02-16T17:09:17Z")

</div>

Thank you for the clarification. I misunderstood the index. Actually, I did not consider `(MAX_PORTS)` to make a register as an array of registers!

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [February 16, 2022, 5:12pm UTC](https://forum.p4.org/t/incorrect-parameter-as-register-index-in-link-monitor-tutorial/243/4 "2022-02-16T17:12:47Z")

</div>

Every P4 register in the v1model, PSA, and TNA architectures is an array of elements, indexed from 0 up to (size-1).
