1 // $Id$
2 // Copyright (c) 2001,2002 RIPE NCC
3 //
4 // All Rights Reserved
5 //
6 // Permission to use, copy, modify, and distribute this software and its
7 // documentation for any purpose and without fee is hereby granted,
8 // provided that the above copyright notice appear in all copies and that
9 // both that copyright notice and this permission notice appear in
10 // supporting documentation, and that the name of the author not be
11 // used in advertising or publicity pertaining to distribution of the
12 // software without specific, written prior permission.
13 //
14 // THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
16 // AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
17 // DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
18 // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 //
21 //
22 // Copyright (c) 1994 by the University of Southern California
23 // All rights reserved.
24 //
25 // Permission is hereby granted, free of charge, to any person obtaining a copy
26 // of this software and associated documentation files (the "Software"), to deal
27 // in the Software without restriction, including without limitation the rights
28 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 // copies of the Software, and to permit persons to whom the Software is
30 // furnished to do so, subject to the following conditions:
31 //
32 // The above copyright notice and this permission notice shall be included in
33 // all copies or substantial portions of the Software.
34 //
35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41 // THE SOFTWARE.
42 //
43 // Questions concerning this software should be directed to
44 // irrtoolset@cs.usc.edu.
45 //
46 // Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
47
48 #include "config.h"
49 #include <cstdio>
50 #include "rpsl_policy.hh"
51 #include "rpsl_attr.hh"
52 #include <ostream>
53
54 using namespace std;
55
56 //// printing ////////////////////////////////////////////////////////
57
print(ostream & out) const58 ostream& Policy::print(ostream &out) const {
59 return out;
60 }
61
print(ostream & out) const62 ostream &PolicyAction::print(ostream &out) const {
63 out << rp_attr->name;
64 if (rp_method->isOperator)
65 out << " " << (rp_method->name + 8) << " " << *args;
66 else
67 out << "." << rp_method->name << "(" << *args << ")";
68
69 return out;
70 }
71
print(ostream & out) const72 ostream &PolicyActionList::print(ostream &out) const {
73 if (!isEmpty()) {
74 out << "action ";
75 for (PolicyAction *nd = head(); nd; nd = next(nd))
76 out << *nd << "; ";
77 }
78
79 return out;
80 }
81
print(ostream & out) const82 ostream &PolicyPeeringAction::print(ostream &out) const {
83 out << *peering << "\n";
84 if (!action->isEmpty())
85 out << " \t" << *action << "\n";
86 return out;
87 }
88
print(ostream & out) const89 ostream &PolicyFactor::print(ostream &out) const {
90 for (PolicyPeeringAction *pa = peeringActionList->head();
91 pa;
92 pa = peeringActionList->next(pa))
93 out << "\tfrom/to " << *pa << "\n";
94
95 out << " \taccept/announce " << *filter <<";";
96
97 return out;
98 }
99
print(ostream & out) const100 ostream &PolicyTerm::print(ostream &out) const {
101 bool indent = !isEmpty() && !isSingleton();
102 if (indent)
103 out << "{\n";
104
105 for (PolicyFactor *pf = head(); pf; pf = next(pf)) {
106 if (indent)
107 out << " ";
108 out << *pf << "\n";
109 }
110 if (indent)
111 out << "}";
112
113 return out;
114 }
115
print(ostream & out) const116 ostream &PolicyRefine::print(ostream &out) const {
117 out << *left << " refine " << *right;
118 return out;
119 }
120
print(ostream & out) const121 ostream &PolicyExcept::print(ostream &out) const {
122 out << *left << " except " << *right;
123 return out;
124 }
125
126
print(ostream & out) const127 ostream &PolicyPeering::print(ostream &out) const {
128 if (prngSet)
129 out << prngSet;
130 else {
131 out << *peerASes;
132 if (peerRtrs)
133 out << " " << *peerRtrs;
134 if (localRtrs)
135 out << " at " << *localRtrs;
136 }
137
138 return out;
139 }
140
141