1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
|
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
// Copyright (c) 2001-2009 XORP, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2, June
// 1991 as published by the Free Software Foundation. Redistribution
// and/or modification of this program under the terms of any other
// version of the GNU General Public License is not permitted.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
// see the GNU General Public License, Version 2, a copy of which can be
// found in the XORP LICENSE.gpl file.
//
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net
#ident "$XORP: xorp/pim/pim_scope_zone_table.cc,v 1.18 2009/01/05 18:31:03 jtc Exp $"
//
// PIM scope zone table implementation.
//
#include "pim_module.h"
#include "libxorp/xorp.h"
#include "libxorp/xlog.h"
#include "libxorp/debug.h"
#include "libxorp/ipvx.hh"
#include "pim_scope_zone_table.hh"
//
// Exported variables
//
//
// Local constants definitions
//
//
// Local structures/classes, typedefs and macros
//
//
// Local variables
//
//
// Local functions prototypes
//
/**
* PimScopeZoneId::PimScopeZoneId:
* @scope_zone_prefix: The scope zone address prefix.
* @is_scope_zone: If true, this is administratively scoped zone, otherwise
* this is the global zone.
*
* PimScopeZoneId constructor.
**/
PimScopeZoneId::PimScopeZoneId(const IPvXNet& scope_zone_prefix,
bool is_scope_zone)
: _scope_zone_prefix(scope_zone_prefix),
_is_scope_zone(is_scope_zone)
{
}
/**
* Equality Operator
*
* @param other the right-hand operand to compare against.
* @return true if the left-hand operand is numerically same as the
* right-hand operand.
*/
bool
PimScopeZoneId::operator==(const PimScopeZoneId& other) const
{
return ((scope_zone_prefix() == other.scope_zone_prefix())
&& (is_scope_zone() == other.is_scope_zone()));
}
/**
* PimScopeZoneId::is_overlap:
*
* Tehst whether a scope zone overlaps with another zone.
*
* @param other the other scope zone ID to compare against.
* @return true if both zones are scoped and the the scope zone prefixes
* for this zone and @other do overlap.
*/
bool
PimScopeZoneId::is_overlap(const PimScopeZoneId& other) const
{
return (is_scope_zone()
&& other.is_scope_zone()
&& scope_zone_prefix().is_overlap(other.scope_zone_prefix()));
}
/**
* PimScopeZoneId::contains:
* @ipvxnet: The subnet address to compare whether is contained within this
* scope zone.
*
* Test whether a scope zone contains a subnet address.
*
* Return value: true if this scope zone contains @ipvxnet, otherwise false.
**/
bool
PimScopeZoneId::contains(const IPvXNet& ipvxnet) const
{
return (scope_zone_prefix().contains(ipvxnet));
}
/**
* PimScopeZoneId::contains:
* @ipvx: The address to compare whether is contained within this
* scope zone.
*
* Test whether a scope zone contains an address.
*
* Return value: true if this scope zone contains @ipvx, otherwise false.
**/
bool
PimScopeZoneId::contains(const IPvX& ipvx) const
{
return (scope_zone_prefix().contains(ipvx));
}
/**
* PimScopeZoneId::str:
*
* Convert this scope zone ID from binary for to presentation format.
*
* Return value: C++ string with the human-readable ASCII representation
* of the scope zone ID.
**/
string
PimScopeZoneId::str() const
{
return (c_format("%s(%s)", _scope_zone_prefix.str().c_str(),
_is_scope_zone? "scoped" : "non-scoped"));
}
/**
* PimScopeZoneTable::PimScopeZoneTable:
* @pim_node: The associated PIM node.
*
* PimScopeZoneTable constructor.
**/
PimScopeZoneTable::PimScopeZoneTable(PimNode& pim_node)
: _pim_node(pim_node)
{
}
/**
* PimScopeZoneTable::~PimScopeZoneTable:
* @:
*
* PimScopeZoneTable destructor.
*
**/
PimScopeZoneTable::~PimScopeZoneTable()
{
}
/**
* PimScopeZoneTable::add_scope_zone:
* @scope_zone_prefix: The prefix address of the zone to add.
* @vif_index: The vif index of the interface to add as zone boundary.
*
* Add a scope zone.
**/
void
PimScopeZoneTable::add_scope_zone(const IPvXNet& scope_zone_prefix,
uint32_t vif_index)
{
// Test first if we have that scope zone already
list<PimScopeZone>::iterator iter;
for (iter = _pim_scope_zone_list.begin();
iter != _pim_scope_zone_list.end();
++iter) {
PimScopeZone& pim_scope_zone = *iter;
if (pim_scope_zone.is_same_scope_zone(scope_zone_prefix)) {
// We already have entry for this scope zone
pim_scope_zone.set_scoped_vif(vif_index, true);
return;
}
}
// Add the new scope
Mifset scoped_vifs;
scoped_vifs.set(vif_index);
PimScopeZone pim_scope_zone(scope_zone_prefix, scoped_vifs);
_pim_scope_zone_list.push_back(pim_scope_zone);
}
/**
* PimScopeZoneTable::delete_scope_zone:
* @scope_zone_prefix: The prefix address of the zone to delete.
* @vif_index: The vif index of the interface to delete as zone boundary.
*
* Delete a scope zone.
**/
void
PimScopeZoneTable::delete_scope_zone(const IPvXNet& scope_zone_prefix,
uint32_t vif_index)
{
// Find the scope zone and delete it
list<PimScopeZone>::iterator iter;
for (iter = _pim_scope_zone_list.begin();
iter != _pim_scope_zone_list.end();
++iter) {
PimScopeZone& pim_scope_zone = *iter;
if (pim_scope_zone.is_same_scope_zone(scope_zone_prefix)) {
// Found
pim_scope_zone.set_scoped_vif(vif_index, false);
// If last scope zone boundary, remove the entry
if (pim_scope_zone.is_empty())
_pim_scope_zone_list.erase(iter);
return;
}
}
}
/**
* PimScopeZoneTable::is_scoped:
* @addr: The address to test whether it is scoped.
* @vif_index: The vif index of the interface to test.
*
* Test if address @addr is scoped on interface with vif index of @vif_index.
* Note that we test against all scope zones until a scoping one is found.
*
* Return value: True if @addr is scoped on @vif_index, otherwise false.
**/
bool
PimScopeZoneTable::is_scoped(const IPvX& addr, uint32_t vif_index) const
{
list<PimScopeZone>::const_iterator iter;
for (iter = _pim_scope_zone_list.begin();
iter != _pim_scope_zone_list.end();
++iter) {
const PimScopeZone& pim_scope_zone = *iter;
if (pim_scope_zone.is_scoped(addr, vif_index))
return (true);
}
return (false);
}
/**
* PimScopeZoneTable::is_scoped:
* @zone_id: The zone ID to test whether it is scoped.
* @vif_index: The vif index of the interface to test.
*
* Test if zone with zone ID of @zone_id is scoped on interface with
* vif index of @vif_index.
* Note that we test against all scope zones until a scoping one is found.
*
* Return value: True if @zone_id is scoped on @vif_index, otherwise false.
**/
bool
PimScopeZoneTable::is_scoped(const PimScopeZoneId& zone_id,
uint32_t vif_index) const
{
if (! zone_id.is_scope_zone())
return (false);
list<PimScopeZone>::const_iterator iter;
for (iter = _pim_scope_zone_list.begin();
iter != _pim_scope_zone_list.end();
++iter) {
const PimScopeZone& pim_scope_zone = *iter;
if (pim_scope_zone.is_scoped(zone_id, vif_index))
return (true);
}
return (false);
}
/**
* PimScopeZoneTable::is_zone_border_router:
* @group_prefix: The group prefix to test.
*
* Test if the router is a Zone Border Router (ZBR) for @group_prefix.
*
* Return value: True if the router is a ZBR for @group_prefix, otherwise
* false.
**/
bool
PimScopeZoneTable::is_zone_border_router(const IPvXNet& group_prefix) const
{
list<PimScopeZone>::const_iterator iter;
for (iter = _pim_scope_zone_list.begin();
iter != _pim_scope_zone_list.end();
++iter) {
const PimScopeZone& pim_scope_zone = *iter;
if (pim_scope_zone.scope_zone_prefix().contains(group_prefix))
return (true);
}
return (false);
}
/**
* PimScopeZone::PimScopeZone:
* @scope_zone_prefix: The scope zone address prefix.
* @scoped_vifs: The bitmask with the vifs that are zone boundary.
*
* PimScopeZone constructor.
**/
PimScopeZone::PimScopeZone(const IPvXNet& scope_zone_prefix,
const Mifset& scoped_vifs)
: _scope_zone_prefix(scope_zone_prefix),
_scoped_vifs(scoped_vifs)
{
}
/**
* PimScopeZone::~PimScopeZone:
* @:
*
* PimScopeZone destructor.
**/
PimScopeZone::~PimScopeZone()
{
}
/**
* PimScopeZone::set_scoped_vif:
* @vif_index: The vif index of the interface to set or reset.
* @v: If true, set the interface as a boundary for this scope zone,
* otherwise reset it.
*
* Set or reset an interface as a boundary for this scope zone.
**/
void
PimScopeZone::set_scoped_vif(uint32_t vif_index, bool v)
{
if (vif_index < _scoped_vifs.size()) {
if (v)
_scoped_vifs.set(vif_index);
else
_scoped_vifs.reset(vif_index);
}
}
/**
* PimScopeZone::is_scoped:
* @addr: The address to test whether it is scoped.
* @vif_index: The vif index of the interface to test.
*
* Test if address @addr is scoped on interface with vif index of @vif_index.
*
* Return value: True if @addr is scoped on @vif_index, otherwise false.
**/
bool
PimScopeZone::is_scoped(const IPvX& addr, uint32_t vif_index) const
{
if (! _scope_zone_prefix.contains(addr))
return (false);
return (is_set(vif_index));
}
/**
* PimScopeZone::is_scoped:
* @zone_id: The zone ID to test whether it is scoped.
* @vif_index: The vif index of the interface to test.
*
* Test if zone with zone ID of @zone_id is scoped on interface with
* vif index of @vif_index.
*
* Return value: True if @zone_id is scoped on @vif_index, otherwise false.
**/
bool
PimScopeZone::is_scoped(const PimScopeZoneId& zone_id,
uint32_t vif_index) const
{
if (! zone_id.is_scope_zone())
return (false);
// XXX: scoped zones don't nest, hence if the scope zone prefixes
// do overlap, then there is scoping.
if (! _scope_zone_prefix.is_overlap(zone_id.scope_zone_prefix()))
return (false);
return (is_set(vif_index));
}
/**
* PimScopeZone::is_set:
* @vif_index: The vif index of the interface to test.
*
* Test if an interface is a boundary for this scope zone.
*
* Return value: True if the tested interface is a boundary for this scope
* zone, otherwise false.
**/
bool
PimScopeZone::is_set(uint32_t vif_index) const
{
if (vif_index < _scoped_vifs.size())
return (_scoped_vifs.test(vif_index));
return (false);
}
/**
* PimScopeZone::is_same_scope_zone:
* @scope_zone_prefix: The prefix address to test if it is the prefix
* address of this scope zone.
*
* Test if this scope zone prefix address is same as @scope_zone_prefix.
*
* Return value: True if @scope_zone_prefix is same prefix address
* as the prefix address of this scope zone, otherwise false.
**/
bool
PimScopeZone::is_same_scope_zone(const IPvXNet& scope_zone_prefix) const
{
return (_scope_zone_prefix == scope_zone_prefix);
}
|