KENSv3
KAIST Educational Network System
All Classes Files Functions Variables Enumerations Pages
Public Member Functions | Protected Member Functions | Friends | List of all members
E::HostModule Class Referenceabstract

HostModule is an interface for classes which is registered to a certain Host. HostModules can communicate with each other by their names. More...

#include <E_Host.hpp>

Inheritance diagram for E::HostModule:
E::Ethernet E::IPv4 E::PWOSPFAssignment E::RIPAssignment E::TCPAssignment

Public Member Functions

 HostModule (std::string name, Host &host)
 Create a HostModule. It is automatically registered to the Host. Module is registered to a System when it is created. More...
 
virtual std::string getHostModuleName () final
 
virtual void initialize (void)
 This function is automatically called by Host just before the simulation begins. You can override this function if needed.
 
virtual void finalize (void)
 This function is automatically called by Host just after the simulation ends. You can override this function if needed.
 
virtual std::any diagnose (std::any param)
 Host module control function.
 

Protected Member Functions

virtual void packetArrived (std::string fromModule, Packet &&packet)=0
 This function is automatically called by Host when this module receives a Packet. You must override this function to handle Packet events. When a Packet is received, you must FREE IT OR PASS IT TO OTHER HOSTMODULE. More...
 
virtual void sendPacket (std::string toModule, Packet &&packet) final
 This function transfers Packets among HostModules in the Host. Unlike Module::Message, we use fire-and-forget policy with Packets. Once you send a Packet using sendPacket, you DO NOT HAVE TO FREE THAT PACKET. More...
 
void sendPacket (std::string toModule, const Packet &packet)
 
Time getCurrentTime ()
 
Size getWireSpeed (int port_num)
 Get cost for local port (link) More...
 
size_t getPortCount ()
 Get the number of ports. More...
 
void print_log (uint64_t level, const char *format,...)
 Prints log with specified log level and format. NetworkLog::print_log prints logs specified in log level parameter. For example, if log level is set to TCP_LOG, it only prints TCP_LOG logs. If you want to print multiple log levels in NetworkLog, you can set log level with OR operation (i.e. SYSCALL_ERROR | MODULE_ERROR). More...
 

Friends

class Host
 

Detailed Description

HostModule is an interface for classes which is registered to a certain Host. HostModules can communicate with each other by their names.

Note
HostModule has no relationship with Module.

Constructor & Destructor Documentation

◆ HostModule()

E::HostModule::HostModule ( std::string  name,
Host host 
)

Create a HostModule. It is automatically registered to the Host. Module is registered to a System when it is created.

Parameters
nameName of this module. This name is used for identifying each module.
hostHost to be registered.

Member Function Documentation

◆ getCurrentTime()

Time E::HostModule::getCurrentTime ( )
protected
Returns
Returns current virtual clock of the System.

◆ getHostModuleName()

std::string E::HostModule::getHostModuleName ( )
finalvirtual
Returns
My name used in the registered Host.

◆ getPortCount()

size_t E::HostModule::getPortCount ( )
protected

Get the number of ports.

Returns
the number of ports

◆ getWireSpeed()

Size E::HostModule::getWireSpeed ( int  port_num)
protected

Get cost for local port (link)

Parameters
port_numquerying port's number
Returns
local link cost

◆ packetArrived()

virtual void E::HostModule::packetArrived ( std::string  fromModule,
Packet &&  packet 
)
protectedpure virtual

This function is automatically called by Host when this module receives a Packet. You must override this function to handle Packet events. When a Packet is received, you must FREE IT OR PASS IT TO OTHER HOSTMODULE.

Parameters
fromModuleName of the HostModule who sent this packet.
packetReceived packet.

Implemented in E::IPv4, E::Ethernet, E::RIPAssignment, E::PWOSPFAssignment, and E::TCPAssignment.

◆ print_log()

void E::HostModule::print_log ( uint64_t  level,
const char *  format,
  ... 
)
protected

Prints log with specified log level and format. NetworkLog::print_log prints logs specified in log level parameter. For example, if log level is set to TCP_LOG, it only prints TCP_LOG logs. If you want to print multiple log levels in NetworkLog, you can set log level with OR operation (i.e. SYSCALL_ERROR | MODULE_ERROR).

Note
Log::print_log
Parameters
levellog level
formatFormat string
...Print arguments for format string

◆ sendPacket()

void E::HostModule::sendPacket ( std::string  toModule,
Packet &&  packet 
)
finalprotectedvirtual

This function transfers Packets among HostModules in the Host. Unlike Module::Message, we use fire-and-forget policy with Packets. Once you send a Packet using sendPacket, you DO NOT HAVE TO FREE THAT PACKET.

Parameters
toModuleName of the destination HostModule.
packetPacket to be sent.

The documentation for this class was generated from the following files: