MCPcopy Create free account
hub / github.com/encodeous/nylon / TestRouterNet2S_SolveStarvation

Function TestRouterNet2S_SolveStarvation

core/router_test.go:152–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func 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)
19510.0.0.19/32 via (nh: S, router: S, prefix: 10.0.0.19/32, seqno: 0, metric: 0)
19610.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

Callers

nothing calls this directly

Calls 15

NeighUpdateMethod · 0.95
GetActionsMethod · 0.95
StringRoutesMethod · 0.95
NodeIdTypeAlias · 0.92
ConfigureConstantsFunction · 0.85
MakeNeighboursFunction · 0.85
nodeToPrefixFunction · 0.85
AddLinkFunction · 0.85
NewMockEndpointFunction · 0.85
ComputeRoutesFunction · 0.85
BroadcastUpdateRouteFunction · 0.85
MakePubRouteFunction · 0.85

Tested by

no test coverage detected