How To Install CLASSIFIER.H Packages in Ns2
To Import Classifier.H Packages In Ns2 we have shared the steps that are required for the installation. The Classifier Header, found in the classifier.h file, is tasked with routing packets to the correct next-hop node or network element according to defined criteria, including destination address and protocol type. This class is essential for effective packet routing and forwarding, as it categorizes packets into flows or routes through different classification techniques. Within the classifier.h file, there are methods and data structures designed to oversee the allocation of packets to their appropriate output ports, ensuring efficient packet distribution throughout the network.
In the TCL script, the features of classifier.h are utilized in an indirect manner. The NS-2 simulation environment provides users the ability to set up classifiers, including multi-field and hierarchical types, using TCL commands, all without the need to directly reference the classifier.h file. These commands connect to the C++ functions found in classifier.h, allowing users to specify the routing and forwarding of packets based on their characteristics. This approach offers the flexibility to dynamically configure routing tables and packet classification criteria throughout the simulation.
Read out the necessary steps for installing Classifier.h.
PRE-REQUISITES:
- Fresh installation of Ubuntu 16.04 LTS:
Screenshot:
2.NS-2.35 Installation:
Screenshot:
Here, Percentage (%) symbol Denotes the successful installation of the NS 2.35 Simulator.
Screenshot:
HEADER FILE VERIFICATION:
- Locate to the ns-2.35 folder:
Screenshot:
2.Create the Main.tcl file in the scratch folder:
Next we need to create the Main.tcl file by using text editor in the ns-2.35 folder.
Screenshot:
Next we need to paste the below code to the Main.tcl file and save the file in the ns-2.35 folder.
Code:
set ns [new Simulator]
$ns proc simplex-link { n1 n2 bw delay type } {
$self instvar link_ queueMap_ nullAgent_
$self instvar traceAllFile_
set sid [$n1 id]
set did [$n2 id]
if [info exists queueMap_($type)] {
set type $queueMap_($type)
}
if { $type == “FQ” } {
set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $nullAgent_]
} else {
set q [new Queue/$type]
$q drop-target $nullAgent_
set link_($sid:$did) [new SimpleLink $n1 $n2 $bw $delay $q]
}
$n1 add-neighbor $n2
if { $type == “RED” } {
set bw [[$link_($sid:$did) set link_] set bandwidth_]
$q set ptc_ [expr $bw / (8. * [$q set mean_pktsize_])]
}
if [info exists traceAllFile_] {
$self trace-queue $n1 $n2 $traceAllFile_
}
set trace [$self get-ns-traceall]
if {$trace != “”} {
$self trace-queue $n1 $n2 $trace
}
set trace [$self get-nam-traceall]
if {$trace != “”} {
$self namtrace-queue $n1 $n2 $trace
}
}
Class Classifier/Hash/Fid/FQ -superclass Classifier/Hash/Fid
Classifier/Hash/Fid/FQ instproc unknown-flow { src dst fid } {
$self instvar fq_
$fq_ new-flow $src $dst $fid
}
Class FQLink -superclass Link
FQLink instproc init { src dst bw delay nullAgent } {
$self next $src $dst
$self instvar link_ queue_ head_ toNode_ ttl_ classifier_ \nactive_ drpT_
$self instvar drophead_
set drpT_ $nullAgent
set nactive_ 0
set queue_ [new Queue/FQ]
set link_ [new DelayLink]
$link_ set bandwidth_ $bw
$link_ set delay_ $delay
set classifier_ [new Classifier/Hash/Fid/FQ 33]
$classifier_ set fq_ $self
$queue_ target $link_
$queue_ drop-target $nullAgent
$link_ target [$toNode_ entry]
set head_ $classifier_
set drophead_ [new Connector]
$drophead_ target [[Simulator instance] set nullAgent_]
set ttl_ [new TTLChecker]
$ttl_ target [$link_ target]
$link_ target $ttl_
$queue_ set secsPerByte_ [expr 8.0 / [$link_ set bandwidth_]]
}
Queue set limit_ 10
FQLink set queueManagement_ RED
FQLink set queueManagement_ DropTail
FQLink instproc new-flow { src dst fid } {
$self instvar classifier_ nactive_ queue_ link_ drpT_
incr nactive_
set type [$class set queueManagement_]
set q [new Queue/$type]
if { $type == “RED” } {
set bw [$link_ set bandwidth_]
$q set ptc_ [expr $bw / (8. * [$q set mean_pktsize_])]
}
$q drop-target $drpT_
set slot [$classifier_ installNext $q]
$classifier_ set-hash auto $src $dst $fid $slot
$q target $queue_
$queue_ install $fid $q
}
FQLink instproc up? { } {
return up
}
FQLink instproc nam-trace { ns f } {
$self instvar enqT_ deqT_ drpT_ rcvT_ dynT_
if [info exists enqT_] {
$enqT_ namattach $f
if [info exists deqT_] {
$deqT_ namattach $f
}
if [info exists drpT_] {
$drpT_ namattach $f
}
if [info exists rcvT_] {
$rcvT_ namattach $f
}
if [info exists dynT_] {
foreach tr $dynT_ {
$tr namattach $f
}
}
} else {
$self trace $ns $f “nam”
}
}
FQLink instproc dump-namconfig {} {
$self instvar link_ attr_ fromNode_ toNode_
if ![info exists attr_(COLOR)] {
set attr_(COLOR) “black”
}
if ![info exists attr_(ORIENTATION)] {
set attr_(ORIENTATION) “”
}
set ns [Simulator instance]
set bw [$link_ set bandwidth_]
set delay [$link_ set delay_]
$ns puts-nam-config \
“l -t * -s [$fromNode_ id] -d [$toNode_ id] -S UP -r $bw -D $delay -o $attr_(ORIENTATION)”
}
FQLink instproc dump-nam-queueconfig {} {
$self instvar attr_ fromNode_ toNode_
set ns [Simulator instance]
if [info exists attr_(QUEUE_POS)] {
$ns puts-nam-config “q -t * -s [$fromNode_ id] -d [$toNode_ id] -a $attr_(QUEUE_POS)”
} else {
set attr_(QUEUE_POS) “”
}
}
FQLink instproc trace { ns f {op “”} } {
$self instvar enqT_ deqT_ drpT_ queue_ link_ head_ fromNode_ toNode_
$self instvar rcvT_ ttl_
$self instvar drophead_
set enqT_ [$ns create-trace Enque $f $fromNode_ $toNode_ $op]
set deqT_ [$ns create-trace Deque $f $fromNode_ $toNode_ $op]
set drpT_ [$ns create-trace Drop $f $fromNode_ $toNode_ $op]
set rcvT_ [$ns create-trace Recv $f $fromNode_ $toNode_ $op]
$self instvar drpT_ drophead_
set nxt [$drophead_ target]
$drophead_ target $drpT_
$drpT_ target $nxt
$queue_ drop-target $drophead_
$deqT_ target [$queue_ target]
$queue_ target $deqT_
if { [$head_ info class] == “networkinterface” } {
$enqT_ target [$head_ target]
$head_ target $enqT_
} else {
$enqT_ target $head_
set head_ $enqT_
}
$rcvT_ target [$ttl_ target]
$ttl_ target $rcvT_
$self instvar dynamics_
if [info exists dynamics_] {
$self trace-dynamics $ns $f $op
}
}
FQLink instproc init-monitor ns {
puts stderr “FQLink::init-monitor not implemented”
}
proc build_topology { ns which } {
$ns color 1 red
$ns color 2 green
foreach i “0 1 2 3” {
global n$i
set tmp [$ns node]
set n$i $tmp
}
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
if { $which == “FIFO” } {
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
} elseif { $which == “RED” } {
$ns duplex-link $n2 $n3 1.5Mb 10ms RED
} else {
$ns duplex-link $n2 $n3 1.5Mb 10ms FQ
}
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5
}
proc build_tcp { from to startTime } {
global ns
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $from $tcp
$ns attach-agent $to $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at $startTime “$ftp start”
return $tcp
}
proc finish file {
set f [open temp.rands w]
puts $f “TitleText: $file”
puts $f “Device: Postscript”
exec rm -f temp.p temp.d
exec touch temp.d temp.p
exec awk {
{
if (($1 == “+” || $1 == “-” ) && \
($5 == “tcp”))\
print $2, $8 + ($11 % 90) * 0.01
}
} out.tr > temp.p
exec awk {
{
if ($1 == “d”) print $2, $8 + ($11 % 90) * 0.01
}
} out.tr > temp.d
puts $f \”packets
flush $f
exec cat temp.p >@ $f
flush $f
puts $f [format “\n\”skip-1\n0 1\n\n\”skip-2\n0 1\n\n”]
puts $f \”drops
flush $f
exec head -n 1 temp.d >@ $f
exec cat temp.d >@ $f
close $f
set k 1
while 1 {
global tcp$k
if [info exists tcp$k] {
set tcp [set tcp$k]
puts “tcp$k seqno [$tcp set t_seqno_]”
} else {
break
}
incr k
}
exit 0
}
set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf
build_topology $ns FQ
set tcp1 [build_tcp $n0 $n3 0.1]
$tcp1 set class_ 1
set tcp2 [build_tcp $n1 $n3 0.1]
$tcp2 set class_ 2
$ns at 40.0 “finish Output”
$ns at 8.0 “xfinish”
proc xfinish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
puts “running nam…”
exec nam out.nam &
exit 0
}
$ns run
Screenshot:
3.Open the Terminal:
Next, we need to launch the terminal by right clicking the mouse in the ns-2.35 location.
Screenshot:
Screenshot:
4.NS-2.35 Configuration && Building Process:
Next, we need to configure and build the ns-2.35 folder to make the Created files need to work in ns-2.35 configuration.
Command: “./make”
Screenshot:
Screenshot:
Screenshot:
Here, NS-2.35 Building process completed successfully.
5.Importing Classifier.h:
Here we imported the Classifier.h header file code indirectly accessed the Classifier class used in the Tcl script (Class Classifier/Hash/Fid/FQ -superclass Classifier/Hash/Fid), Classify the Packet Information for each nodes in this example program. Here we highlighted the code line that highlighted which is internally accessed Classifier.h that we will show class file that used in this code via Routing folder.
Screenshot:
Screenshot:
Here we will show the header file by opening Classifier.h file to show the class or function imported from the Classifier.h in the example code. “(Class Classifier/Hash/Fid/FQ -superclass Classifier/Hash/Fid)” eventually instantiating to Classify the packet information and Time Slot for each nodes in the Tcl script internally relies on Classification of the packet information and assign the time Slot for each nodes.
Screenshot:
Screenshot:
6.Executing the Example Program for Packet Header:
Then we need to run the Example program for Packet Header to view output of the program.
Command: “./ns Main.tcl”
Screenshot:
Here we shown the output of the example program by using Classifier.h.
Screenshot:
Screenshot:
Screenshot:
Here, we have shown the out.tr file for Output of the Communication of the Network done in the simulation.
Screenshot:
In the NS 2.35 Simulation Example Program, the Classifier.h Header file is successfully imported. If you need more help with CLASSIFIER.H PACKAGES, feel free to contact us! Our development team is here to help you get the best results. We have all the tools and resources you need to support you at the right time. Check out ns2projects.com for personalized research services.