ContextRouter.pm

filter: Statementstmt 42.4% 14 / 33 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 40.0% 4 / 10 Podpod 83.3% 5 / 6 totaltotal 37.7% 23 / 61 CC 5 SCAR 20.1
CC
5
Cov
33%
new
20.0
context
6.0
add_peer
2.0
CRAP 7.4
« RIBEntry.pm ↑ Summary Policy.pm »
1 #!/usr/bin/perl
2  
3 # $Id: ContextRouter.pm,v 1.3 2003/06/02 11:58:05 unimlo Exp $
4  
5 package Net::BGP::ContextRouter;
6  
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ## Inheritance and Versioning ##
13  
14 1 $VERSION = '0.04';
15  
16 1 ▶use Net::BGP::Router;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 sub new
19 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
20 0 ▶ my $proto = shift || __PACKAGE__;
Condition0%0/2
shift() || __PACKAGE__
l!l
00
MC/DC0%0/1
shift() || __PACKAGE__
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
21 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
22  
23 0 my $this = {
24 _contexts => {}
25 };
26  
27 0 ▶ while ( defined(my $arg = shift) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $arg = shift())) 0 0 0
28 {
29 0 my $value = shift;
30 0 croak "unrecognized argument $arg\n";
31 };
32  
33 0 bless($this, $class);
34 0 return $this;
35 }
36  
37 sub context
38 0 ▶{
Subroutine context: not called CC=2 SCAR=17.9
Pod documented
39 0 my ($this,$context) = @_;
40 $this->{_contexts}->{$context} = new Net::BGP::Router(Name => $context)
41 0 ▶ unless defined($this->{_contexts}->{$context});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"_contexts"}{$context} 0 0 0
42 0 return $this->{_contexts}->{$context};
43 }
44  
45 sub add_peer
46 0 ▶{
Subroutine add_peer: not called CC=1 SCAR=6.9
Pod documented
47 0 my ($this,$context,$peer,$dir,$acl) = @_;
48 0 $this->context($context)->add_peer($peer,$dir,$acl);
49 }
50  
51 sub remove_peer
52 0 ▶{
Subroutine remove_peer: not called CC=1 SCAR=6.9
Pod documented
53 0 my ($this,$context,@args) = @_;
54 0 $this->context($context)->remove_peer(@args);
55 }
56  
57 sub set_policy
58 0 ▶{
Subroutine set_policy: not called CC=1 SCAR=6.9
Pod documented
59 0 my ($this,$context,@args) = @_;
60 0 $this->context($context)->set_policy(@args);
61 }
62  
63 sub remove_context
64 0 ▶{
Subroutine remove_context: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my ($this,$context) = @_;
66 0 delete $this->{_context}->{$context};
67 }
68  
69 =pod
70  
71 =head1 NAME
72  
73 Net::BGP::ContextRouter - A Multiple Context BGP Router
74  
75 =head1 SYNOPSIS
76  
77 use Net::BGP::ContextRouter;
78  
79 # Constructor
80 $crouter = new Net::BGP::ContextRouter();
81  
82 # Accessor Methods
83 $router = $crouter->context($context);
84  
85 $crouter->add_peer($context,$peer,'both',$acl);
86 $crouter->remove_peer($context,$peer,'both');
87 $crouter->set_policy($context,$policy);
88 $crouter->set_policy($context,$peer,'in',$acl);
89  
90  
91 =head1 DESCRIPTION
92  
93 This module implements a multiple-context BGP router using the
94 L<Net::BGP::Router|Net::BGP::Router> object.
95  
96 =head1 CONSTRUCTOR
97  
98 =over 4
99  
100 =item new() - create a new Net::BGP::ContextRouter object
101  
102 $router = new Net::BGP::ContextRouter();
103  
104 This is the constructor for Net::BGP::ContextRouter object. It returns a
105 reference to the newly created object. No arguments are allowed.
106  
107 =back
108  
109 =head1 ACCESSOR METHODS
110  
111 =over 4
112  
113 =item context()
114  
115 Return a given context. If the context doesn't exist, it will be created.
116 The argument is the name of the context. The Net::BGP::Router object
117 representing the context is returned.
118  
119 =item add_peer()
120  
121 =item remove_peer()
122  
123 =item set_policy()
124  
125 Just like Net::BGP::Router->add_peer() but with the context name as the first
126 argument.
127  
128 =back
129  
130 =head1 SEE ALSO
131  
132 Net::BGP::Router, Net::BGP, Net::BGP::Policy
133  
134 =head1 AUTHOR
135  
136 Martin Lorensen <bgp@martin.lorensen.dk>
137  
138 =cut
139  
140 ## End of Net::BGP::ContextRouter ##
141  
142 1 1;
« RIBEntry.pm ↑ Summary Policy.pm »