Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "ifmap/ifmap_util.h" 6 : 7 : #include <boost/foreach.hpp> 8 : #include <boost/tuple/tuple.hpp> 9 : #include "ifmap/ifmap_link.h" 10 : #include "ifmap/ifmap_log.h" 11 : #include "ifmap/ifmap_log_types.h" 12 : #include "ifmap/ifmap_node.h" 13 : #include "ifmap/ifmap_table.h" 14 : 15 : using namespace std; 16 : 17 22 : bool IFMapTypenameFilter::VertexFilter(const DBGraphVertex *vertex) const { 18 22 : const IFMapNode *node = static_cast<const IFMapNode *>(vertex); 19 22 : if (exclude_vertex.find(node->table()->Typename()) != exclude_vertex.end()) { 20 4 : return false; 21 : } else { 22 18 : return true; 23 : } 24 : } 25 : 26 36 : bool IFMapTypenameFilter::EdgeFilter(const DBGraphVertex *source, 27 : const DBGraphVertex *target, 28 : const DBGraphEdge *edge) const { 29 36 : const IFMapNode *node = static_cast<const IFMapNode *>(source); 30 36 : VertexEdgeMap::const_iterator it = exclude_edge.find(node->table()->Typename()); 31 36 : if (it == exclude_edge.end()) return true; 32 14 : const IFMapLink *link = static_cast<const IFMapLink *>(edge); 33 14 : if (it->second.find(link->name()) != it->second.end()) { 34 8 : return false; 35 : } else { 36 6 : return true; 37 : } 38 : } 39 : 40 18 : DBGraph::VisitorFilter::AllowedEdgeRetVal IFMapTypenameFilter::AllowedEdges( 41 : const DBGraphVertex *source) const { 42 36 : return std::make_pair(true, DBGraph::VisitorFilter::AllowedEdgeSet()); 43 : } 44 : 45 : // Return true if the node-type is in the white list 46 924 : bool IFMapTypenameWhiteList::VertexFilter(const DBGraphVertex *vertex) const { 47 924 : const IFMapNode *node = static_cast<const IFMapNode *>(vertex); 48 924 : if (include_vertex.find(node->table()->Typename()) != include_vertex.end()) { 49 918 : return true; 50 : } else { 51 6 : return false; 52 : } 53 : } 54 : 55 501 : DBGraph::VisitorFilter::AllowedEdgeRetVal IFMapTypenameWhiteList::AllowedEdges( 56 : const DBGraphVertex *source) const { 57 501 : const IFMapNode *node = static_cast<const IFMapNode *>(source); 58 501 : VertexEdgeMap::const_iterator it = include_vertex.find(node->table()->Typename()); 59 501 : assert(it != include_vertex.end()); 60 1002 : return std::make_pair(false, it->second); 61 : } 62 : 63 419 : bool IFMapTypenameWhiteList::EdgeFilter(const DBGraphVertex *source, 64 : const DBGraphVertex *target, 65 : const DBGraphEdge *edge) const { 66 419 : const IFMapNode *node = static_cast<const IFMapNode *>(source); 67 419 : VertexEdgeMap::const_iterator it = include_vertex.find(node->table()->Typename()); 68 419 : if (it == include_vertex.end()) { 69 0 : IFMAP_WARN(IFMapIdentifierNotFound, "Cant find vertex", 70 : node->table()->Typename()); 71 0 : return false; 72 : } 73 419 : const IFMapLink *link = static_cast<const IFMapLink *>(edge); 74 419 : if (it->second.find(link->name()) != it->second.end()) { 75 290 : return true; 76 : } else { 77 129 : return false; 78 : } 79 : }