Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Teach the Perl example code the <map> and <unmap> commands

  • Loading branch information...
commit 67481b2678a409d4a83cc519f9b66715848792fd 1 parent feff8c1
@matthiasl authored
View
22 perl/README
@@ -9,7 +9,7 @@ Keep in mind that I'm a Perl dabbler, i.e. if it looks weird, then
that's most likely because I didn't know better. Suggestions for
improvement are welcome to matthias@corelatus.se
-There are four examples:
+There are six examples:
Recorded file playback
----------------------
@@ -81,7 +81,25 @@ Enable L1
Enable Layer 1 on SDH/SONET and E1/T1 hardware. Typical use:
- >./enable 172.16.11.9 sdh1
+ >./enable.pl 172.16.11.9 sdh1
+
+Map and unmap E1/T1 links carried on SDH/SONET
+----------------------------------------------
+
+ This example is only useful on SDH/SONET hardware. It's used
+ to get access to E1/T1 links carried on SDH/SONET.
+
+ >./map.pl 172.16.1.10 sdh1:hop1_1:lop1_1_1
+ pcm1
+
+ the 'pcm1' is the dynamically assigned name of the E1/T1 link.
+ Once you've got a name assigned, you can use it, e.g.:
+
+ >./enable.pl 172.16.1.10 pcm1
+
+ When you're finished, you can clean up:
+
+ >./unmap.pl 172.16.1.10 pcm1
The examples are built on top of a little library, gth_command.pm,
View
46 perl/gth_control/lib/gth_control.pm
@@ -59,6 +59,15 @@ sub enable {
expect_xml($parsed, "ok", "enable failed");
}
+sub map {
+ my ($self, $resource) = @_;
+
+ $self->send("<map target_type='pcm_source'>".
+ "<sdh_source name='$resource'/></map>");
+ my $resource_id = parse_resource_name($self->next_non_event());
+ return $resource_id;
+}
+
sub new_mtp2_monitor {
my ($self, $span, $timeslot) = @_;
@@ -171,6 +180,15 @@ sub set {
defined $parsed->{"ok"} || die("set failed");
}
+sub unmap {
+ my ($self, $resource) = @_;
+
+ $self->send("<unmap name='$resource'/>");
+ my $parsed = $self->next_non_event();
+
+ expect_xml($parsed, "ok", "unmap failed");
+}
+
#-- Internal functions.
@@ -193,6 +211,15 @@ sub parse_job_id {
return (keys %$hashref)[0];
}
+sub parse_resource_name {
+ my ($parsed) = @_;
+
+ defined($parsed->{'resource'}) || die(Dumper($parsed));
+
+ my $hashref= $parsed->{'resource'};
+ return (keys %$hashref)[0];
+}
+
sub send {
my ($self, $data, $type) = @_;
my $s = $self->{SOCKET};
@@ -275,7 +302,9 @@ E1/T1 line to decode signalling, record or play back voice, detect
tones or connect timeslots.
A GTH is controlled through a socket using a text protocol. This
-module wraps that text protocol in a Perl API.
+module wraps that text protocol in a Perl API. The function names map
+1:1 to the commands in the API, e.g. new_mtp_monitor() corresponds to
+the <new><mtp2_monitor>... command.
=head1 CONSTRUCTOR
@@ -299,8 +328,18 @@ module wraps that text protocol in a Perl API.
Delete (stop) a job on the GTH.
+=item enable (Resource, Attributes)
+
+ The <enable> command.
+
+=item map (Resource, Attributes)
+
+ The <map> command.
+
=item new_mtp2_monitor (Span, Timeslot)
+ The <new><mtp2_monitor> command.
+
Commands the GTH to start decoding MTP-2 on the given timeslot.
Returns a job identifier (needed to delete the MTP-2 decoding job)
@@ -346,6 +385,11 @@ module wraps that text protocol in a Perl API.
Multiple Attribute, Value pairs can be given.
+=item unmap (Resource, Attributes)
+
+ The <unmap> command.
+
+
=back
=head1 SEE ALSO
View
38 perl/map.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl -Igth_control/lib/
+#
+# Title: Map an E1/T1 carried on an SDH/SONET link, usually a fiber
+# Author: Matthias Lang (matthias@corelatus.se)
+#
+
+use 5.008; # Probably works with earlier versions too.
+use strict;
+use warnings;
+use gth_control;
+use Data::Dumper;
+
+sub usage() {
+ print("
+map.pl <hostname> <resource>
+
+ <hostname>: the hostname or IP address of a GTH
+ <resource>: an SDH/SONET LOP resource (hint: 'query inventory')
+
+Example:
+ ./map.pl 172.16.1.10 sdh1:hop1_1:lop1_1_1
+
+Output:
+ on success, this program prints the name of the newly mapped resource,
+ e.g. 'pcm1'.
+");
+}
+
+# Entry point
+($#ARGV == 1) || usage() && die();
+
+my ($host, $resource) = @ARGV;
+
+my $api = new gth_control($host);
+my $new_name = $api->map($resource);
+print "$new_name\n";
+
+$api->bye();
View
34 perl/unmap.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -Igth_control/lib/
+#
+# Title: Unmap a previously mapped E1/T1 carried on an SDH/SONET link.
+# Author: Matthias Lang (matthias@corelatus.se)
+#
+
+use 5.008; # Probably works with earlier versions too.
+use strict;
+use warnings;
+use gth_control;
+use Data::Dumper;
+
+sub usage() {
+ print("
+unmap.pl <hostname> <resource>
+
+ <hostname>: the hostname or IP address of a GTH
+ <resource>: a previously mapped E1/T1 (hint: 'query inventory')
+
+Example:
+ ./unmap.pl 172.16.1.10 pcm1
+
+");
+}
+
+# Entry point
+($#ARGV == 1) || usage() && die();
+
+my ($host, $resource) = @ARGV;
+
+my $api = new gth_control($host);
+$api->unmap($resource);
+
+$api->bye();
Please sign in to comment.
Something went wrong with that request. Please try again.