Problems about the class PLC_Node and the original class Node

75 views
Skip to first unread message

panqi...@gmail.com

unread,
May 15, 2014, 10:24:24 PM5/15/14
to ns-3-...@googlegroups.com
I am a new NS-3 user .I hope to use the PLC_Node as the formal Node and install the other netdevice,distribute the IPv4 address and so on.So there was the error .This is my code as follows.I wish that PLC ,p2p,wifi and so on can use one node together .Need for your help!  Thank you .

#include<iostream>
#include<sstream>
#include<fstream>
#include<time.h>
#include<ns3/core-module.h>
#include<ns3/nstime.h>
#include<ns3/simulator.h>
#include<ns3/output-stream-wrapper.h>
#include"ns3/plc.h"
#include"ns3/network-module.h"
#include"ns3/internet-module.h"
#include"ns3/point-to-point-module.h"
#include"ns3/applications-module.h"
using namespace ns3;

void ReceivedACK(void)
{
   NS_LOG_UNCOND(Simulator::Now()<<":ACK received!");
}
int main(int argc,char *argv[])
{
      LogComponentEnableAll(LOG_PREFIX_TIME);
      LogComponentEnable("PLC_Mac",LOG_LEVEL_INFO);
      Packet::EnablePrinting();
      //定义频率类型
      PLC_SpectrumModelHelper smHelper;
      Ptr<const SpectrumModel> sm;
      sm=smHelper.GetSpectrumModel(0,10e6,100);
      //定义传输电力谱密度
      Ptr<SpectrumValue>txPsd=Create<SpectrumValue> (sm);
      (*txPsd)=1e-8;
      //创建电线类型
      Ptr<PLC_Cable>cable=CreateObject<PLC_NAYY150SE_Cable> (sm);
      //创建节点
      Ptr<PLC_Node> n1=CreateObject<PLC_Node>();
      Ptr<PLC_Node> n2=CreateObject<PLC_Node>();
      n1->SetPosition(0,0,0);
      n2->SetPosition(1000,0,0);
      n1->SetName("Node1");
      n2->SetName("Node2");
     
      PLC_NodeList nodes;
      nodes.push_back(n1);
      nodes.push_back(n2);
     //链接节点
      CreateObject<PLC_Line>(cable,n1,n2);
     //设置信道
      PLC_ChannelHelper channelHelper(sm);
      channelHelper.Install(nodes);
      Ptr<PLC_Channel> channel=channelHelper.GetChannel();
      //创建电力线出路
      Ptr<PLC_Outlet> o1=CreateObject<PLC_Outlet>(n1);
      Ptr<PLC_Outlet> o2=CreateObject<PLC_Outlet>(n2);
      //定义环境噪声
      Ptr<SpectrumValue> noiseFloor=CreateWorstCaseBgNoise(sm)->GetNoisePsd();
      //创建网络设备
      PLC_NetDeviceHelper deviceHelper(sm,txPsd,nodes);
      deviceHelper.SetNoiseFloor(noiseFloor);
      deviceHelper.Setup();
      PLC_NetdeviceMap devMap=deviceHelper.GetNetdeviceMap();
     //计算信道
      channel->InitTransmissionChannels();
      channel->CalcTransmissionChannels();
      //创建信息发送包
      Ptr<Packet> p=Create<Packet> (1024);
      //确定node1的网络设备在时间t=1s时发送数据包p到node2网络设备的开始时间
      Simulator::Schedule(Seconds(1),&PLC_NetDevice::Send,devMap["Node1"],p,devMap["Node2"]->GetAddress(),0);

      PointToPointHelper pointToPoint;//2、创建P2P类型的Helper
      pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));//使用Helper设置链路属性
      pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

      NetDeviceContainer devices;
      devices = pointToPoint.Install (n1,n2);//使用Helper将网卡安装到节点

      InternetStackHelper stack;//3、安装IP协议栈
      stack.Install (n1,n2);

      Ipv4AddressHelper address;//4、分配IP地址
      address.SetBase ("10.1.1.0", "255.255.255.0");
      Ipv4InterfaceContainer interfaces = address.Assign (devices);//分配到网卡

      UdpEchoServerHelper echoServer (9);//5.1、安装UdpServer应用服务,9表示服务端口
      ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
      serverApps.Start (Seconds (1.0));
      serverApps.Stop (Seconds (10.0));
      serverApps.Start (Seconds (1.0));//6.1、Server启动时间
      serverApps.Stop (Seconds (10.0));

      UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);//5.2、安装UdpClient应用服务,需要指明服务器IP以及服务端口
      echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
      echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
      echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
      ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
      clientApps.Start (Seconds (2.0));//6.2、Client启动时间
      clientApps.Stop (Seconds (10.0));
       //开始仿真
      Simulator::Run();

       //清除仿真
      Simulator::Destroy();

      return EXIT_SUCCESS;
}
     
Reply all
Reply to author
Forward
0 new messages