ns-mpls-node.tcl

来自「一款用来进行网络模拟的软件」· TCL 代码 · 共 510 行 · 第 1/2 页

TCL
510
字号
# -*-	Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-##  Time-stamp: <2000-09-11 15:10:21 haoboy># #  This program is free software; you can redistribute it and/or#  modify it under the terms of the GNU General Public License,#  version 2, as published by the Free Software Foundation.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#  GNU General Public License for more details.##  You should have received a copy of the GNU General Public License along#  with this program; if not, write to the Free Software Foundation, Inc.,#  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.##  The copyright of this module includes the following#  linking-with-specific-other-licenses addition:##  In addition, as a special exception, the copyright holders of#  this module give you permission to combine (via static or#  dynamic linking) this module with free software programs or#  libraries that are released under the GNU LGPL and with code#  included in the standard release of ns-2 under the Apache 2.0#  license or under otherwise-compatible licenses with advertising#  requirements (or modified versions of such code, with unchanged#  license).  You may copy and distribute such a system following the#  terms of the GNU GPL for this module and the licenses of the#  other code concerned, provided that you include the source code of#  that other code when and as the GNU GPL requires distribution of#  source code.##  Note that people who make modified versions of this module#  are not obligated to grant this special exception for their#  modified versions; it is their choice whether to do so.  The GNU#  General Public License gives permission to release a modified#  version without this exception; this exception also makes it#  possible to release a modified version which carries forward this#  exception.# #  Original source contributed by Gaeil Ahn. See below.##  $Header: /cvsroot/nsnam/ns-2/tcl/mpls/ns-mpls-node.tcl,v 1.5 2005/09/16 03:05:45 tomh Exp $############################################################################ Copyright (c) 2000 by Gaeil Ahn                                	  ## Everyone is permitted to copy and distribute this software.		  ## Please send mail to fog1@ce.cnu.ac.kr when you modify or distribute     ## this sources.								  ############################################################################## XXX MPLS is NOT compatible with hierarchical routing, because:## 1) MPLS classifier is explicitly coupled with unicast address classifier,#    which does not support hierarchical routing. The reason is MPLS needs #    to check whether a route update is an update, a new entry, or a #    "no change". This is not as straightforward and efficient when the #    MPLS classifier is decoupled from the unicast address classifier, because#    through add-route{} interface, Node can only tell this module that a new#    route is added, but not whether this is an update, a new entry, or #    a "no change". I don't have a clean solution yet. - haoboy#RtModule/MPLS instproc register { node } {	$self instvar classifier_	$self attach-node $node	$node route-notify $self	$node port-notify $self        set classifier_ [new Classifier/Addr/MPLS]        $classifier_ set-node $node $self	$node install-entry $self $classifier_ 0	$self attach-classifier $classifier_}#RtModule/MPLS instproc route-notify { module } { }# Done common routing module interfaces. Now is our own processing.RtModule/MPLS instproc enable-data-driven {} {	[$self set classifier_] cmd enable-data-driven}RtModule/MPLS instproc enable-control-driven {} {	[$self set classifier_] cmd enable-control-driven}RtModule/MPLS instproc make-ldp {} {	set ldp [new Agent/LDP]	$self cmd attach-ldp $ldp	$ldp set-mpls-module $self	[$self node] attach $ldp	return $ldp}RtModule/MPLS instproc exist-fec {fec phb} {        return [[$self set classifier_] exist-fec $fec $phb]}RtModule/MPLS instproc get-incoming-iface {fec lspid} {        return [[$self set classifier_] GetInIface $fec $lspid]}RtModule/MPLS instproc get-incoming-label {fec lspid} {        return [[$self set classifier_] GetInLabel $fec $lspid]}RtModule/MPLS instproc get-outgoing-label {fec lspid} {        return [[$self set classifier_] GetOutLabel $fec $lspid]}RtModule/MPLS instproc get-outgoing-iface {fec lspid} {        return [[$self set classifier_] GetOutIface $fec $lspid]}RtModule/MPLS instproc get-fec-for-lspid {lspid} {        return [[$self set classifier_] get-fec-for-lspid $lspid]}RtModule/MPLS instproc in-label-install {fec lspid iface label} {	set dontcare [Classifier/Addr/MPLS dont-care]	$self label-install $fec $lspid $iface $label $dontcare $dontcare}RtModule/MPLS instproc out-label-install {fec lspid iface label} {	set dontcare [Classifier/Addr/MPLS dont-care]	$self label-install $fec $lspid $dontcare $dontcare $iface $label}RtModule/MPLS instproc in-label-clear {fec lspid} {	set dontcare [Classifier/Addr/MPLS dont-care]	$self label-clear $fec $lspid -1 -1 $dontcare $dontcare}RtModule/MPLS instproc out-label-clear {fec lspid} {	set dontcare [Classifier/Addr/MPLS dont-care]	$self label-clear $fec $lspid $dontcare $dontcare -1 -1}RtModule/MPLS instproc label-install {fec lspid iif ilbl oif olbl} {        [$self set classifier_] LSPsetup $fec $lspid $iif $ilbl $oif $olbl}RtModule/MPLS instproc label-clear {fec lspid iif ilbl oif olbl} {        [$self set classifier_] LSPrelease $fec $lspid $iif $ilbl $oif $olbl}RtModule/MPLS instproc flow-erlsp-install {fec phb lspid} {        [$self set classifier_] ErLspBinding $fec $phb $lspid}RtModule/MPLS instproc erlsp-stacking {erlspid tunnelid} {        [$self set classifier_] ErLspStacking -1 $erlspid -1 $tunnelid}RtModule/MPLS instproc flow-aggregation {fineFec finePhb coarseFec coarsePhb} {        [$self set classifier_] FlowAggregation $fineFec $finePhb $coarseFec \			$coarsePhb}RtModule/MPLS instproc enable-reroute {option} {        $self instvar classifier_         $classifier_ set enable_reroute_ 1        if {$option == "drop"} {		$classifier_ set reroute_option_ 0        } elseif {$option == "L3"} {		$classifier_ set reroute_option_ 1        } elseif {$option == "new"} {		$classifier_ set reroute_option_ 2        } else {		$classifier_ set reroute_option_ 0	}}RtModule/MPLS instproc reroute-binding {fec phb lspid} {        [$self set classifier_] aPathBinding $fec $phb -1 $lspid}RtModule/MPLS instproc lookup-nexthop {node fec} {        set ns [Simulator instance]        set routingtable [$ns get-routelogic]        set nexthop [$routingtable lookup $node $fec]        return $nexthop}RtModule/MPLS instproc get-nexthop {fec} {	# find a next hop for fec        set nodeid [[$self node] id]        set nexthop [$self lookup-nexthop $nodeid $fec]        return $nexthop}RtModule/MPLS instproc get-link-status {hop} {	if {$hop < 0} {		return "down"	}	set nexthop [$self get-nexthop $hop]	if {$nexthop == $hop} {		set status "up"	} else {		set status "down"	}	return $status}RtModule/MPLS instproc is-egress-lsr { fec } {        # Determine whether I am a egress-lsr for fec.         if { [[$self node] id] == $fec } {		return  "1"        }        set nexthopid [$self get-nexthop $fec]        if { $nexthopid < 0 } {		return "-1"        }        set nexthop [[Simulator instance] get-node-by-id $nexthopid]	if { [$nexthop get-module "MPLS"] == "" } {		return  "1"        } else {		return  "-1"        }}# distribute labels based on routing protocolRtModule/MPLS instproc ldp-trigger-by-routing-table {} {        if { [[$self set classifier_] cmd control-driven?] != 1 } {		return        }        set ns [Simulator instance]	for {set i 0} {$i < [$ns get-number-of-nodes]} {incr i} {		# select a node		set host [$ns get-node-by-id $i]		if { [$self is-egress-lsr [$host id]] == 1 } {			# distribute label			$self ldp-trigger-by-control [$host id] *		}        }}RtModule/MPLS instproc ldp-trigger-by-control {fec pathvec} {	lappend pathvec [[$self node] id]	set inlabel [$self get-incoming-label $fec -1]	set nexthop [$self get-nexthop $fec]	set ldpagents [lsort [$self get-ldp-agents]]	for {set i 0} {$i < [llength $ldpagents]} {incr i 1} {		set ldpagent [lindex $ldpagents $i]		if { [$ldpagent peer-ldpnode] == $nexthop } {			continue		}		if { $inlabel == -1 } {			if { [$self is-egress-lsr $fec] == 1 } {				# This is egress LSR				set inlabel 0			} else {				set inlabel [$self new-incoming-label]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?