Server.pm

filter: Statementstmt 42.4% 14 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 38.8% 21 / 54 CC 5 SCAR 26.6
CC
5
Cov
33%
process_request
30.0
vmps_request
2.0
default_values
2.0
CRAP 14.4
« Packet.pm ↑ Summary
1 package VMPS::Server;
2 2 ▶use base qw[ Net::Server::PreFork ];
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use VMPS::Packet;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 VMPS::Server - VLAN Membership Policy Server
11  
12 This package implements a VMPS server. For more information on VMPS
13 itself, consult the Cisco web site:
14  
15 http://www.cisco.com/
16  
17 =head1 VERSION
18  
19 Version 0.04
20  
21 =cut
22  
23 2 our $VERSION = '0.04';
24  
25  
26 =head1 SYNOPSIS
27  
28 package My::VMPSServer;
29 use base qw/VMPS::Server/;
30  
31 sub vmps_request{ ... }
32  
33 __PACKAGE__->run();
34  
35 =head1 HANDLING REQUESTS
36  
37 =head2 vmps_request()
38  
39 Child modules should implement the vmps_request method. The method should
40 return a VMPS::Packet response object. The default behavior is to reject
41 all requests. For more info, see L<VMPS::Packet>.
42  
43 sub vmps_request {
44 my ($this, $packet, $from_ip) = @_;
45 ....
46 return $packet->reply(...);
47 }
48  
49 =cut
50  
51 0 ▶sub vmps_request {
Subroutine vmps_request: not called CC=1 SCAR=6.9
Pod documented
52 0 my ($this, $packet, $from_ip) = @_;
53 0 return $packet->reject;
54 }
55  
56 =head1 DEFAULTS
57  
58 The module listens on the "vqp" port (1589/udp), on all interfaces.
59  
60 =cut
61  
62 0 ▶sub default_values {
Subroutine default_values: not called CC=1 SCAR=6.9
Pod documented
63 return {
64 0 port => '1589',
65 host => '*',
66 proto => 'udp',
67 }
68 }
69  
70 #################################################################
71  
72 0 ▶sub process_request {
Subroutine process_request: not called CC=5 SCAR=34.0
Pod documented
73 0 my $this = shift;
74 0 my $client = $this->{server}{client}->peerhost();
75 0 my $dgram = $this->{server}{udp_data};
76  
77 0 my $request = eval { VMPS::Packet->_decode($dgram) };
78 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
79 {
80 0 $this->log(1, "(Request from $client) $@");
81 0 return;
82 }
83  
84 0 eval {
85 0 my $reply = $this->vmps_request($request, $client);
86  
87 0 ▶ $reply = $request->reject
Branch: 1 branch
BranchTrueFalseTotal
unless $reply and UNIVERSAL::isa($reply, "VMPS::Packet") 0 0 0
Condition0%0/3
$reply and UNIVERSAL::isa($reply, "VMPS::Packet")
!ll&&!rl&&r
000
MC/DC0%0/2
$reply and UNIVERSAL::isa($reply, "VMPS::Packet")
$reply UNIVERSAL::isa($reply, "VMPS::Packet")
Truth table0%0/3
A and B
A= $replyB= UNIVERSAL::isa($reply, "VMPS::Packet")
ABresult
0X0
100
111
88 unless ($reply and UNIVERSAL::isa($reply, 'VMPS::Packet'));
89  
90 0 my $reply_pkt = $reply->_encode;
91 0 $this->{server}{client}->send($reply_pkt);
92 };
93 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
94 {
95 0 $this->log(1, "(Reply to $client) $@");
96 0 return;
97 }
98 }
99  
100 #################################################################
101  
102 =head1 CUSTOMIZING
103  
104 This module inherits its behavior from L<Net::Server>. Sub-classes may
105 implement any of the hooks/arguments from Net::Server in order to
106 customize their behavior. For more information, see the documentation for
107 L<Net::Server>.
108  
109 =head1 AUTHOR
110  
111 kevin brintnall, C<< <kbrint at rufus.net> >>
112  
113 =head1 ACKNOWLEDGEMENTS
114  
115 The packet handling code is based on VQP spec documentation from the
116 OpenVMPS project. For more information, see:
117  
118 http://vmps.sourceforge.net/
119  
120 =head1 COPYRIGHT & LICENSE
121  
122 Copyright 2008 kevin brintnall, all rights reserved.
123  
124 This program is free software; you can redistribute it and/or modify it
125 under the same terms as Perl itself.
126  
127  
128 =cut
129  
130 2 1; # End of VMPS::Server
« Packet.pm ↑ Summary