Skip to content

Commit cb26d00

Browse files
authored
Merge pull request #54 from DEIS-Tools/star_construction
Fixing Start Construction
2 parents 66f0d14 + 268f089 commit cb26d00

File tree

6 files changed

+53
-105
lines changed

6 files changed

+53
-105
lines changed

src/aalwines/model/Network.cpp

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,18 @@ namespace aalwines
8989

9090
std::unordered_set<Query::label_t> Network::get_labels(uint64_t label, uint64_t mask, Query::type_t type, bool exact)
9191
{
92+
Query::label_t lbl(type, mask, label);
9293
std::unordered_set<Query::label_t> res;
9394
for (auto& pr : all_labels()) {
94-
if (pr.type() != type) continue;
95-
auto msk = std::max<uint8_t>(mask, pr.mask());
9695
if(pr == Query::label_t::unused_ip4 ||
9796
pr == Query::label_t::unused_ip6 ||
9897
pr == Query::label_t::unused_mpls ||
9998
pr == Query::label_t::unused_sticky_mpls ||
10099
pr == Query::label_t::any_ip ||
101100
pr == Query::label_t::any_ip4 ||
102-
pr == Query::label_t::any_ip6 ||
103-
pr == Query::label_t::any_mpls ||
104-
pr == Query::label_t::any_sticky_mpls) continue;
105-
switch (type) {
106-
case Query::IP6:
107-
case Query::IP4:
108-
case Query::STICKY_MPLS:
109-
case Query::MPLS:
110-
{
111-
if ((pr.value() << msk) == (label << msk) &&
112-
(pr.type() & Query::STICKY) == (type & Query::STICKY))
113-
{
114-
res.insert(pr);
115-
}
116-
}
117-
default:
118-
break;
119-
}
101+
pr == Query::label_t::any_ip6) continue;
102+
if (lbl.overlaps(pr))
103+
res.insert(pr);
120104
}
121105
if(res.empty())
122106
{
@@ -146,16 +130,16 @@ namespace aalwines
146130
case Query::IP6:
147131
res.emplace(Query::label_t::any_ip6);
148132
break;
149-
case Query::STICKY_MPLS:
150-
res.emplace(Query::label_t::any_sticky_mpls);
151-
break;
152-
case Query::MPLS:
153-
res.emplace(Query::label_t::any_mpls);
154-
break;
155133
default:
156-
throw base_error("Unknown expansion");
134+
break;
157135
}
158136
}
137+
#ifndef NDEBUG
138+
for(auto& r : res)
139+
{
140+
assert(r.mask() == 0 || type == Query::IP6 || type == Query::IP4 || type == Query::ANYIP);
141+
}
142+
#endif
159143
return res;
160144
}
161145

@@ -172,8 +156,6 @@ namespace aalwines
172156
res.insert(Query::label_t::any_ip);
173157
res.insert(Query::label_t::any_ip4);
174158
res.insert(Query::label_t::any_ip6);
175-
res.insert(Query::label_t::any_mpls);
176-
res.insert(Query::label_t::any_sticky_mpls);
177159
_non_service_label = res;
178160
for (auto& r : _routers) {
179161
for (auto& inf : r->interfaces()) {
@@ -523,4 +505,4 @@ namespace aalwines
523505
return Network(std::move(mapping), std::move(routers), std::move(interfaces));
524506
}
525507

526-
}
508+
}

src/aalwines/model/NetworkPDAFactory.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,12 @@ namespace aalwines {
259259
auto mask = pre.mask();
260260

261261
switch (pre.type()) {
262-
case Query::ANYSTICKY:
263-
case Query::ANYMPLS:
264-
mask = 64;
265-
val = 0;
266-
// fall through to MPLS
267262
case Query::STICKY_MPLS:
268263
case Query::MPLS: {
269264
if (mask == 0) {
270265
rules.push_back(cpy);
271266
rules.back()._pre = pre;
272-
rules.push_back(cpy);
273-
if (pre.type() & Query::STICKY)
274-
rules.back()._pre = Query::label_t::any_sticky_mpls;
275-
else
276-
rules.back()._pre = Query::label_t::any_mpls;
267+
assert(rules.back()._pre.mask() == 0);
277268
} else {
278269
for (auto &l : _network.get_labels(val, mask,
279270
(Query::type_t) (Query::MPLS | (pre.type() & Query::STICKY)))) {
@@ -367,9 +358,7 @@ namespace aalwines {
367358
entry._top_label.type() == Query::IP6)) {
368359
return false;
369360
}
370-
if (entry._top_label.type() != Query::ANYIP &&
371-
entry._top_label.type() != Query::ANYMPLS &&
372-
entry._top_label.type() != Query::ANYSTICKY) {
361+
if (entry._top_label.type() != Query::ANYIP) {
373362
nr._op = pdaaal::SWAP;
374363
nr._op_label = entry._top_label;
375364
assert(entry._top_label.mask() == 0);
@@ -739,11 +728,9 @@ namespace aalwines {
739728
if (!step._stack.empty()) {
740729
// ANYMPLS = 1, ANYIP = 2, IP4 = 4, IP6 = 8, MPLS = 16, STICKY = 32, INTERFACE = 64, NONE = 128, ANYSTICKY = ANYMPLS | STICKY, STICKY_MPLS = MPLS | STICKY
741730
switch (step._stack.front().type()) {
742-
case Query::ANYMPLS:
743-
case Query::ANYSTICKY:
744-
case Query::ANYIP:
745731
case Query::IP4:
746732
case Query::IP6:
733+
case Query::ANYIP:
747734
if (entries[cnt]->_top_label != Query::label_t::any_ip &&
748735
entries[cnt]->_top_label.mask() < step._stack.front().mask()) {
749736
concrete = entries[cnt]->_top_label;
@@ -759,9 +746,7 @@ namespace aalwines {
759746
for (auto &s : trace[upd]._stack) {
760747
if (s.type() == Query::ANYIP ||
761748
s.type() == Query::IP4 ||
762-
s.type() == Query::IP6 ||
763-
s.type() == Query::ANYSTICKY ||
764-
s.type() == Query::ANYMPLS) {
749+
s.type() == Query::IP6) {
765750
s = concrete;
766751
break;
767752
}

src/aalwines/model/Query.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ namespace aalwines {
4444
out << "// PATH\n";
4545
_path.to_dot(out);
4646
}
47-
47+
48+
// concrete labels for unused entry
4849
const Query::label_t Query::label_t::unused_mpls(MPLS, 0, std::numeric_limits<uint64_t>::max());
4950
const Query::label_t Query::label_t::unused_sticky_mpls(STICKY_MPLS, 0, std::numeric_limits<uint64_t>::max());
50-
const Query::label_t Query::label_t::unused_ip4(IP4, 0, 0);
51-
const Query::label_t Query::label_t::unused_ip6(IP6, 0, 0);
52-
53-
const Query::label_t Query::label_t::any_mpls(ANYMPLS, std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint64_t>::max());
54-
const Query::label_t Query::label_t::any_sticky_mpls(ANYSTICKY, std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint64_t>::max());
55-
const Query::label_t Query::label_t::any_ip(ANYIP, std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint64_t>::max());
56-
const Query::label_t Query::label_t::any_ip4(IP4, std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint64_t>::max());
57-
const Query::label_t Query::label_t::any_ip6(IP6, std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint64_t>::max());
51+
const Query::label_t Query::label_t::unused_ip4(IP4, 0, std::numeric_limits<uint64_t>::max());
52+
const Query::label_t Query::label_t::unused_ip6(IP6, 0, std::numeric_limits<uint64_t>::max());
53+
54+
// any_mpls and any_sticky_mpls are META labels that MUST be unfolded
55+
const Query::label_t Query::label_t::any_mpls(MPLS, std::numeric_limits<uint8_t>::max(), 0);
56+
const Query::label_t Query::label_t::any_sticky_mpls(STICKY_MPLS, std::numeric_limits<uint8_t>::max(), 0);
57+
58+
// these are ordered labels
59+
const Query::label_t Query::label_t::any_ip(ANYIP, std::numeric_limits<uint8_t>::max(), 0);
60+
const Query::label_t Query::label_t::any_ip4(IP4, std::numeric_limits<uint8_t>::max(), 0);
61+
const Query::label_t Query::label_t::any_ip6(IP6, std::numeric_limits<uint8_t>::max(), 0);
5862
}

src/aalwines/model/Query.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace aalwines {
4444
};
4545

4646
enum type_t {
47-
ANYMPLS = 1, ANYIP = 2, IP4 = 4, IP6 = 8, MPLS = 16, STICKY = 32, INTERFACE = 64, NONE = 128, ANYSTICKY = ANYMPLS | STICKY, STICKY_MPLS = MPLS | STICKY
47+
ANYIP=2, IP4 = 4, IP6 = 8, MPLS = 16, STICKY = 32, INTERFACE = 64, NONE = 128, STICKY_MPLS = MPLS | STICKY
4848
};
4949

5050
struct label_t {
@@ -81,26 +81,18 @@ namespace aalwines {
8181
_mask = 64;
8282
_value = 0;
8383
break;
84-
case ANYSTICKY:
85-
case ANYMPLS:
86-
_mask = 64;
87-
_value = 0;
88-
break;
8984
case STICKY_MPLS:
9085
case MPLS:
9186
_mask = std::min<uint8_t>(64, _mask);
92-
_value = (_value >> _mask) << _mask;
9387
if(_mask == 64)
94-
{
95-
if(_type == STICKY_MPLS)
96-
*this = any_sticky_mpls;
97-
else
98-
*this = any_mpls;
99-
}
100-
88+
_value = 0;
89+
_value = (_value >> _mask) << _mask;
10190
break;
10291
case IP4:
103-
_mask = std::min<uint8_t>(32, _mask);
92+
if(_mask >= 32) {
93+
_mask = 64;
94+
_value = 0;
95+
}
10496
_value = std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), _value);
10597
_value = (_value >> _mask) << _mask;
10698
if(_mask >= 32)
@@ -128,8 +120,9 @@ namespace aalwines {
128120
}
129121

130122
bool uses_mask() const {
131-
return _mask != 0 && _type != INTERFACE && _type != ANYIP && _type != ANYMPLS && _type != ANYSTICKY;
123+
return _mask != 0 && _mask != 64 && _type != INTERFACE && _type != ANYIP;
132124
}
125+
133126
bool operator<(const label_t& other) const {
134127
if(_type != other._type)
135128
return _type < other._type;
@@ -166,11 +159,14 @@ namespace aalwines {
166159
case STICKY_MPLS:
167160
stream << "$";
168161
case MPLS:
169-
stream << ((label._value >> label._mask) << label._mask);
162+
if(label._mask >= 64 || label == Query::label_t::unused_mpls || label == Query::label_t::unused_sticky_mpls)
163+
stream << "mpls";
164+
else
165+
stream << ((label._value >> label._mask) << label._mask);
170166
break;
171167
case IP4:
172168
mx = 32;
173-
if(label._mask < 32)
169+
if(label._mask < 32 && label != Query::label_t::unused_ip4)
174170
write_ip4(stream, (label._value >> label._mask) << label._mask);
175171
else
176172
{
@@ -180,7 +176,7 @@ namespace aalwines {
180176
break;
181177
case IP6:
182178
mx = 64;
183-
if(label._mask < 64)
179+
if(label._mask < 64 && label != Query::label_t::unused_ip6)
184180
write_ip6(stream, (label._value >> label._mask) << label._mask);
185181
else
186182
{
@@ -194,11 +190,6 @@ namespace aalwines {
194190
case ANYIP:
195191
stream << "ip";
196192
break;
197-
case ANYSTICKY:
198-
stream << "$";
199-
case ANYMPLS:
200-
stream << "mpls";
201-
break;
202193
case NONE:
203194
stream << "NONE";
204195
break;
@@ -216,14 +207,11 @@ namespace aalwines {
216207
if(_type == other._type)
217208
{
218209
auto m = std::max(other._mask, _mask);
210+
if(_mask >= 64) return true;
219211
return (_value >> m) == (other._value >> m);
220212
}
221-
if(std::min(_type, other._type) == ANYIP &&
222-
(std::max(other._type, _type) == IP4 || std::max(other._type, _type) == IP6))
223-
return true;
224-
if(std::min(_type, other._type) == ANYMPLS && std::max(_type, other._type) == MPLS)
225-
return true;
226-
if(std::min(_type, other._type) == ANYSTICKY && std::max(_type, other._type) == STICKY_MPLS)
213+
if(std::min(_type, other._type) == ANYIP &&
214+
(std::max(other._type, _type) == IP4 || std::max(other._type, _type) == IP6))
227215
return true;
228216
return false;
229217
}

src/aalwines/model/RoutingTable.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,13 @@ namespace aalwines
308308
case Query::STICKY_MPLS:
309309
s << "s"; // fall through on purpose
310310
case Query::MPLS:
311-
s << 'l' << std::dec << label.value() << std::dec;
311+
if(label == Query::label_t::any_mpls ||
312+
label == Query::label_t::any_sticky_mpls)
313+
s << "mpls";
314+
else
315+
s << 'l' << std::dec << label.value() << std::dec;
312316
assert(label.mask() == 0);
313317
break;
314-
case Query::ANYSTICKY:
315-
s << "s"; // fall through on purpose
316-
case Query::ANYMPLS:
317-
s << "am";
318-
break;
319318
case Query::IP4:
320319
s << "ip4" << std::hex << label.value() << "M" << (uint32_t) label.mask() << std::dec;
321320
assert(label.mask() == 0 || label.value() == std::numeric_limits<uint64_t>::max());

src/aalwines/query/QueryBuilder.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,7 @@ namespace aalwines
108108

109109
Builder::labelset_t Builder::expand_labels(Query::label_t label)
110110
{
111-
if(!_expand) return {label};
112-
113-
if(label.type() == Query::ANYMPLS)
114-
{
115-
return _network.get_labels(0, 255, _sticky ? Query::STICKY_MPLS : Query::MPLS);
116-
}
117-
else if(label.type() == Query::ANYSTICKY)
118-
{
119-
return _network.get_labels(0, 255, Query::STICKY_MPLS);
120-
}
121-
return _network.get_labels(label.value(), label.mask(), label.type());
111+
return _network.get_labels(label.value(), label.mask(), label.type());
122112
}
123113

124114
Builder::labelset_t Builder::match_ip4(int i1, int i2, int i3, int i4, int mask)

0 commit comments

Comments
 (0)