Skip to content

Commit 9756925

Browse files
committed
L2NetworkConfigurator: add dumpConfiguration parameter and a module test
The dumpConfiguration parameter (default false) prints the computed per-port link cost, priority and edge flag for every interface to the module output, analogous to Ipv4NetworkConfigurator's dump* parameters. tests/module/L2NetworkConfigurator_1.test uses it to verify that every port of a small switch network is configured: speed-derived default costs (200000 for 100 Mb/s, 20000 for 1 Gb/s) plus an explicit per-port <interface> cost override. It is a regression test for the "only one port configured" bug.
1 parent 4f6c89a commit 9756925

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

src/inet/linklayer/configurator/common/L2NetworkConfigurator.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,26 @@ void L2NetworkConfigurator::computeConfiguration()
210210
TIME(extractTopology(topology));
211211
// read the configuration from XML; it will serve as input for port assignment
212212
TIME(readInterfaceConfiguration(rootNode));
213+
// optionally dump the computed per-port configuration to the module output
214+
if (par("dumpConfiguration"))
215+
dumpConfiguration();
213216
printElapsedTime("initialize", initializeStartTime);
214217
}
215218

219+
void L2NetworkConfigurator::dumpConfiguration()
220+
{
221+
for (int i = 0; i < topology.getNumNodes(); i++) {
222+
Node *node = (Node *)topology.getNode(i);
223+
for (auto& interfaceInfo : node->interfaceInfos) {
224+
NetworkInterface *networkInterface = interfaceInfo->networkInterface;
225+
EV_INFO << node->module->getFullPath() << "." << networkInterface->getInterfaceName()
226+
<< ": linkCost=" << interfaceInfo->portData.linkCost
227+
<< " priority=" << interfaceInfo->portData.priority
228+
<< " edge=" << (interfaceInfo->portData.edge ? "true" : "false") << endl;
229+
}
230+
}
231+
}
232+
216233
void L2NetworkConfigurator::ensureConfigurationComputed(L2Topology& topology)
217234
{
218235
if (topology.getNumNodes() == 0)

src/inet/linklayer/configurator/common/L2NetworkConfigurator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class INET_API L2NetworkConfigurator : public SimpleModule
110110
*/
111111
virtual void computeConfiguration();
112112

113+
/**
114+
* Prints the computed per-port Layer 2 configuration (link cost, priority,
115+
* edge flag) for every interface to the module output. Controlled by the
116+
* "dumpConfiguration" parameter.
117+
*/
118+
virtual void dumpConfiguration();
119+
113120
// helper functions
114121
virtual bool linkContainsMatchingHostExcept(InterfaceInfo *currentInfo, Matcher& hostMatcher, cModule *exceptModule);
115122
void ensureConfigurationComputed(L2Topology& topology);

src/inet/linklayer/configurator/common/L2NetworkConfigurator.ned

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ simple L2NetworkConfigurator extends SimpleModule
3939
@class(L2NetworkConfigurator);
4040
@display("i=block/cogwheel");
4141
xml config = default(xml("<config><interface hosts='**' ports='**' priority='128' edge='false'/></config>"));
42+
bool dumpConfiguration = default(false); // Print the computed per-port configuration (link cost, priority, edge flag) to the module output
4243
}
4344

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
%description:
2+
3+
Tests that L2NetworkConfigurator configures the STP/RSTP port parameters
4+
(link cost, priority, edge flag) on EVERY port of EVERY switch in the network,
5+
not just on a single port. The default link cost is derived from the link speed
6+
as recommended by IEEE 802.1D-2004 (200000 for 100 Mb/s, 20000 for 1 Gb/s),
7+
and explicit per-port <interface> rules override it.
8+
9+
This is a regression test for the bug where extractTopology() was triggered
10+
prematurely (during interface creation) and cached an incomplete topology, so
11+
only one port of the whole network ended up being configured.
12+
13+
Topology:
14+
switchA --Eth100M-- switchB --Eth1G-- switchC
15+
16+
The <interface> rules:
17+
- switchB's port towards switchC: explicit cost 12345
18+
- every other port: cost derived from link speed; priority 100; edge false
19+
20+
%file: test.ned
21+
22+
import inet.linklayer.configurator.common.L2NetworkConfigurator;
23+
import inet.node.ethernet.Eth100M;
24+
import inet.node.ethernet.Eth1G;
25+
import inet.node.ethernet.EthernetSwitch;
26+
27+
network Test
28+
{
29+
submodules:
30+
l2NetworkConfigurator: L2NetworkConfigurator {
31+
parameters:
32+
dumpConfiguration = true;
33+
config = xml("<config>\
34+
<interface hosts='switchB' towards='switchC' cost='12345' priority='100' edge='false'/>\
35+
<interface hosts='**' ports='**' priority='100' edge='false'/>\
36+
</config>");
37+
}
38+
switchA: EthernetSwitch { hasStp = true; }
39+
switchB: EthernetSwitch { hasStp = true; }
40+
switchC: EthernetSwitch { hasStp = true; }
41+
connections:
42+
switchA.ethg++ <--> Eth100M <--> switchB.ethg++;
43+
switchB.ethg++ <--> Eth1G <--> switchC.ethg++;
44+
}
45+
46+
%inifile: omnetpp.ini
47+
48+
[General]
49+
network = Test
50+
cmdenv-express-mode = false
51+
ned-path = .;../../../../src;../../lib
52+
sim-time-limit = 0s
53+
54+
#omnetpp 5.0 - 5.1 compatibility:
55+
eventlog-file = "${resultdir}/${configname}-${runnumber}.elog"
56+
output-scalar-file = "${resultdir}/${configname}-${runnumber}.sca"
57+
output-vector-file = "${resultdir}/${configname}-${runnumber}.vec"
58+
snapshot-file = "${resultdir}/${configname}-${runnumber}.sna"
59+
60+
%contains: stdout
61+
Test.switchA.eth0: linkCost=200000 priority=100 edge=false
62+
Test.switchB.eth0: linkCost=200000 priority=100 edge=false
63+
Test.switchB.eth1: linkCost=12345 priority=100 edge=false
64+
Test.switchC.eth0: linkCost=20000 priority=100 edge=false
65+
66+
%#--------------------------------------------------------------------------------------------------------------
67+
%postrun-command: grep "undisposed object:" test.out > test_undisposed.out || true
68+
%not-contains: test_undisposed.out
69+
undisposed object: (
70+
%#--------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)