(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestRouterNet2S_SolveStarvation(t *testing.T) { |
| 153 | tunables := ConfigureConstants() |
| 154 | // This test is for the following network with our router being S: |
| 155 | // A |
| 156 | // 1 /| D(A) = 1 |
| 157 | // / | FD(A) = 1 |
| 158 | // S |1 |
| 159 | // \ | D(B) = 2 |
| 160 | // 3 \| FD(B) = 2 |
| 161 | // B |
| 162 | |
| 163 | h := &RouterHarness{} |
| 164 | rs := &state.RouterState{ |
| 165 | RouterTunables: tunables, |
| 166 | Id: "S", |
| 167 | SelfSeqno: make(map[netip.Prefix]uint16), |
| 168 | Routes: make(map[netip.Prefix]state.SelRoute), |
| 169 | Sources: make(map[state.Source]state.FD), |
| 170 | Neighbours: MakeNeighbours("A", "B"), |
| 171 | Advertised: map[netip.Prefix]state.Advertisement{nodeToPrefix("S"): {NodeId: state.NodeId("S"), Expiry: maxTime}}, |
| 172 | } |
| 173 | |
| 174 | AS := AddLink(rs, NewMockEndpoint("A", 1)) |
| 175 | _ = AddLink(rs, NewMockEndpoint("B", 3)) |
| 176 | |
| 177 | // A's advertised routes |
| 178 | h.NeighUpdate(rs, "A", "S", nodeToPrefix("S"), 0, 1) |
| 179 | h.NeighUpdate(rs, "A", "A", nodeToPrefix("A"), 0, 0) |
| 180 | h.NeighUpdate(rs, "A", "B", nodeToPrefix("B"), 0, 1) |
| 181 | |
| 182 | // B's advertised routes |
| 183 | h.NeighUpdate(rs, "B", "B", nodeToPrefix("B"), 0, 0) |
| 184 | h.NeighUpdate(rs, "B", "A", nodeToPrefix("A"), 0, 1) |
| 185 | h.NeighUpdate(rs, "B", "S", nodeToPrefix("S"), 0, 3) |
| 186 | |
| 187 | ComputeRoutes(rs, h) |
| 188 | a := h.GetActions() |
| 189 | a.AssertEqual(t, |
| 190 | BroadcastUpdateRoute(MakePubRoute("A", nodeToPrefix("A"), 0, 1)), |
| 191 | BroadcastUpdateRoute(MakePubRoute("B", nodeToPrefix("B"), 0, 2)), |
| 192 | BroadcastUpdateRoute(MakePubRoute("S", nodeToPrefix("S"), 0, 0)), |
| 193 | ) |
| 194 | assert.Equal(t, `10.0.0.1/32 via (nh: A, router: A, prefix: 10.0.0.1/32, seqno: 0, metric: 1) |
| 195 | 10.0.0.19/32 via (nh: S, router: S, prefix: 10.0.0.19/32, seqno: 0, metric: 0) |
| 196 | 10.0.0.2/32 via (nh: A, router: B, prefix: 10.0.0.2/32, seqno: 0, metric: 2)`, rs.StringRoutes()) |
| 197 | |
| 198 | // check feasibility distances |
| 199 | assert.Equal(t, state.FD{Seqno: 0, Metric: 1}, rs.Sources[state.Source{NodeId: "A", Prefix: nodeToPrefix("A")}]) |
| 200 | assert.Equal(t, state.FD{Seqno: 0, Metric: 2}, rs.Sources[state.Source{NodeId: "B", Prefix: nodeToPrefix("B")}]) |
| 201 | assert.Equal(t, state.FD{Seqno: 0, Metric: 0}, rs.Sources[state.Source{NodeId: "S", Prefix: nodeToPrefix("S")}]) |
| 202 | |
| 203 | // Suppose now that the link to A goes down |
| 204 | // A |
| 205 | // | |
| 206 | // | FD(A) = 1 |
| 207 | // S |1 |
| 208 | // \ | D(B) = 2 |
| 209 | // 3 \| FD(B) = 2 |
nothing calls this directly
no test coverage detected