我正在尝试使用OMNet ++构建网络模拟。问题是我不知道如何配置EtherSwitch和EtherHost设备并给它们IP。在交换机和路由器之间路由流量的必要路由代码是什么。路由器端口的IP地址必须如下表所示;
路由器支路IP
1 ------ 1 --- 192.168.1.0/24
1 ------ 4 --- 192.168.4.1
1 ------ 5 --- 192.168.5.1
2 ------ 2 --- 192.168.2.0/24
2 ------ 5 --- 192.168.5.2
2 ------ 6 --- 192.168.6.2
3 ------ 3 --- 192.168.3.0/24
3 ------ 4 --- 192.168.4.3
3 ------ 6 --- 192.168.6.3
此处所需网络的图片:
我的NED档案:
import inet.nodes.inet.Router;
import inet.nodes.inet.StandardHost;
import ned.DatarateChannel;
import inet.nodes.ethernet.EtherSwitch;
import inet.nodes.ethernet.EtherHost;
import inet.networklayer.autorouting.FlatNetworkConfigurator;
network gyte
{
@display("bgb=457,318");
types:
channel geth extends DatarateChannel
{
datarate = 1Gbps;
}
channel hgeth extends DatarateChannel
{
datarate = 512Mbps;
}
submodules:
// Routers
routers[3]: Router {
parameters:
@display("p=208,272,row=id;i=abstract/router");
gates:
pppg[3];
}
// Switches
switches[3]: EtherSwitch {
parameters:
@display("p=179,162,row");
gates:
ethg[3];
}
// Hosts
ehosts[4]: EtherHost {
parameters:
@display("p=384,56,row");
gates:
ethg;
}
// Servers
eservers[2]: EtherHost {
parameters:
@display("i=device/server;p=117,71,row");
gates:
ethg;
}
configurator: FlatNetworkConfigurator {
@display("p=22,25");
}
connections:
ehosts[0].ethg <--> switchs[0].ethg[0];
eservers[0].ethg <--> switchs[0].ethg[1];
ehosts[1].ethg <--> switchs[1].ethg[0];
eservers[1].ethg <--> switchs[1].ethg[1];
switchs[0].ethg[2] <--> routers[0].pppg[0];
switchs[1].ethg[2] <--> routers[1].pppg[0];
routers[0].pppg[1] <--> routers[1].pppg[1];
routers[0].pppg[2] <--> routers[2].pppg[0];
routers[1].pppg[2] <--> routers[2].pppg[1];
routers[2].pppg[2] <--> switchs[2].ethg[0];
switchs[2].ethg[1] <--> ehosts[2].ethg;
switchs[2].ethg[2] <--> ehosts[3].ethg;
}
答案 0 :(得分:1)
交换机没有IP地址(实际上它们是为了管理交换机)。切换(第2层)基于MAC地址。 所以在模拟中你不必为Switch配置任何东西。
为了将IP地址分配给主机和路由器并将路由添加到路由表,您可以使用“flatnetworkconfigurator”模块。只需将其放入您的NED文件中即可。 但是所有IP地址都不在一个子网中。
其他解决方案是使用MRT文件。在那里你用linux语法为每个接口指定IP,子网掩码,网关等。