Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This should give you a clean start.

I suppose you'll be able to adjust the methods to your needs.

Especially ->__out__ where you can write the new format based on the already parsed data.

Based on the limited insight I have, I tried to keep it as generic as possible.

YMMV but HTH! :)

# https://perlmonks.org/index.pl?node_id=11132953 use strict; use warnings; use Data::Dump qw/pp dd/; my $obj = "CiscoService"; while (<DATA>) { chomp; my ($indent,$data) = /^(\s*)(.*)$/; my ($call, @args) = split/\s+/, $data; $call =~ s/^!$/__out__/; $call =~ s/-/_/g; if ( my $meth = $obj->can($call) ) { $obj = $meth->( $obj, length($indent),@args) } else { warn "<$call> not impemented"; } } package CiscoService; use Data::Dump qw/pp dd/; sub service { my ($self,$indent,@args) = @_; return bless {__head__ => \@args, sub=>{} },__PACKAGE__; } sub description { my ($self,$indent,@args) = @_; $self->{sub}{description} = \@args; return $self; } sub service_policy { my ($self,$indent,@args) = @_; $self->{sub}{"service-policy"} = \@args; return $self; } sub encapsulation { my ($self,$indent,@args) = @_; $self->{sub}{encapsulation} = \@args; return $self; } sub rewrite { my ($self,$indent,@args) = @_; $self->{sub}{rewrite} = \@args; return $self; } sub xconnect { my ($self,$indent,@args) = @_; $self->{sub}{xconnect} = {head =>\@args, sub=>{}}; return $self; } sub mtu { my ($self,$indent,@args) = @_; $self->{sub}{xconnect}{sub}{mtu} = \@args; return $self; } sub __out__ { my ($self,$indent,@args) = @_; pp $self; return "CiscoService"; } package main; __DATA__ service instance 20 ethernet description Internal site encapsulation dot1q 17 rewrite ingress tag pop 1 symmetric xconnect 192.168.51.20 838969735 encapsulation mpls mtu 9202 ! service instance 21 ethernet description Client 1 important encapsulation dot1q 18 rewrite ingress tag pop 1 symmetric xconnect 192.168.51.21 838969736 encapsulation mpls mtu 9202 ! service instance 22 ethernet description Client other 2 encapsulation dot1q 22 rewrite ingress tag pop 1 symmetric xconnect 192.168.56.22 838925386 encapsulation mpls mtu 9202 ! service instance 23 ethernet description Client name with fun stuff encapsulation dot1q 3200 second-dot1q 5 rewrite ingress tag pop 2 symmetric service-policy input CoS_222_333_23 xconnect 192.168.56.23 571125465 encapsulation mpls mtu 9202 ! service instance 24 ethernet description Client - not as important encapsulation dot1q 3200 second-dot1q 6 rewrite ingress tag pop 2 symmetric service-policy input 222_444_24 xconnect 192.168.56.24 571637077 encapsulation mpls mtu 9202 !

bless({ __head__ => ["instance", 20, "ethernet"], sub => { description => ["Internal", "site"], encapsulation => ["dot1q", 17], rewrite => ["ingress", "tag", "pop", 1, "symmetric"], xconnect => { head => ["192.168.51.20", 838969735, "encapsula +tion", "mpls"], sub => { mtu => [9202] }, }, }, }, "CiscoService") bless({ __head__ => ["instance", 21, "ethernet"], sub => { description => ["Client", 1, "important"], encapsulation => ["dot1q", 18], rewrite => ["ingress", "tag", "pop", 1, "symmetric"], xconnect => { head => ["192.168.51.21", 838969736, "encapsula +tion", "mpls"], sub => { mtu => [9202] }, }, }, }, "CiscoService") bless({ __head__ => ["instance", 22, "ethernet"], sub => { description => ["Client", "other", 2], encapsulation => ["dot1q", 22], rewrite => ["ingress", "tag", "pop", 1, "symmetric"], xconnect => { head => ["192.168.56.22", 838925386, "encapsula +tion", "mpls"], sub => { mtu => [9202] }, }, }, }, "CiscoService") bless({ __head__ => ["instance", 23, "ethernet"], sub => { "description" => ["Client", "name", "with", "fun", "stuff"], "encapsulation" => ["dot1q", 3200, "second-dot1q", 5], "rewrite" => ["ingress", "tag", "pop", 2, "symmetric"], "service-policy" => ["input", "CoS_222_333_23"], "xconnect" => { head => ["192.168.56.23", 571125465, "encaps +ulation", "mpls"], sub => { mtu => [9202] }, }, }, }, "CiscoService") bless({ __head__ => ["instance", 24, "ethernet"], sub => { "description" => ["Client", "-", "not", "as", "important"], "encapsulation" => ["dot1q", 3200, "second-dot1q", 6], "rewrite" => ["ingress", "tag", "pop", 2, "symmetric"], "service-policy" => ["input", "222_444_24"], "xconnect" => { head => ["192.168.56.24", 571637077, "encaps +ulation", "mpls"], sub => { mtu => [9202] }, }, }, }, "CiscoService")

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re: Cisco to Juniper - parser help by LanX
in thread Cisco to Juniper - parser help by jamescmatt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-25 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found