Skip to content
Snippets Groups Projects
Commit 5a680e29 authored by Piotr's avatar Piotr
Browse files

removing redundant flow routes from routing transformation

parent 3466d943
No related branches found
No related tags found
No related merge requests found
......@@ -493,6 +493,69 @@
</nextHop>
</hops>
</routes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.131 to node_with_IP_192.168.132.133" id="id40144" flow="id11" start="id1" end="id3">
<hops interfaceref="id1">
<nextHop interfaceref="id32">
<nextHop interfaceref="id34">
<nextHop interfaceref="id3"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.131 to node_with_IP_192.168.132.133" id="id53070" flow="id12" start="id1" end="id3">
<hops interfaceref="id1">
<nextHop interfaceref="id32">
<nextHop interfaceref="id34">
<nextHop interfaceref="id3"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.131 to node_with_IP_192.168.132.133" id="id83240" flow="id13" start="id1" end="id3">
<hops interfaceref="id1">
<nextHop interfaceref="id32">
<nextHop interfaceref="id34">
<nextHop interfaceref="id3"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.131 to node_with_IP_192.168.132.133" id="id72767" flow="id14" start="id1" end="id3">
<hops interfaceref="id1">
<nextHop interfaceref="id32">
<nextHop interfaceref="id34">
<nextHop interfaceref="id3"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.133 to node_with_IP_192.168.132.131" id="id87876" flow="id21" start="id3" end="id1">
<hops interfaceref="id3">
<nextHop interfaceref="id34">
<nextHop interfaceref="id32">
<nextHop interfaceref="id1"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.133 to node_with_IP_192.168.132.131" id="id95616" flow="id22" start="id3" end="id1">
<hops interfaceref="id3">
<nextHop interfaceref="id34">
<nextHop interfaceref="id32">
<nextHop interfaceref="id1"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
<flowRoutes name="FlowRoute from node_with_IP_192.168.132.133 to node_with_IP_192.168.132.131" id="id34822" flow="id23" start="id3" end="id1">
<hops interfaceref="id3">
<nextHop interfaceref="id34">
<nextHop interfaceref="id32">
<nextHop interfaceref="id1"/>
</nextHop>
</nextHop>
</hops>
</flowRoutes>
</routes>
</configuration>
</master:NetworkInfrastructure>
......@@ -11,6 +11,21 @@ post renameDashes{
}
operation generateUniqueId() : String{
var all = DNI.getAllOfKind("Entity");
var all_ids = all.collect(a|a.id);
var int = getRandomInt(100,99999);
var idCandidate = "id"+int;
while(all_ids.contains(idCandidate)){
int = getRandomInt(100,99999);
idCandidate = "id"+int;
}
return idCandidate;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////// RULES ///
//////////////////////////////////////////////////////////////////////
......@@ -29,8 +44,7 @@ rule Flow2Route
("====== Looking for route betwwen "+start_node.name+" and "+dest_node.name).println;
route.name = "FlowRoute from "+start_node.name+" to "+dest_node.name;
route.id = start_node.name+dest_node.name+flow.id;
route.id = generateUniqueId(); //start_node.name+dest_node.name+flow.id;
route.flow = flow;
......@@ -77,7 +91,22 @@ rule Flow2Route
var repo = DNI.getAllOfType("RoutesRepository").first();
repo.flowRoutes.add(route);
//route.getRouteForInterfaces(flow, iface, end, dirs);
//removing duplicate flow routes
var toRemove : OrderedSet;
for(fr1 in repo.flowRoutes){
for(fr2 in repo.flowRoutes){
if(fr1.id <> fr2.id and flowRoutesIdentic(fr1,fr2) and not toRemove.contains(fr1) and not toRemove.contains(fr2)){
("\t Removing duplicate route "+fr1.id+" - is identic with "+fr2.id).println();
toRemove.add(fr1);
}
}
}
for(r in toRemove){
repo.flowRoutes.remove(r);
}
}//rule
......@@ -312,6 +341,19 @@ operation getNextInterface(curr : DNI!NetworkInterface) : DNI!NetworkInterface{
return iface;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
operation Any printFlowRoute() : String{
if(self.isKindOf(DNI!FlowRoute) and self.isDefined()){
return "implement me";
}
else{
return "implement me";
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
operation Any printIface() : String{
......@@ -329,7 +371,53 @@ operation Any printIface() : String{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
operation flowRoutesIdentic(r1 : DNI!FlowRoute, r2 : DNI!FlowRoute) : Boolean {
("Comparing routes "+r1.id+" with "+r2.id).println();
if(r1.flow.id <> r2.flow.id){
//("\t different: flows. r1 "+r1.flow.id+" r2 "+r2.flow.id).println();
return false;
}
if(r1.start.id <> r2.start.id){
//("\t different: start").println();
return false;
}
if(r1.end.id <> r2.end.id){
//("\t different: end").println();
return false;
}
if(r1.hops.isDefined() and r2.hops.isDefined()){
var hop1 = r1.hops;
var hop2 = r2.hops;
if(hop1.interfaceref.id <> hop2.interfaceref.id){
//("\t different: first hop").println();
return false;
}
while(hop1.nextHop.isDefined() and hop2.nextHop.isDefined()){
hop1 = hop1.nextHop;
hop2 = hop2.nextHop;
if(hop1.interfaceref.id <> hop2.interfaceref.id){
//("\t different: some hop").println();
return false;
}
}
//end of while - some of hops' nextHop was null
if(hop1.nextHop.isUndefined() and hop2.nextHop.isDefined() or hop1.nextHop.isUndefined() and hop2.nextHop.isDefined()){
//("\t different: differend lengths").println();
return false;
}
if(hop1.nextHop.isUndefined() and hop2.nextHop.isUndefined() and hop1.interfaceref.id == r1.end.id and hop2.interfaceref.id == r2.end.id and r1.end.id == r2.end.id){
return true;
}
}
("\t flowRoutesIdentic shall never get here").println();
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
operation DNI!Flow getFlowSourceAsNode() : DNI!Node {
if(self.sourceSoftwareComponent.isDefined()){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment