[36655] in North American Network Operators' Group
RE: Router Servers in a lab
daemon@ATHENA.MIT.EDU (Yosi Yarchi)
Thu Apr 12 13:45:24 2001
Message-ID: <2B15221907365C468941FDFC02C8776940B845@EXCHANGE.kerenix.com>
From: Yosi Yarchi <Yosi_Yarchi@KereniX.com>
To: Yosi Yarchi <Yosi_Yarchi@KereniX.com>,
'mike harrison' <meuon@highertech.net>,
'Barrie Jones' <bjones@digisle.net>
Cc: 'Perry Jannette' <perry.jannette@usa.net>,
'Nanog1' <nanog@merit.edu>
Date: Thu, 12 Apr 2001 20:37:14 +0300
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----_=_NextPart_000_01C0C377.3684FE80"
Errors-To: owner-nanog-outgoing@merit.edu
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C0C377.3684FE80
Content-Type: text/plain;
charset="iso-8859-1"
Sorry, I forgot the files
Best Regards,
Yosi Yarchi
KereniX Data-Aware Optical NetworksTM
----------------------------------------------------------------------------
------
Yosi Yarchi http://www.kerenix.com
Phone: +972-3-9050783 Mobile: 972-58-512783
Fax: +972-3-9347720
mailto:yosi_yarchi@kerenix.com
> 70 Pinsker St., Petach-Tikva 49221 ISRAEL
----------------------------------------------------------------------------
------
> -----Original Message-----
> From: Yosi Yarchi
> Sent: Thu, April 12, 2001 8:36 PM
> To: 'mike harrison'; Barrie Jones
> Cc: Perry Jannette; Nanog1
> Subject: RE: Router Servers in a lab
>
>
> Hi
>
> I'm using mrtd for this purpose exactly. To begin with, I
> wrote small PERL script (route_stoa.pl) which takes "show ip
> bgp" output of cisco router (default free, found in the
> internet) and convert it to mrtd ASCII format. Then I patched
> the route_atob (route_atob.c) of mrtd package to read this
> file. I used sbgp to inject the full table into my router.
> Assuming that the "show ip bgp" dump file is ASproc.pl (this
> is actually the name I found it), the command should be
> (after trimming ASproc so only pure table exist):
>
> gunzip --stdout ASproc.pl | route_stoa.pl -i stdin -o stdout
> | route_atob -i stdin -o stdout | sbgp -i stdin ....
>
> Good luck
>
> Best Regards,
> Yosi Yarchi
>
> KereniX Data-Aware Optical
> NetworksTM
> --------------------------------------------------------------
> --------------------
> Yosi Yarchi http://www.kerenix.com
> Phone: +972-3-9050783 Mobile: 972-58-512783
> Fax: +972-3-9347720
> mailto:yosi_yarchi@kerenix.com
> > 70 Pinsker St., Petach-Tikva 49221 ISRAEL
> --------------------------------------------------------------
> --------------------
>
>
>
> > -----Original Message-----
> > From: mike harrison [mailto:meuon@highertech.net]
> > Sent: Wed, April 11, 2001 6:27 AM
> > To: Barrie Jones
> > Cc: Perry Jannette; Nanog1
> > Subject: Re: Router Servers in a lab
> >
> >
> >
> > > i like mrtd better anyway, since it has the bgpsim tool.
> > it allows you
> > > to withdraw and announce routes to simulate flapping. has
> > frequency,
> > > jitter, all that fun stuff.
> > > (see www.mrtd.net)
> >
> > Downloading.... :) --Thanks
> >
> >
>
------_=_NextPart_000_01C0C377.3684FE80
Content-Type: application/octet-stream;
name="route_atob.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="route_atob.c"
/* =0A=
* $Id: route_atob.c,v 1.12.2.1 2000/01/15 14:20:04 masaki Exp $=0A=
*/=0A=
=0A=
#include <mrt.h>=0A=
#include <bgp.h>=0A=
#include <ctype.h>=0A=
=0A=
static void=0A=
adjust_y2k (struct tm *tm)=0A=
{=0A=
/* if the year is 0 thru 68, it is treated as 21st centry */=0A=
if (tm->tm_year <=3D 68)=0A=
tm->tm_year +=3D 100;=0A=
}=0A=
=0A=
#ifndef HAVE_STRPTIME=0A=
=0A=
/*=0A=
* Please be careful because this function doesn't consult the =
format.=0A=
* This only parses "MM/DD/YY HH:MM:SS" like 05/06/96 23:55:10.=0A=
*/=0A=
=0A=
static char *=0A=
strptime (char *buf, const char *format, struct tm *tm)=0A=
{=0A=
=0A=
static char *tm_zone =3D NULL;=0A=
static long tm_gmtoff =3D 0;=0A=
static int tm_isdst =3D 0;=0A=
=0A=
if (strlen (buf) < 17)=0A=
return (NULL);=0A=
=0A=
if (tm_zone =3D=3D NULL && tm_gmtoff =3D=3D 0) {=0A=
struct tm *tmp;=0A=
time_t now;=0A=
time (&now);=0A=
tmp =3D localtime (&now);=0A=
tm_isdst =3D tmp->tm_isdst;=0A=
tm_gmtoff =3D tmp->tm_gmtoff;=0A=
tm_zone =3D strdup (tmp->tm_zone);=0A=
}=0A=
buf[2] =3D buf[5] =3D buf[8] =3D buf[11] =3D buf[14] =3D '\0';=0A=
tm->tm_mon =3D atoi (buf + 0) - 1;=0A=
tm->tm_mday =3D atoi (buf + 3);=0A=
tm->tm_year =3D atoi (buf + 6);=0A=
tm->tm_hour =3D atoi (buf + 9);=0A=
tm->tm_min =3D atoi (buf + 12);=0A=
tm->tm_sec =3D atoi (buf + 15);=0A=
tm->tm_gmtoff =3D tm_gmtoff;=0A=
tm->tm_zone =3D tm_zone;=0A=
=0A=
return (buf + 17);=0A=
}=0A=
=0A=
#endif /* HAVE_STRPTIME */=0A=
=0A=
=0A=
static char *=0A=
checkstradvance (char *cp, char *s)=0A=
{=0A=
int len =3D strlen (s);=0A=
if (strncasecmp (cp, s, len) =3D=3D 0) {=0A=
if (cp[len] =3D=3D '\0') {=0A=
return (cp + len);=0A=
}=0A=
if (cp[len] =3D=3D ':' || isspace (cp[len])) {=0A=
do {=0A=
len++;=0A=
} while (isspace (cp[len]));=0A=
return (cp + len);=0A=
}=0A=
return (NULL);=0A=
}=0A=
return (NULL);=0A=
}=0A=
=0A=
=0A=
static int=0A=
nulline (char *cp)=0A=
{=0A=
while (isspace (*cp))=0A=
cp++;=0A=
if (*cp =3D=3D '\0')=0A=
return (1);=0A=
return (0);=0A=
}=0A=
=0A=
=0A=
static void =0A=
trace_mrt_header (trace_t *tr, time_t tstamp, int type, int subtype)=0A=
{ =0A=
char *stime, **cpp;=0A=
=0A=
stime =3D my_strftime (tstamp, "%D %T");=0A=
trace (TR_TRACE, tr, "TIME: %s\n", stime);=0A=
if ((cpp =3D S_MRT_MSG_SUBTYPES[type]) !=3D NULL)=0A=
trace (TR_TRACE, tr, "TYPE: %s/%s\n",=0A=
S_MRT_MSG_TYPES[type], cpp[subtype]);=0A=
else =0A=
trace (TR_TRACE, tr, "TYPE: %s\n", S_MRT_MSG_TYPES[type]);=0A=
Delete (stime);=0A=
} =0A=
=0A=
=0A=
static void=0A=
flushout (io_t *io, time_t tstamp, int type, int subtype, bgp_attr_t =
*attr, =0A=
LINKED_LIST *ll_ann, LINKED_LIST *ll_with, gateway_t *gateway_to)=0A=
{=0A=
u_char *cp;=0A=
int size;=0A=
=0A=
trace_mrt_header (MRT->trace, tstamp, type, subtype);=0A=
cp =3D bgp_create_update_msg (type, subtype, &size, attr, ll_ann, =
ll_with, =0A=
gateway_to);=0A=
io_write (io, tstamp, type, subtype, size, (char *) cp);=0A=
Delete (cp);=0A=
trace (TR_TRACE, MRT->trace, "write %d bytes\n", size);=0A=
trace (TR_TRACE, MRT->trace, "\n");=0A=
}=0A=
=0A=
=0A=
static void=0A=
flushout2 (io_t *io, time_t tstamp, int type, int subtype,=0A=
u_char *bgp_packet, int len, =0A=
gateway_t *gateway_from, gateway_t *gateway_to)=0A=
{=0A=
u_char *cp =3D bgp_packet;=0A=
int size =3D len;=0A=
=0A=
trace_mrt_header (MRT->trace, tstamp, type, subtype);=0A=
cp =3D bgp_create_update_msg2 (type, subtype, &size, cp,=0A=
gateway_from, gateway_to);=0A=
io_write (io, tstamp, type, subtype, size, (char *) cp);=0A=
Delete (cp);=0A=
trace (TR_TRACE, MRT->trace, "write %d bytes\n", size);=0A=
trace (TR_TRACE, MRT->trace, "\n");=0A=
}=0A=
=0A=
=0A=
static void =0A=
read_ascii (FILE *fd, io_t *IO)=0A=
{=0A=
LINKED_LIST *ll_ann, *ll_with;=0A=
bgp_attr_t *attr;=0A=
int announce_flag =3D 0;=0A=
int line_num =3D 0;=0A=
int have_data =3D 0;=0A=
int have_data2 =3D 0;=0A=
time_t tstamp =3D 0;=0A=
int type =3D 0;=0A=
int subtype =3D 0;=0A=
int bgptype =3D 0;=0A=
int newtype =3D 0;=0A=
gateway_t *gateway_from =3D NULL;=0A=
gateway_t *gateway_to =3D NULL;=0A=
int first =3D 1;=0A=
u_char bgp_packet[BGPMAXPACKETSIZE], *bp =3D bgp_packet;=0A=
u_char buffer[MAX_MSG_SIZE], *buffer_p =3D buffer;=0A=
u_char *end =3D buffer + sizeof (buffer);=0A=
int eof =3D 0;=0A=
buffer_t *stdbuf;=0A=
=0A=
int state1 =3D 0, state2 =3D 0;=0A=
=0A=
int version =3D 0, as =3D 0, holdtime =3D 0, optlen =3D 0;=0A=
u_long id =3D 0;=0A=
=0A=
int code =3D 0, subcode =3D 0;=0A=
=0A=
int viewno =3D 0;=0A=
char *filename =3D NULL;=0A=
=0A=
prefix_t *route_prefix =3D NULL;=0A=
time_t originated =3D 0;=0A=
u_long status =3D 0;=0A=
int seq_num =3D 0;=0A=
=0A=
attr =3D bgp_new_attr (PROTO_BGP);=0A=
ll_ann =3D LL_Create (LL_DestroyFunction, Deref_Prefix, 0);=0A=
ll_with =3D LL_Create (LL_DestroyFunction, Deref_Prefix, 0);=0A=
=0A=
stdbuf =3D New_Buffer_Stream (fd);=0A=
for (;;) {=0A=
char *line =3D NULL, *ret =3D NULL;=0A=
int len =3D 0;=0A=
int ok =3D 0;=0A=
char *cp;=0A=
=0A=
if (buffer_gets (stdbuf) <=3D 0) {=0A=
eof++;=0A=
}=0A=
else {=0A=
len =3D buffer_data_len (stdbuf);=0A=
line =3D buffer_data (stdbuf);=0A=
=0A=
if (line[len - 1] =3D=3D '\n') {=0A=
line[len - 1] =3D '\0';=0A=
len--;=0A=
}=0A=
trace (TR_TRACE, MRT->trace, "++%s\n", line);=0A=
line_num++;=0A=
=0A=
if ((cp =3D strpbrk (line, "#!")) !=3D NULL) {=0A=
*cp =3D '\0';=0A=
len =3D cp - line;=0A=
}=0A=
=0A=
if (first && nulline (line))=0A=
continue;=0A=
first =3D 0;=0A=
}=0A=
=0A=
if (eof || nulline (line)) {=0A=
if (have_data && have_data2) {=0A=
trace (TR_ERROR, MRT->trace, "Mixture of two formats\n");=0A=
goto error;=0A=
}=0A=
if (bgptype =3D=3D BGP_UPDATE && have_data) {=0A=
flushout (IO, tstamp, type, subtype, attr, ll_ann, ll_with, =0A=
gateway_to);=0A=
}=0A=
else if (have_data2) {=0A=
flushout2 (IO, tstamp, type, subtype, =0A=
bgp_packet, bp - bgp_packet, =0A=
gateway_from, gateway_to);=0A=
}=0A=
else if (bgptype =3D=3D BGP_KEEPALIVE) {=0A=
if (type =3D=3D MSG_PROTOCOL_BGP4MP) {=0A=
memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN);=0A=
BGP_PUT_HDRTYPE (bgptype, bgp_packet);=0A=
bp =3D bgp_packet + BGP_HEADER_LEN;=0A=
BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet);=0A=
}=0A=
else {=0A=
bp =3D bgp_packet;=0A=
}=0A=
flushout2 (IO, tstamp, type, subtype, =0A=
bgp_packet, bp - bgp_packet, =0A=
gateway_from, gateway_to);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN) {=0A=
if (type =3D=3D MSG_PROTOCOL_BGP4MP) {=0A=
memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN);=0A=
BGP_PUT_HDRTYPE (bgptype, bgp_packet);=0A=
bp =3D bgp_packet + BGP_HEADER_LEN;=0A=
}=0A=
else {=0A=
bp =3D bgp_packet;=0A=
}=0A=
BGP_PUT_BYTE (version, bp);=0A=
BGP_PUT_SHORT (as, bp);=0A=
BGP_PUT_SHORT (holdtime, bp);=0A=
BGP_PUT_NETLONG (id, bp);=0A=
BGP_PUT_BYTE (0, bp); /* XXX */=0A=
if (type =3D=3D MSG_PROTOCOL_BGP4MP) {=0A=
BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet);=0A=
}=0A=
flushout2 (IO, tstamp, type, subtype, =0A=
bgp_packet, bp - bgp_packet, =0A=
gateway_from, gateway_to);=0A=
}=0A=
else if (bgptype =3D=3D BGP_NOTIFY) {=0A=
if (type =3D=3D MSG_PROTOCOL_BGP4MP) {=0A=
memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN);=0A=
BGP_PUT_HDRTYPE (bgptype, bgp_packet);=0A=
bp =3D bgp_packet + BGP_HEADER_LEN;=0A=
}=0A=
else {=0A=
bp =3D bgp_packet;=0A=
}=0A=
BGP_PUT_BYTE (code, bp);=0A=
BGP_PUT_BYTE (subcode, bp);=0A=
if (type =3D=3D MSG_PROTOCOL_BGP4MP) {=0A=
BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet);=0A=
}=0A=
flushout2 (IO, tstamp, type, subtype, =0A=
bgp_packet, bp - bgp_packet, =0A=
gateway_from, gateway_to);=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_STATE_CHANGE) {=0A=
bp =3D bgp_packet;=0A=
BGP_PUT_SHORT (state1, bp);=0A=
BGP_PUT_SHORT (state2, bp);=0A=
flushout2 (IO, tstamp, type, subtype, =0A=
bgp_packet, bp - bgp_packet, =0A=
gateway_from, NULL);=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_SNAPSHOT) {=0A=
bp =3D bgp_packet;=0A=
BGP_PUT_SHORT (viewno, bp);=0A=
if (filename)=0A=
BGP_PUT_DATA (filename, strlen (filename), bp);=0A=
BGP_PUT_BYTE (0, bp);=0A=
trace_mrt_header (MRT->trace, tstamp, type, subtype);=0A=
io_write (IO, tstamp, type, subtype, =0A=
bp - bgp_packet, bgp_packet);=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_ENTRY || newtype =3D=3D 1) {=0A=
if (route_prefix !=3D NULL) {=0A=
buffer_p =3D bgp_table_dump_entry (buffer_p, end, type, =0A=
subtype, viewno, =0A=
route_prefix, status, originated, attr);=0A=
}=0A=
if (buffer_p - buffer > 0) {=0A=
trace_mrt_header (MRT->trace, tstamp, type, subtype);=0A=
io_write (IO, tstamp, type, subtype, =0A=
buffer_p - buffer, buffer);=0A=
}=0A=
}=0A=
=0A=
if (eof)=0A=
break;=0A=
if (MRT->force_exit_flag)=0A=
exit (1);=0A=
bgp_deref_attr (attr);=0A=
attr =3D bgp_new_attr (PROTO_BGP);=0A=
LL_Clear (ll_ann);=0A=
LL_Clear (ll_with);=0A=
=0A=
announce_flag =3D 0;=0A=
have_data =3D 0;=0A=
have_data2 =3D 0;=0A=
tstamp =3D 0;=0A=
type =3D 0;=0A=
subtype =3D 0;=0A=
bgptype =3D 0;=0A=
newtype =3D 0;=0A=
gateway_to =3D NULL;=0A=
gateway_from =3D NULL;=0A=
route_prefix =3D NULL;=0A=
seq_num =3D 0;=0A=
first =3D 1;=0A=
if (filename)=0A=
free (filename);=0A=
filename =3D NULL;=0A=
continue;=0A=
}=0A=
=0A=
if (have_data) {=0A=
/* a prefix -- line begins with a space */=0A=
if (isspace (line[0])) {=0A=
prefix_t *prefix;=0A=
char *cp =3D line +1;=0A=
=0A=
while (isspace (*cp))=0A=
cp++;=0A=
if ((prefix =3D ascii2prefix (0, cp)) !=3D NULL) {=0A=
if (announce_flag =3D=3D 1) {=0A=
LL_Add (ll_ann, prefix);=0A=
}=0A=
else {=0A=
LL_Add (ll_with, prefix);=0A=
}=0A=
continue;=0A=
}=0A=
}=0A=
}=0A=
=0A=
if (have_data2) {=0A=
prefix_t *prefix;=0A=
int num;=0A=
u_long value;=0A=
=0A=
if (isspace (line[0]) &&=0A=
strpbrk (line, ".:") && strchr (line, '/') &&=0A=
parse_line (line, "%d %m", &num, &prefix) =3D=3D 2) {=0A=
u_char *here =3D bp;=0A=
/* v4 or v6 address with prefixlen */=0A=
#ifdef HAVE_IPV6=0A=
if (prefix->family =3D=3D AF_INET6)=0A=
BGP_PUT_PREFIX6 (prefix->bitlen, prefix_tochar (prefix), =0A=
bp);=0A=
else=0A=
#endif /* HAVE_IPV6 */=0A=
BGP_PUT_PREFIX (prefix->bitlen, prefix_tochar (prefix), =0A=
bp);=0A=
Deref_Prefix (prefix);=0A=
if (num !=3D bp - here) {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"length was %d but must be %d\n", num, bp - here);=0A=
goto error;=0A=
}=0A=
continue;=0A=
}=0A=
else if (isspace (line[0]) &&=0A=
strpbrk (line, ".:") && =0A=
parse_line (line, "%d %M", &num, &prefix) =3D=3D 2) {=0A=
/* v4 or v6 address w/o prefixlen */=0A=
if (prefix->family =3D=3D AF_INET6 && num > 16) {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"length was %d but must be less than or equal %d\n",=0A=
num, 16);=0A=
Deref_Prefix (prefix);=0A=
goto error;=0A=
}=0A=
if (prefix->family =3D=3D AF_INET && num > 4) {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"length was %d but must be less than or equal %d\n",=0A=
num, 4);=0A=
Deref_Prefix (prefix);=0A=
goto error;=0A=
}=0A=
BGP_PUT_DATA (prefix_tochar (prefix), num, bp);=0A=
Deref_Prefix (prefix);=0A=
continue;=0A=
}=0A=
else if (isspace (line[0]) &&=0A=
parse_line (line, "%d %i", &num, &value) =3D=3D 2) {=0A=
if (num =3D=3D 1)=0A=
BGP_PUT_BYTE (value, bp);=0A=
else if (num =3D=3D 2)=0A=
BGP_PUT_SHORT (value, bp);=0A=
else if (num =3D=3D 4)=0A=
BGP_PUT_LONG (value, bp);=0A=
else {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"unknown length %d\n", num);=0A=
goto error;=0A=
}=0A=
continue;=0A=
}=0A=
}=0A=
=0A=
if ((ret =3D checkstradvance (line, "TIME"))) {=0A=
struct tm tm;=0A=
if (strptime (ret, "%D %T", &tm)) {=0A=
time_t now;=0A=
time (&now);=0A=
tm.tm_isdst =3D localtime (&now)->tm_isdst;=0A=
adjust_y2k (&tm);=0A=
tstamp =3D mktime (&tm);=0A=
}=0A=
}=0A=
=0A=
else if ((ret =3D checkstradvance (line, "TO"))) {=0A=
int as;=0A=
char data[MAXLINE];=0A=
prefix_t *prefix;=0A=
if (sscanf (ret, "%s AS%d", data, &as) >=3D 2 ||=0A=
sscanf (ret, "AS%d %s", &as, data) >=3D 2 /* obsolete */) {=0A=
prefix =3D ascii2prefix (0, data);=0A=
gateway_to =3D add_gateway (prefix, as, NULL);=0A=
Deref_Prefix (prefix);=0A=
}=0A=
}=0A=
=0A=
else if ((ret =3D checkstradvance (line, "FROM"))) {=0A=
int as;=0A=
char data[MAXLINE];=0A=
if (sscanf (ret, "%s AS%d", data, &as) >=3D 2 ||=0A=
sscanf (ret, "AS%d %s", &as, data) >=3D 2 /* obsolete */) {=0A=
prefix_t *prefix =3D ascii2prefix (0, data);=0A=
gateway_from =3D add_gateway (prefix, as, NULL);=0A=
attr->gateway =3D gateway_from;=0A=
Deref_Prefix (prefix);=0A=
}=0A=
}=0A=
=0A=
/* type BGP/UPDATE */=0A=
else if ((ret =3D checkstradvance (line, "TYPE"))) {=0A=
char *subtypestr;=0A=
char **cpp;=0A=
int i;=0A=
=0A=
if ((subtypestr =3D strchr (ret, '/')) !=3D NULL)=0A=
*subtypestr++ =3D '\0';=0A=
=0A=
cpp =3D S_MRT_MSG_TYPES;=0A=
for (i =3D 0; cpp[i]; i++) {=0A=
if (strcasecmp (cpp[i], ret) =3D=3D 0)=0A=
break;=0A=
}=0A=
type =3D (enum MRT_MSG_TYPES) i;=0A=
=0A=
if (subtypestr) {=0A=
char *subsubtypestr;=0A=
=0A=
if ((subsubtypestr =3D strchr (subtypestr, '/')) !=3D NULL)=0A=
*subsubtypestr++ =3D '\0';=0A=
if ((cpp =3D S_MRT_MSG_SUBTYPES[type]) !=3D NULL) {=0A=
for (i =3D 0; cpp[i]; i++) {=0A=
if (strcasecmp (cpp[i], subtypestr) =3D=3D 0)=0A=
break;=0A=
}=0A=
subtype =3D i;=0A=
}=0A=
newtype =3D subtype;=0A=
=0A=
if (type =3D=3D MSG_PROTOCOL_BGP ||=0A=
type =3D=3D MSG_PROTOCOL_BGP4PLUS ||=0A=
type =3D=3D MSG_PROTOCOL_BGP4PLUS_01) {=0A=
if (subtype =3D=3D MSG_BGP_UPDATE) {=0A=
bgptype =3D BGP_UPDATE;=0A=
newtype =3D BGP4MP_MESSAGE;=0A=
}=0A=
else if (subtype =3D=3D MSG_BGP_KEEPALIVE) {=0A=
bgptype =3D BGP_KEEPALIVE;=0A=
newtype =3D BGP4MP_MESSAGE;=0A=
}=0A=
else if (subtype =3D=3D MSG_BGP_NOTIFY) {=0A=
bgptype =3D BGP_NOTIFY;=0A=
newtype =3D BGP4MP_MESSAGE;=0A=
}=0A=
else if (subtype =3D=3D MSG_BGP_OPEN) {=0A=
bgptype =3D BGP_OPEN;=0A=
newtype =3D BGP4MP_MESSAGE;=0A=
}=0A=
else if (subtype =3D=3D MSG_BGP_SYNC) {=0A=
newtype =3D BGP4MP_SNAPSHOT;=0A=
}=0A=
else if (subtype =3D=3D MSG_BGP_STATE_CHANGE) {=0A=
newtype =3D BGP4MP_STATE_CHANGE;=0A=
}=0A=
else if (subtype =3D=3D MSG_TABLE_DUMP) {=0A=
newtype =3D BGP4MP_ENTRY;=0A=
}=0A=
}=0A=
else if (type =3D=3D MSG_PROTOCOL_BGP4MP && (=0A=
subtype =3D=3D BGP4MP_MESSAGE || =0A=
subtype =3D=3D BGP4MP_MESSAGE_OLD)) {=0A=
for (i =3D 0; sbgp_pdus[i]; i++) {=0A=
if (strcasecmp (sbgp_pdus[i], subsubtypestr) =3D=3D 0) {=0A=
bgptype =3D i;=0A=
break;=0A=
}=0A=
}=0A=
}=0A=
}=0A=
=0A=
if (type =3D=3D MSG_PROTOCOL_BGP=0A=
|| type =3D=3D MSG_PROTOCOL_BGP4PLUS=0A=
|| type =3D=3D MSG_PROTOCOL_BGP4PLUS_01=0A=
|| type =3D=3D MSG_TABLE_DUMP=0A=
|| type =3D=3D MSG_PROTOCOL_BGP4MP=0A=
) {=0A=
/* OK */=0A=
}=0A=
else {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"Unknown message type %s at line %d\n", ret, line_num);=0A=
goto error;=0A=
}=0A=
}=0A=
=0A=
else if ((ret =3D checkstradvance (line, "DATA"))) {=0A=
bp =3D bgp_packet;=0A=
have_data2++;=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_STATE_CHANGE &&=0A=
(ret =3D checkstradvance (line, "PEER"))) {=0A=
int as;=0A=
char data[MAXLINE];=0A=
if (sscanf (ret, "%s AS%d", data, &as) >=3D 2 ||=0A=
sscanf (ret, "AS%d %s", &as, data) >=3D 2 /* obsolete */) {=0A=
prefix_t *prefix =3D ascii2prefix (0, data);=0A=
gateway_from =3D add_gateway (prefix, as, NULL);=0A=
Deref_Prefix (prefix);=0A=
}=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_STATE_CHANGE &&=0A=
(ret =3D checkstradvance (line, "STATE"))) {=0A=
char *cp =3D strchr (ret, '/');=0A=
int i;=0A=
=0A=
if (cp =3D=3D NULL)=0A=
goto error;=0A=
*cp++ =3D '\0';=0A=
for (i =3D 0; sbgp_states[i]; i++) {=0A=
if (strcasecmp (sbgp_states[i], ret) =3D=3D 0) {=0A=
state1 =3D i;=0A=
}=0A=
}=0A=
for (i =3D 0; sbgp_states[i]; i++) {=0A=
if (strcasecmp (sbgp_states[i], cp) =3D=3D 0) {=0A=
state2 =3D i;=0A=
}=0A=
}=0A=
}=0A=
else if ((newtype =3D=3D BGP4MP_SNAPSHOT || newtype =3D=3D =
BGP4MP_ENTRY || newtype =3D=3D 1) &&=0A=
(ret =3D checkstradvance (line, "VIEW"))) {=0A=
viewno =3D atoi (ret);=0A=
}=0A=
else if (newtype =3D=3D BGP4MP_SNAPSHOT &&=0A=
(ret =3D checkstradvance (line, "FILE"))) {=0A=
if (filename)=0A=
free (filename);=0A=
filename =3D strdup (ret);=0A=
}=0A=
else if ((newtype =3D=3D BGP4MP_ENTRY || newtype =3D=3D 1) &&=0A=
(ret =3D checkstradvance (line, "PREFIX"))) {=0A=
if (route_prefix =3D=3D NULL) {=0A=
buffer_p =3D buffer;=0A=
if (type =3D=3D MSG_TABLE_DUMP) {=0A=
BGP_PUT_SHORT (viewno, buffer_p);=0A=
BGP_PUT_SHORT (seq_num, buffer_p);=0A=
}=0A=
}=0A=
else {=0A=
buffer_p =3D bgp_table_dump_entry (buffer_p, end, type, subtype,=0A=
viewno, route_prefix, status, originated, attr);=0A=
}=0A=
route_prefix =3D ascii2prefix (0, ret);=0A=
bgp_deref_attr (attr);=0A=
attr =3D bgp_new_attr (PROTO_BGP);=0A=
}=0A=
else if ((newtype =3D=3D BGP4MP_ENTRY || newtype =3D=3D 1)&&=0A=
(ret =3D checkstradvance (line, "SEQUENCE"))) {=0A=
seq_num =3D atoi (ret);=0A=
}=0A=
else if ((newtype =3D=3D BGP4MP_ENTRY || newtype =3D=3D 1)&&=0A=
(ret =3D checkstradvance (line, "ORIGINATED"))) {=0A=
struct tm tm;=0A=
if (strptime (ret, "%D %T", &tm)) {=0A=
time_t now;=0A=
time (&now);=0A=
tm.tm_isdst =3D localtime (&now)->tm_isdst;=0A=
adjust_y2k (&tm);=0A=
originated =3D mktime (&tm);=0A=
}=0A=
}=0A=
else if ((newtype =3D=3D BGP4MP_ENTRY || newtype =3D=3D 1)&&=0A=
(ret =3D checkstradvance (line, "STATUS"))) {=0A=
sscanf (ret, "%li", &status);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN &&=0A=
(ret =3D checkstradvance (line, "VERSION"))) {=0A=
version =3D atoi (ret);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN &&=0A=
(ret =3D checkstradvance (line, "AS"))) {=0A=
as =3D atoi (ret);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN &&=0A=
(ret =3D checkstradvance (line, "HOLD_TIME"))) {=0A=
holdtime =3D atoi (ret);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN &&=0A=
(ret =3D checkstradvance (line, "ID"))) {=0A=
inet_pton (AF_INET, ret, &id);=0A=
}=0A=
else if (bgptype =3D=3D BGP_OPEN &&=0A=
(ret =3D checkstradvance (line, "OPT_PARM_LEN"))) {=0A=
optlen =3D atoi (ret);=0A=
}=0A=
else if (bgptype =3D=3D BGP_NOTIFY &&=0A=
(ret =3D checkstradvance (line, "CODE"))) {=0A=
char *cp;=0A=
code =3D atoi (ret);=0A=
if ((cp =3D strchr (ret, '/')) !=3D NULL)=0A=
subcode =3D atoi (cp + 1);=0A=
}=0A=
else if (bgptype =3D=3D BGP_UPDATE &&=0A=
(ret =3D checkstradvance (line, "ANNOUNCE"))) {=0A=
announce_flag =3D 1;=0A=
have_data++;=0A=
}=0A=
else if (bgptype =3D=3D BGP_UPDATE &&=0A=
(ret =3D checkstradvance (line, "WITHDRAW"))) {=0A=
announce_flag =3D 0;=0A=
have_data++;=0A=
}=0A=
else if ((bgptype =3D=3D BGP_UPDATE || newtype =3D=3D BGP4MP_ENTRY =
|| newtype =3D=3D 1) &&=0A=
(ok =3D bgp_scan_attr (line, attr, MRT->trace)) > 0) {=0A=
/* OK */=0A=
}=0A=
else if ((bgptype =3D=3D BGP_UPDATE || newtype =3D=3D BGP4MP_ENTRY =
|| newtype =3D=3D 1) && ok < 0) {=0A=
trace (TR_ERROR, MRT->trace, =0A=
"Invalid BGP attribute at line %d\n", line_num);=0A=
goto error;=0A=
}=0A=
else {=0A=
trace (TR_ERROR, MRT->trace, "Unrecognized line at %d\n", =
line_num);=0A=
goto error;=0A=
}=0A=
}=0A=
=0A=
error:=0A=
if (filename)=0A=
free (filename);=0A=
bgp_deref_attr (attr);=0A=
LL_Destroy (ll_ann);=0A=
LL_Destroy (ll_with);=0A=
Delete_Buffer (stdbuf);=0A=
}=0A=
=0A=
=0A=
void=0A=
main (int argc, char *argv[])=0A=
{=0A=
int c;=0A=
extern char *optarg; /* getopt stuff */=0A=
extern int optind; /* getopt stuff */=0A=
char *usage =3D=0A=
"Usage: route_atob [-i ascii_data_file] [-(o|w) =
binary_out_file]\n";=0A=
char *filename =3D "stdin";=0A=
char *ofile =3D "stdout";=0A=
char *wfile =3D NULL;=0A=
int errors =3D 0;=0A=
io_t *IO;=0A=
trace_t *default_trace;=0A=
FILE *fd;=0A=
=0A=
default_trace =3D New_Trace ();=0A=
IO =3D New_IO (default_trace);=0A=
=0A=
while ((c =3D getopt (argc, argv, "i:f:o:w:v")) !=3D -1)=0A=
switch (c) {=0A=
case 'o':=0A=
ofile =3D (char *) (optarg);=0A=
break;=0A=
case 'w':=0A=
wfile =3D (char *) (optarg);=0A=
break;=0A=
case 'i':=0A=
case 'f':=0A=
filename =3D (char *) optarg;=0A=
break;=0A=
case 'v':=0A=
set_trace (default_trace, TRACE_FLAGS, TR_ALL,=0A=
TRACE_LOGFILE, "stdout", NULL);=0A=
break;=0A=
default:=0A=
errors++;=0A=
}=0A=
=0A=
init_mrt (default_trace);=0A=
=0A=
if (ofile) {=0A=
if (io_set (IO, IO_OUTFILE, ofile, NULL) < 0) {=0A=
printf ("Error setting outfile: %s (%s)\n", ofile, strerror =
(errno));=0A=
errors++;=0A=
}=0A=
}=0A=
if (wfile) {=0A=
if (io_set (IO, IO_OUTMSGQ, wfile, NULL) < 0) {=0A=
printf ("Error setting output: %s (%s)\n", wfile, strerror =
(errno));=0A=
errors++;=0A=
}=0A=
}=0A=
if (errors) {=0A=
fprintf (stderr, usage);=0A=
printf ("\nMRT version (%s) compiled on %s\n\n",=0A=
MRT_VERSION, __DATE__);=0A=
exit (0);=0A=
}=0A=
=0A=
if (!strcasecmp (filename, "stdin"))=0A=
fd =3D stdin;=0A=
else=0A=
fd =3D fopen (filename, "r");=0A=
=0A=
if (fd =3D=3D NULL) {=0A=
perror (filename);=0A=
exit (1);=0A=
}=0A=
read_ascii (fd, IO);=0A=
exit (0);=0A=
}=0A=
=0A=
------_=_NextPart_000_01C0C377.3684FE80
Content-Type: application/octet-stream;
name="route_stoa.pl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="route_stoa.pl"
#!/usr/bin/perl=0A=
=0A=
require "getopts.pl";=0A=
=0A=
$USAGE =3D "route_stob.pl -i ascii_input_file -o ascii_output_file";=0A=
=0A=
& Getopts("i:f:o:v");=0A=
if(defined $opt_i) {=0A=
$INPUT =3D $opt_i;=0A=
}=0A=
if(defined $opt_f) {=0A=
$INPUT =3D $opt_f;=0A=
}=0A=
if(defined $opt_o) {=0A=
$OUTPUT =3D $opt_o;=0A=
}=0A=
if(defined $opt_v) {=0A=
$DEBUG =3D 1;=0A=
}=0A=
=0A=
if (($INPUT eq "") || ($OUTPUT eq "")) {=0A=
print "Usage: $USAGE\n";=0A=
exit;=0A=
}=0A=
=0A=
# handle special stdin and stdout cases=0A=
if ($INPUT eq "stdin") {$INPUT =3D "-";}=0A=
if ($OUTPUT eq "stdout") {=0A=
open (OUT, ">-");=0A=
}=0A=
else {=0A=
open (OUT, "> $OUTPUT") || die "Could not open $OUTPUT : $! \n";=0A=
}=0A=
=0A=
&read_input ($INPUT);=0A=
=0A=
sub read_input {=0A=
local ($inputfile) =3D @_;=0A=
my $month, $mday, $year, $hour, $min, $sec, $src, $dst;=0A=
my $valid, $network, $nexthop, $Metric, $LocPrf, $Weight, $Path, =
$origin, nexthopAS;=0A=
my $prevNetwork, $time;=0A=
my $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst;=0A=
=0A=
$time =3D time;=0A=
=0A=
if (open (INPUT, $inputfile) < 1) {=0A=
print "Could not open $inputfile\n";=0A=
return;=0A=
}=0A=
=0A=
printf ("TIME: 02/28/01 10:38:07\nTYPE: TABLE_DUMP/INET\nVIEW: =
0\nSEQUENCE: 0\n");=0A=
$line =3D 0;=0A=
while (<INPUT>) {=0A=
$line++;=0A=
$offset =3D 0;=0A=
=0A=
$valid =3D substr ($_, 0, 3);=0A=
$offset +=3D 3;=0A=
=0A=
# Take first 15 chars (xxx.xxx.xxx.xxx), to see whether the=0A=
# network field exist or not.=0A=
=0A=
$network =3D substr ($_, $offset, 17);=0A=
=0A=
# Are there characters other than white spaces?=0A=
if ($network =3D~ /\S/) {=0A=
=0A=
# looking for the location of the last space (white space=0A=
# which is followed by digit) of the $network. If it=0A=
# exceedes the boundaries, all other fields are shifted=0A=
$pos =3D substr ($_, 3);=0A=
$pos =3D~ /\s(\d)/g;=0A=
$network =3D substr ($_, $offset, pos($pos)-1);=0A=
=0A=
# discard trailing whitespaces from $network=0A=
$network =3D~ s/\s+$//;=0A=
=0A=
# Check whether it is required to add mask to the network=0A=
# (if not exist. I think mrt format require mask)=0A=
unless ($network =3D~ /\//) {=0A=
$network =3D~ s/(.)$/\1\/24/;=0A=
}=0A=
$prevNetwork =3D $network;=0A=
=0A=
$offset +=3D (pos($pos)-1);=0A=
} else {=0A=
$offset +=3D 17;=0A=
$network =3D $prevNetwork;=0A=
}=0A=
=0A=
$pos =3D substr ($_, $offset);=0A=
$pos =3D~ /\s/g;=0A=
$nexthop =3D substr ($_, $offset, pos($pos)-1);=0A=
$offset +=3D 15;=0A=
# no nexthop - no valid entry=0A=
exit unless $nexthop =3D~ /\d/;=0A=
=0A=
$Metric =3D substr ($_, $offset, 11);=0A=
$offset +=3D 11;=0A=
#print $Metric;=0A=
=0A=
$LocPrf =3D substr ($_, $offset, 7);=0A=
$offset +=3D 7;=0A=
=0A=
$Weight =3D substr ($_, $offset, 7);=0A=
$offset +=3D 7;=0A=
=0A=
chop ($pos);=0A=
$pos =3D substr ($_, $offset);=0A=
# isolate the origin from the $Path=0A=
if ($pos =3D~ /[aie\?]/g) {=0A=
$origin =3D substr ($_, $offset+(pos($pos)-1));=0A=
$Path =3D substr ($_, $offset, pos($pos)-1);=0A=
} else {=0A=
# no origin attributes. Check whether trailing spaces=0A=
# exist, and cut them=0A=
$Path =3D substr ($_, $offset);=0A=
chop ($Path);=0A=
}=0A=
# Discard trailing whitespaces=0A=
$Path =3D~ s/\s+$//;=0A=
# Discard leading whitespaces=0A=
$Path =3D~ s/^\s+//;=0A=
$nexthopAS =3D $Path;=0A=
# Isolate the first AS in the list (this is the AS of the peer=0A=
# who sent the update)=0A=
# Discard leading whitespaces=0A=
$nexthopAS =3D~ s/^\s+//;=0A=
$nexthopAS =3D~ s/\s.*//;=0A=
=0A=
#printf ("%s%s%s%s%s%s\n", $network, $nexthop, $Metric, $LocPrf, =
$Weight, $Path);=0A=
printf ("PREFIX: %s\n", $network);=0A=
printf ("FROM: %s AS%s\n", $nexthop, $nexthopAS);=0A=
$time++;=0A=
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =3D =
localtime($time);=0A=
printf ("ORIGINATED: %s/%s/01 %s:%s:%s\n",$mon, $mday, $hour, $min, =
$sec); =0A=
#printf ("ORIGINATED: 02/28/01 09:14:19\n");=0A=
SWITCH: {=0A=
if ($origin =3D~ /i/) {=0A=
printf ("ORIGIN: IGP\n");=0A=
last SWITCH;=0A=
}=0A=
if ($origin =3D~ /e/) {=0A=
printf ("ORIGIN: EGP\n");=0A=
last SWITCH;=0A=
}=0A=
if ($origin =3D~ /\?/) {=0A=
printf ("ORIGIN: INCOMPLETE\n");=0A=
last SWITCH;=0A=
}=0A=
}=0A=
printf ("ASPATH: %s\n", $Path);=0A=
printf ("NEXT_HOP: %s\n", $nexthop);=0A=
#printf ("MULTI_EXIT_DISC: 46\n");=0A=
#printf ("STATUS: 0x1\n");=0A=
if ($line eq 100) {=0A=
$line=3D0;=0A=
# Must put here empty line & new view. Otherwise the route_atob =
crashes=0A=
print "\n";=0A=
printf ("TIME: 02/28/01 10:38:07\nTYPE: TABLE_DUMP/INET\nVIEW: =
0\nSEQUENCE: 0\n");=0A=
}=0A=
}=0A=
}=0A=
------_=_NextPart_000_01C0C377.3684FE80--