📄 readme.examples
字号:
NOTE: mplsadm2 serves the same purpose as mplsadm did. The reason forcreating mplsadm2 is that the underlying communication mechanism with thekernel changed between mpls-linux-1.0 and mpls-linux-1.1x (switched fromnetlink to IOCTLs)------------------------1. Basic 'mplsadm' usage------------------------This utility can be used to manually create LSPs from the command line.It is also a great example of how to use the IOCTLS calls.Command line usage:usage: mplsadm [ADBUdhvT:FL:I:O:i:o:m:]-A add modifier-B bind modifier-D delete modifier-U unbind modifier-d toggle debug-h this message-v verbose info-T <tunnel name>:<dest addr>-L <interface name>:<label space> set the label space for an interface (-1 disables)-I <gen|atm|fr>:<label>:<label space> create|delete an incoming label-O <key>-i <opcode:opcode_data>+-o <opcode:opcode_data>+-m <mtu>Combinations of command line options:-A/-D can be used with -T -I -O-B/-U can be used with -T and -O, -I and -O-i/-o MUST be used with -I/-O respectivlyExample use of mplsadm:Create an out going label entry with generic label 16 that send packetsout eth0 to the next hop LSR/LER 128.104.17.130.Establish an out going label----------------------------mplsadm -A -O 0 -o push:gen:16:set:eth0:ipv4:128.104.17.130 | | | | | | | | | | | add | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | IP addr of next hop | | | | | | | | | | | | | | | | | following info is ipv4 for the nexthop | | | | | | | | | | | | | | | out going interface | | | | | | | | | | | | | set the next hop info | | | | | | | | | | | label | | | | | | | | | generic label | | | | | | | push a label | | | | | specify the intructions associated with this out label | | | specify a key of 0 when creating a new out label | outgoing label(the key created for this out label is output, alternativly you can look up the key value in /proc/net/mpls_out)Delete the outgoing info------------------------mplsadm -D -O <key>Interface eth0 uses label space 0---------------------------------mplsadm -L eth0:0 | | | | | label space | | | interface name | modify interface label space(if you change the label space to -1, you disable MPLS processing on the interface)Establish incoming label 34 in label space 0--------------------------------------------mplsadm -A -I gen:34:0 | | | | | | | | | label space add | | | | | label | | | generic label | incoming label(if you change the -A to -D you will delete the entry)Establish a label switch path-----------------------------mplsadm -A -B -I gen:34:0 -O <key>Delete a label switch path --------------------------mplsadm -D -B -I gen:34:0 -O <key>Binding a FEC to an outgoing labels (mapping traffic to an LSP)---------------------------------------------------------------Use a patched version of iproute2 (read ../patches/README.iproute2)-----------------2. Simple example----------------- Manual LSP beteen 2 hosts ---------------------------Setup----- --------- --------- | A | | B | --------- --------- |eth0 |eth0 |17.130 |18.114----------------------------------- 128.104.16.0/22Config------On A: mplsadm -A -O 0 mplsadm -O KEY1 -o push:gen:16:set:eth0:ipv4:128.104.18.114 ip route add 128.104.18.114/32 via 128.104.18.114 spec_nh 0x8847 KEY1 mplsadm -A -I gen:17:0 Where KEY1 is in the output from the previous 'mplsadm' commandOn B: mplsadm -A -O 0 mplsadm -O KEY2 -o push:gen:17:set:eth0:ipv4:128.104.17.130 ip route add 128.104.17.130/32 via 128.104.17.130 spec_nh 0x8847 KEY2 mplsadm -A -I gen:16:0 Where KEY2 is in the output from the previous 'mplsadm' commandNow you need to set a label space on eth0 on both A and B. Watch out!if you do this remotely you could saw your leg off!On both: mplsadm -L eth0:0Now all traffic with destination address of A or B use the LSP.-------------------------4. MPLS Tunnel Interfaces-------------------------MPLS tunnels are a way to represent an LSP to traditional routing protocolsor IP services in a way which the understand, as an interface.MPLS tunnels are also one way or doing LSP heiearchy.To create an MPLS tunnel manually:-create an outgoing labelmplsadm -A -O 0 -o push:gen:1024:set:eth1:ipv4:192.168.0.1(key 2)-create an mpls tunnel interfacemplsadm -A -T mpls0-assign an IP address to the tunnel (it can be the same as the true interface it goes out, or maybe as a point-to-point with the IP address of the end of the LSP being used.ifconfig mpls0 192.168.0.2 netmask 255.255.255.255-bind the outgoing label to the tunnelmplsadm -B -O 0x2 -T mpls0-add a route to forward traffic out mpls0route add -net 172.16.0.0/16 mpls0-any traffic to 17.16.0.0/16 now goes out eth1 with label 1024.You can create an outgoing label on an MPLS tunnel interface:-after the tunnel is setup as above, create an outgoing label on mpls0mplsadm -A -O 0 -o push:gen:2048:set:mpls0(key 3)-bind a FEC to it or create another tunnel interface on top of itip route add 172.16.1.0/24 dev mpls0mplsadm -B -O 0x3 -f 172.16.1.0/24 -or-mplsadm -A -T mpls1mplsadm -B -O 0x3 -T mpls1ip route add 172.16.1.0/24 dev mpls1-both options above produce the same affect, any traffic to 172.16.1.0/24 leaved eth1 with the label stack 1024:2048 and any traffic to the less specific 172.16.0.0/16 goes out eth1 with the label 1024.-----------------5. MPLS Hierarchy-----------------LSP Hierarchy can be acrhived via three mechanism:-MPLS tunnel interface-Multiple pushes-forwardingMPLS tunnel interface---------------------see aboveMultiple pushes---------------Conside the simple MPLS network: A------B--------C------Dwhere A,D are LERs and B,C are LSRs. B,C have a LSP setup between them.A,D would like to setup an LSP between them, but THOUGH the existingLSP. This is called hierachtical LSPs.The desired label stacking is: 101 200 201 202 A------B--------C------D(We receive on eth1 and send on eth0)Setup the LSP between A,B: On A: mplsadm -A -O 0 -o push:gen:200:set:eth0:ipv4:B (key 4) On B: mplsadm -L eth1:0 mplsadm -A -I gen:200:0Now setup the LSP between C,D: On C: mplsadm -A -O 0 -o push:gen:202:set:eth0:ipv4:B (key 5) On D: mplsadm -L eth1:0 mplsadm -A -I gen:202:0Now setup the LSP between B and C: On B: mplsadm -A -O 0 -o push:gen:201:push:gen:101:set:eth0:ipv4:C (key 3) On C: mplsadm -L eth1:0 mplsadm -A -I gen:101:0 mplsadm -A -I gen:201:0 mplsadm -I gen:101:0 -i pop:peek *Note: here we see when a peek is for. If a packet arrives with 101 on top of the stack, 101 if popped, and if more labels exist, they are looked up, and there instructions are run, if not labels exist a 'dlv' is executed. If we had use a 'dlv' as oppsed to a peek then all packets with a 101 on top would be send to a layer 3 protocol even if more labels existed.Now tie the three LSPs togther (A,B),(B,C),(C,D): On B: mplsadm -I gen:200:0 -O 0x3 -B On C: mplsadm -I gen:201:0 -O 0x5 -BForwarding----------Considering the same example above:The desired label stacking is: 101 200 201 202 A------B--------C------D(We receive on eth1 and send on eth0)First setup the LSP between B and C: On B: mplsadm -A -O 0 -o push:gen:101:set:eth0:ipv4:C (key 2) On C: mplsadm -L eth1:0 mplsadm -A -I gen:101:0Now setup the LSP between A,B: On A: mplsadm -A -O 0 -o push:gen:200:set:eth0:ipv4:B (key 3) On B: mplsadm -L eth1:0 mplsadm -A -I gen:200:0Now setup the LSP between C,D: On C: mplsadm -A -O 0 -o push:gen:202:set:eth0:ipv4:D (key 4) On D: mplsadm -L eth1:0 mplsadm -A -I gen:202:0Now setup another LSP between B,C: On B: mplsadm -A -O 0 -o push:gen:201:set:eth0:ipv4:C (key 5) On C: mplsadm -A -I gen:201:0Forward traffic for the 201 LSP to ride on the 101 LSP: On B: mplsadm -O 0x5 -o push:gen:201:fwd:0x2 On C: mplsadm -I gen:101:0 -i pop:peekTie the LSPs together: On B: mplsadm -B -I gen:200:0 -O 0x5 On C: mplsadm -B -I gen:201:0 -O 0x4---------------------------------6. MPLS forwarding "Instructions"---------------------------------Inside the kernel the processing of MPLS packets and their label stacksis down via "instructions". By adding in and out labels and switch pathsyou are modifing these instructions. Sometimes it is useful to be ableto override these instructions, one specific case is when you want tosend or receive packets with a label stack of size greater then 1.Incoming labels and outgoing labels each have a set of instructions thatcan be executed. Certain instructions are only valid for incoming oroutgoing labels.List of MPLS instructions--------------------------pop - remove the top label from the label stack. (in/out)-peek - look at the label on top of the label stack, look the label up in the list of incoming label for this interface, and start executing the instructions associated with it. If there is not a label, execute a dlv. (in)-push - push another label on the label stack. (in/out)-dlv - send this packet to the layer 3 protocol stored with this in label. (in)-fwd - send a packet to an outgoing label structure to be processed (in/out)-nffwd - mask:nf:key:nf:key-dsfwd - mask:ds:key:ds:key-expfwd - exp:key:exp:key-set_ds - ds-set_tc - tc-set_exp - exp-set - last step before transmitting a MPLS packet. It copies the outgoing interface and the next hop layer 2 destination from the out going label structure. (out) - set the incoming interface to somethgin diffetn then the REAL incoming interface (in)-exp2tc - exp:tc:exp:tc-exp2ds - exp:tc:exp:ds-nf2exp - mask:nf:exp:nf:exp-tc2exp - mask:tc:exp:tcp:exp-ds2exp - mask:ds:exp:ds:expFormat of each instruction--------------------------Incoming instructions---------------------poppush:<label type>:<value>dlvpeekset:<interface>:<nh famliy>:<next hop>fwd:<key>Outgoing instructions---------------------push:<label type>:<value>set:<interface>:<nh famliy>:<next hop>fwd:<key>*Note: when using 'fwd' you are referencing an outgoing label key*Note: when using 'push' you can push any label values you would like. Theydo not need to exist in any table, nor do they have to correspond to thelabel structure your operating on.By adding in or out labels and switch paths your already setting upinstructions. Here are some examples and what the resulting structureand instrustions are:mplsadm -A -I gen:34:0-----------------------create an in label structure with a key of (gen,34,0)-set the instructions in the in label structure to be: pop:peek-set the layer 3 protocol to be IPv4mplsadm -A -O 0----------------create an out label structure with no instructionsmplsadm -B -I gen:34:0 -O <key>--------------------------------lookup in label structure with key (gen,34,0)-lookup out label structure with key (gen,16,eth0)-set the instructions in the in label structure to be: pop:fwd:<key>-the out label structures instructions do not changeThe command line usage for instructions is straigh forward:mpls -I gen:34:0 -i pop:dlvmpls -O <key> -o push:gen:16:setmpls -I gen:34:0 -i pop:fwd:gen:16:eth0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -