namespace skypesim; import DSM.metamodel.SkypeSim.SkypeSimEditor; @incremental machine Final_Rules_Random { pattern RS_RG_SC(RS,SC,RG) = { SC(SC); RS(RS); RS.register(RG,RS,SC); } pattern RS_rg_SN(RS,SN,RG) = { SN(SN); RS(RS); RS.RSoverlay(RG,RS,SN); } pattern SC_Chronos(SC,CRO) = { SC(SC); SkypeNode.Chronos(CRO); SkypeNode.chronos(CRR,SC,CRO); } pattern SN_Chronos(SN,CRO) = { SN(SN); SkypeNode.Chronos(CRO); SkypeNode.chronos(CRR,SN,CRO); } pattern SC_Exit(SC,EX) = { SC(SC); SkypeNode.Exit(EX); SkypeNode.exit(EXR,SC,EX); } pattern SN_Exit(SN,EX) = { SN(SN); SkypeNode.Exit(EX); SkypeNode.exit(EXR,SN,EX); } pattern SN_Bandwidth(SN,BW)= { SN(SN); SkypeNode.Bandwidth(BW); SkypeNode.bandwidth(BWR,SN,BW); } pattern SC_Bandwidth(SC,BW)= { SC(SC); SkypeNode.Bandwidth(BW); SkypeNode.bandwidth(BWR,SC,BW); } gtrule Rule1_Create_Client_Firewall_ON() = { precondition pattern lhs(RS,Network) = { RS(RS); Network(Network); } action { let SC1=undef, K=undef, KR=undef, C=undef, CR=undef, B=undef, BR=undef, CH=undef, CHR=undef, JI=undef, JR=undef, CP=undef, CPR=undef, PP=undef, PPR=undef, NR=undef, EX=undef, EXR=undef, RG=undef in seq { new(SC(SC1)in Network);// create client inside the network new(SC.Firewall(K)in SC1); // create attribute firewall in the SC setValue(K,"True");// set firewall value new(SC.firewall(KR,SC1,K));// create relation between the SC and attribute new(SkypeNode.Memory(C)in SC1); setValue(C,skypesim.random(500,4000)); // use random function to assign valye to memory new(SkypeNode.memory(CR,SC1,C)); new(SkypeNode.Bandwidth(B) in SC1); setValue(B,skypesim.random(56,200)); // use random function to assign bandwidth new(SkypeNode.bandwidth(BR,SC1,B)); new(SkypeNode.Chronos(CH) in SC1); setValue(CH,systime()); // System Time // set chronos to system time new(SkypeNode.chronos(CHR,SC1,CH)); new(SkypeNode.Jitter(JI) in SC1); new(SkypeNode.jitter(JR,SC1,JI)); new(SkypeNode.CurrPacket(CP) in SC1); new(SkypeNode.currPacket(CPR,SC1,CP)); new(SkypeNode.PrevPacket(PP) in SC1); new(SkypeNode.prevPacket(PPR,SC1,PP)); new(SkypeNode.Exit(EX) in SC1); new(SkypeNode.exit(EXR,SC1,EX)); new(Network.nodes(NR,Network,SC1)); new(RS.register(RG,RS,SC1)); //rename(SC1,"sc"); setValue(EX,"False");// set default Exit to false println("SC created, registered and Attribute Memory is set="+fqn(K)); // println("SC created, registered and Attribute Memory is set="+value(K)); } } } gtrule Rule2_Rule1_Create_Client_Firewall_off() = { precondition pattern lhs(RS,Network) = { RS(RS); Network(Network); } action { let SC1=undef, K=undef, KR=undef, C=undef, CR=undef, B=undef, BR=undef, CH=undef, CHR=undef, JI=undef, JR=undef, CP=undef, CPR=undef, PP=undef, PPR=undef, NR=undef, EX=undef, EXR=undef, RG=undef in seq { new(SC(SC1)in Network);// create client inside the network new(SC.Firewall(K)in SC1); // create attribute firewall in the SC setValue(K,"False");// set firewall value new(SC.firewall(KR,SC1,K));// create relation between the SC and attribute new(SkypeNode.Memory(C)in SC1); setValue(C,skypesim.random(500,4000)); // use random function to assign valye to memory new(SkypeNode.memory(CR,SC1,C)); new(SkypeNode.Bandwidth(B) in SC1); setValue(B,skypesim.random(201,20000)); // use random function to assign bandwidth new(SkypeNode.bandwidth(BR,SC1,B)); new(SkypeNode.Chronos(CH) in SC1); setValue(CH,systime()); // System Time // set chronos to system time new(SkypeNode.chronos(CHR,SC1,CH)); new(SkypeNode.Jitter(JI) in SC1); new(SkypeNode.jitter(JR,SC1,JI)); new(SkypeNode.CurrPacket(CP) in SC1); new(SkypeNode.currPacket(CPR,SC1,CP)); new(SkypeNode.PrevPacket(PP) in SC1); new(SkypeNode.prevPacket(PPR,SC1,PP)); new(Network.nodes(NR,Network,SC1)); new(SkypeNode.Exit(EX) in SC1); setValue(EX,"False");// set default Exit to false new(SkypeNode.exit(EXR,SC1,EX)); new(RS.register(RG,RS,SC1)); rename(SC1,"sc"); println("SC created, registered and Attribute Memory is set="+fqn(K)); // println("SC created, registered and Attribute Memory is set="+value(K)); } } } // this rule select random Super Node and establish AddressOf edge with it. // If a super Node is not linked and it is currently haveing edge with super node then it send // a time stamp packet to find the round trip latency // this rule provide three addresses to the SC and then SC slect one of them for conection pattern address_check(SC)= { SC(SC); find link(SC); } pattern no_address(SC) = { SC(SC); neg find address_check(SC); } pattern link(SC)= { SC(SC); SN(SN); SN(SN1); SN(SN2); SN.addressOf(AD,SN,SC); SN.addressOf(AD1,SN1,SC); SN.addressOf(AD2,SN2,SC); } pattern lhs(SC,SN) = { SN(SN); SC(SC); neg find address_check(SC); find RS_RG_SC(RS,SC,RG); find SC_Chronos(SC,CRO); find SN_Exit(SN,EX); neg find Address_link(SC,SN); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); neg find Link_SN(SC); check((toInteger(value(BW)))>256); check((value(EX))=="False"); } gtrule Rule3a_Select_Super_Node_to_SN(out SC, out SN) = { precondition find lhs(SC,SN) action { let RGI=undef in new(SN.addressOf(RGI,SN,SC)); println("SC address has been to SN"); } } pattern SN_address_check(SC)= { SC(SC); SN(SN); find Address_link(SC,SN); } pattern Address_link(SC,SN)= { SC(SC); SN(SN); SN.addressOf(ADI,SN,SC); } // this Rule Create Time Stamp Packet and send it to the Selected Super Node pattern Packet_SE_check(SC)= { SC(SC); Packet(PK); Packet.sender(SE,PK,SC); } pattern Packet_RE_check(SC)= { SC(SC); Packet(PK); Packet.receiver(SE,PK,SC); } gtrule Rule3b_Send_Time_Stamp_Packet_to_SN() = { precondition pattern lhs(SC,SN,CRO) = { SN(SN); find SC_Chronos(SC,CRO); neg find Link_SN(SC); find Address_link(SC,SN); neg find Packet_SE_check(SC); neg find Packet_RE_check(SC); } action { let Packet=undef, PC=undef, CRR=undef, PCO=undef, PCR=undef, SE=undef, RE=undef, AH=undef in seq { new(Packet(Packet)in SN); //Create Packet in SC new(Packet.Chronos(PC)in Packet); //Create a chronos attribute in Packet new(Packet.chronos(CRR,Packet,PC));//Create a relation between packet and Chronos entity new(Packet.Content(PCO)in Packet);//Create a content attribute in Packet new(Packet.content(PCR,Packet,PCO));//Create a relation between packet and content entity new(Packet.sender(SE,Packet,SC)); // Create a relation new(Packet.receiver(RE,Packet,SN)); // Create a relation new(Packet.at(AH,Packet,SN)); // Create a relation setValue(CRO,systime()); setValue(PC,value(CRO)); setValue(PCO,"Ping"); println("Ping Packet Created"); } } } // This rule send back the Packet with ACK if satisfies the badwidth constraint // and it is not going to exit from Network pattern Packet_reciver_Check(Packet,SN,RE)= { Packet(Packet); SN(SN); Packet.receiver(RE,Packet,SN); } pattern Packet_sender_Check(Packet,SC,SE)= { Packet(Packet); SC(SC); Packet.sender(SE,Packet,SC); } pattern Packet_at_Check(Packet,SN,AT)= { Packet(Packet); SN(SN); Packet.at(AT,Packet,SN); } pattern Packet_Content(Packet,CONT)= { Packet(Packet); Packet.Content(CONT); Packet.content(CI,Packet,CONT); } // this send back the time stamp packet gtrule Rule3c_Revers_Time_Stamp_Packet_to_SN() = { precondition pattern lhs(Packet,CONT,SN,SC,SE,RE,AT,CO) = { Packet(Packet); find Packet_reciver_Check(Packet,SN,RE); find Packet_sender_Check(Packet,SC,SE); find Packet_at_Check(Packet,SN,AT); find Packet_Content(Packet,CONT); find SC_Chronos(SC,CRO); find Packet_Chronos(Packet,CO); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); check((toInteger(value(BW)))>256); check((value(EX))=="False"); check((value(CONT))=="Ping"); } action { let NSE=undef,NRE=undef,NAT=undef in seq { new (Packet.sender(NSE,Packet,SN)); new(Packet.receiver(NRE,Packet,SC)); new(Packet.at(NAT,Packet,SC)); move(Packet,SC); } delete (SE); delete (RE); delete (AT); setValue(CONT,"AcK"); setValue(CO,systime()); println("Ping Replied Back"); }} // Return DNY if Controlled EXIT is True gtrule Rule3d_Revers_DnY_Stamp_Packet_to_SN() = { precondition pattern lhs(Packet,CONT,SN,SC,SE,RE,AT,CO) = { Packet(Packet); find Packet_reciver_Check(Packet,SN,RE); find Packet_sender_Check(Packet,SC,SE); find Packet_at_Check(Packet,SN,AT); find Packet_Content(Packet,CONT); find SC_Chronos(SC,CRO); find Packet_Chronos(Packet,CO); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); check((value(EX))=="True"); check((value(CONT))=="Ping"); } action { let NSE=undef,NRE=undef,NAT=undef in seq { new (Packet.sender(NSE,Packet,SN)); new(Packet.receiver(NRE,Packet,SC)); new(Packet.at(NAT,Packet,SC)); move(Packet,SC); } delete (SE); delete (RE); delete (AT); setValue(CONT,"DnY"); setValue(CO,systime()); println("Ping Replied Back"); }} gtrule Rule3e_Revers_DnY_Stamp_Packet_to_SN() = { precondition pattern lhs(Packet,CONT,SN,SC,SE,RE,AT,CO) = { Packet(Packet); find Packet_reciver_Check(Packet,SN,RE); find Packet_sender_Check(Packet,SC,SE); find Packet_at_Check(Packet,SN,AT); find Packet_Content(Packet,CONT); find SC_Chronos(SC,CRO); find Packet_Chronos(Packet,CO); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); check((toInteger(value(BW)))<256); check((value(CONT))=="Ping"); } action { let NSE=undef,NRE=undef,NAT=undef in seq { new (Packet.sender(NSE,Packet,SN)); new(Packet.receiver(NRE,Packet,SC)); new(Packet.at(NAT,Packet,SC)); move(Packet,SC); } delete (SE); delete (RE); delete (AT); setValue(CONT,"DnY"); setValue(CO,systime()); println("Ping Replied Back"); }} pattern SN_address_check(SC,SN,ADR)= { SN(SN); SC(SC); SN.addressOf(ADR,SN,SC); } gtrule Rule3f_delete_ping__andSelect_Another_SN() = { precondition pattern lhs(RS,SC,SN,RG,Network,Packet,CONT,PCO,CRO,BW,SCBW,ADR) = { SN(SN); Network(Network); Packet(Packet); find Packet_at_Check_SC(Packet,SC); find RS_RG_SC(RS,SC,RG); find Packet_Content(Packet,CONT); find Packet_Chronos(Packet,PCO); find SC_Chronos(SC,CRO); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); find SN_address_check(SC,SN,ADR); neg find Link_SN(SC); check((value(CONT))=="DnY"); } action { delete(ADR); delete(Packet); println("Connection refused by SN"); } } pattern test_links(SC)= { SC(SC); find Link_SN(SC); } pattern Link_SN(SC)= { LK(LK); SC(SC); LK.linkto(CO,LK,SC); } pattern Packet_at_Check_SC(Packet,SC)= { Packet(Packet); SC(SC); Packet.at(AT,Packet,SC); } pattern Packet_Chronos(Packet,CO)= { Packet(Packet); Packet.Chronos(CO); Packet.chronos(CI,Packet,CO); } gtrule Rule3_Link_SC_to_SN() = { precondition pattern lhs(RS,SC,SN,RG,Network,Packet,CONT,PCO,CRO,BW,SCBW,ADR) = { SN(SN); Network(Network); Packet(Packet); find Packet_at_Check_SC(Packet,SC); find RS_RG_SC(RS,SC,RG); find Packet_Content(Packet,CONT); find Packet_Chronos(Packet,PCO); find SC_Chronos(SC,CRO); find SN_Bandwidth(SN,BW); find SN_address_check(SC,SN,ADR); find SC_Bandwidth(SC,SCBW); neg find Link_SN(SC); check((value(CONT))=="AcK"); check(((toInteger(value(PCO)))- (toInteger(value(CRO))))<= toInteger(300)); } action { setValue(CRO,systime()); let LK=undef, CO=undef,OU=undef,NR=undef in seq{ new (LK(LK) in Network); new(Network.nodes(NR,Network,LK)); new(LK.linkto(CO,LK,SC)); new(LK.outTo(OU,LK,SN)); delete(RG); setValue(BW,((toInteger(value(BW)))-5)); setValue(SCBW,((toInteger(value(SCBW)))-5)); delete(ADR); delete(Packet); println("connected/Linked and round trip time taken is "+((toInteger(value(PCO)))- (toInteger(value(CRO))))); } } } pattern Link_SC_LK(SC,LK)= { LK(LK); SC(SC); LK.linkto(LKI,LK,SC); } pattern Link_SN_LK(SN,LK)= { LK(LK); SN(SN); LK.outTo(LKIT,LK,SN); } pattern Test_SN_LK(LK)= { LK(LK); SN(SN); find Link_SN_LK(SN,LK); } gtrule Rule4_Reconfigure_Link_SC_to_link_back_SN() = { precondition pattern lhs(RS,LK,SN,SC,BW,CRO) = { LK(LK); SN(SN); SC(SC); RS(RS); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SC_Chronos(SC,CRO); find Link_SC_LK(SC,LK); neg find Packet_SE_check(SC); neg find Packet_RE_check(SC); neg find Link_SN_LK(SN,LK); neg find Test_SN_LK(LK); check((toInteger(value(BW)))>256); check((value(EX))=="False"); } action { delete(LK); let ADD=undef in new (SN.addressOf(ADD,SN,SC)); println("Super Node selected for Linking"); let RG=undef in new (RS.register(RG,RS,SC)); let Packet=undef, PC=undef, CRR=undef, PCO=undef, PCR=undef, SE=undef, RE=undef, AH=undef in seq { new(Packet(Packet)in SN); //Create Packet in SC new(Packet.Chronos(PC)in Packet); //Create a chronos attribute in Packet new(Packet.chronos(CRR,Packet,PC));//Create a relation between packet and Chronos entity new(Packet.Content(PCO)in Packet);//Create a content attribute in Packet new(Packet.content(PCR,Packet,PCO));//Create a relation between packet and content entity new(Packet.sender(SE,Packet,SC)); // Create a relation new(Packet.receiver(RE,Packet,SN)); // Create a relation new(Packet.at(AH,Packet,SN)); // Create a relation setValue(CRO,systime()); setValue(PC,value(CRO)); setValue(PCO,"Ping"); println("Ping Packet Created and Transmited "); } } } pattern SC_firewall(SC,FIRW) = { SC(SC); SC.Firewall(FIRW); SC.firewall(FIRWR,SC,FIRW); } pattern firstSN(RS)= { RS(RS); SN(SN); find RS_rg_SN(RS,SN,RG); } gtrule Rule5_Promote_at_Registration_Super_Node() = { precondition pattern lhs(SC,RS,RG,BW) = { SC(SC); RS(RS); find SC_firewall(SC,FIRW); find RS_RG_SC(RS,SC,RG); find SC_Bandwidth(SC,BW); check((value(FIRW))=="False"); check((toInteger(value(BW)))>= 8000); } action { new(instanceOf(SC,DSM.metamodel.SkypeSim.SkypeSimEditor.SN)); let RG1=undef in seq{ new (RS.RSoverlay(RG1,RS,SC)); rename(SC,"sn"); delete(instanceOf(SC,DSM.metamodel.SkypeSim.SkypeSimEditor.SC)); delete(RG); } println("promoted to Supere Node at registration"); //println("Rule executed "+fqn(SC)); } } pattern SC_Linked_SN(SC,SN,LK)= { SC(SC); SN(SN); LK(LK); LK.linkto(LT,LK,SC); LK.outTo(LO,LK,SN); } gtrule Rule6_Promote_at_Linked_Super_Node() = { precondition pattern lhs(SC,RS,LK,BW) = { SC(SC); RS(RS); LK(LK); find SC_Linked_SN(SC,SN,LK); find SC_firewall(SC,FIRW); find SC_Bandwidth(SC,BW); check((value(FIRW))=="False"); check((toInteger(value(BW)))>= 8000); } action { new(instanceOf(SC,DSM.metamodel.SkypeSim.SkypeSimEditor.SN)); let RG1=undef in seq{ new (RS.RSoverlay(RG1,RS,SC)); rename(SC,"sn"); delete(instanceOf(SC,DSM.metamodel.SkypeSim.SkypeSimEditor.SC)); delete(LK); } println(" promoted to Supere Node"); } } pattern SN_SN(SN,SN1)= { SN(SN); SN(SN1); OV(OV); OV.source(OVI,OV,SN); OV.target(OVIT,OV,SN1); } pattern SN_SN_OVI(SN,SN1,OVI)= { SN(SN); SN(SN1); SN.overlayPath(OVI,SN,SN1); } pattern SN_SN_Test(SN,SN1)= { SN(SN); SN(SN1); find SN_SN(SN,SN1); } pattern OV_Path(SN)= { SN(SN); find SN_SN(SN,SN1); find SN_SN(SN,SN2); find SN_SN(SN,SN3); find SN_SN(SN,SN4); } gtrule Rule7_connect_SN_SN() = { precondition pattern lhs(SN,SN1,BW,BWR,Network) = { RS(RS); SN(SN); SN(SN1); Network(Network); find SN_Exit(SN1,EX); find SN_Exit(SN,EX1); find SN_Bandwidth(SN,BW); find SN_Bandwidth(SN1,BWR); neg find SN_SN_Test(SN,SN1); neg find SN_SN_Test(SN1,SN); neg find OV_Path(SN); check((toInteger(value(BW)))>256); check((toInteger(value(BWR)))>256); check((value(EX))=="False"); check((value(EX1))=="False"); } action { let OV=undef, CO=undef,OU=undef,NR=undef in seq{ new (OV(OV) in Network); new(Network.nodes(NR,Network,OV)); new(OV.source(CO,OV,SN)); new(OV.target(OU,OV,SN1)); setValue(BW,((toInteger(value(BW)))-5)); setValue(BWR,((toInteger(value(BWR)))-5)); println("Connected "+fqn(SN)+"with"+fqn(SN)); } }} pattern Check_OV(SN,SN1,OV)= { SN(SN); SN(SN1); OV(OV); OV.source(OVS,OV,SN); OV.target(OVT,OV,SN1); } gtrule Rule8_Laod_Managed_SN_SNa() = { // This Rule Stablizes the SN by removing the overlay connectiones // the approch is to delete the Link object OV and update the bandwidth precondition pattern lhs(SN,BW,BWR,OV) = { SN(SN); SN(SN1); OV(OV); find SN_Bandwidth(SN,BW); find SN_Bandwidth(SN1,BWR); find Check_OV(SN,SN1,OV); check((toInteger(value(BW)))<256); } action { delete(OV); setValue(BWR,((toInteger(value(BWR)))+5)); setValue(BW,((toInteger(value(BW)))+5)); println("Edge between SN and SN1 removed Selfishely "); } } gtrule Rule8_Laod_Managed_SN_SNb() = { // This Rule Stablizes the SN by removing the overlay connectiones // the approch is to delete the Link object OV and update the bandwidth precondition pattern lhs(SN,BW,BWR,OV) = { SN(SN); SN(SN1); OV(OV); find SN_Bandwidth(SN,BW); find SN_Bandwidth(SN1,BWR); find Check_OV(SN1,SN,OV); check((toInteger(value(BW)))<256); } action { delete(OV); setValue(BWR,((toInteger(value(BWR)))+5)); setValue(BW,((toInteger(value(BW)))+5)); println("Edge between SN and SN1 removed Selfishely "); } } pattern SN_Target_Check(SN,OV,OVT)= { SN(SN); OV(OV); OV.target(OVT,OV,SN); } pattern SN_Source(SN,OV)= { SN(SN); OV(OV); OV.source(OVI,OV,SN); } pattern Test(OV)= { OV(OV); find target(OV,SN); } pattern target(OV,SN)= { OV(OV); SN(SN); OV.target(OVI,OV,SN); } pattern SN_Target(SN,OV)= { SN(SN); OV(OV); OV.target(OVI,OV,SN); } pattern Test_Target(OV)= { OV(OV); find Source(OV,SN); } pattern Source(OV,SN)= { OV(OV); SN(SN); OV.source(OVI,OV,SN); } pattern SC_Source(LK,SC)= { LK(LK); SC(SC); LK.linkto(LKR,LK,SC); } pattern SN_SC_Target(LK,SN)= { LK(LK); SN(SN); LK.outTo(LKR,LK,SN); } pattern Check_SC_SN_Link(SC,SN,LK)= { SC(SC); SN(SN); LK(LK); find SC_Source(LK,SC); find SN_SC_Target(LK,SN); } pattern SN_SC_Target(LKR,LK,SN)= { LK(LK); SN(SN); LK.outTo(LKR,LK,SN); } gtrule Rule8_Laod_Managed_SC_SN_c() = { precondition pattern lhs(SN,SC,BW,BWR,LK,RS) = { // Selfish approch // This rule remove the object LK and register back SC with RS SN(SN); SC(SC); LK(LK); RS(RS); find RS_rg_SN(RS,SN,RG); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,BWR); find Check_SC_SN_Link(SC,SN,LK); check((toInteger(value(BW)))<256); } action { let RG=undef in new (RS.register(RG,RS,SC)); delete(LK); setValue(BW,((toInteger(value(BW)))+5)); setValue(BWR,((toInteger(value(BWR)))+5)); println("SC disconnected from SN due to SN selfishness"); } } pattern Check_Links_with_SN(SN)= { LK(LK); SN(SN); LK.outTo(LKI,LK,SN); } pattern Check_OV_Links_with_SN(SN)= { OV(OV); SN(SN); OV.source(LKI,OV,SN); } or { OV(OV); SN(SN); OV.target(OVT,OV,SN); } gtrule Rule9_Down_to_SC() = { precondition pattern lhs(SN,BW,RG,RS) = { RS(RS); SN(SN); find RS_rg_SN(RS,SN,RG); find SN_Bandwidth(SN,BW); neg find Check_Links_with_SN(SN); neg find Check_OV_Links_with_SN(SN); check((toInteger(value(BW)))<256); } action { new (instanceOf(SN,DSM.metamodel.SkypeSim.SkypeSimEditor.SC)); delete (instanceOf(SN,DSM.metamodel.SkypeSim.SkypeSimEditor.SN)); delete(RG); let REG=undef in new(RS.register(REG,RS,SN)); println("Down to Ordinary SC "); } } pattern SC_Chec_for_Exit(SC)= { SC(SC); LK(LK); LK.linkto(LKI,LK,SC); } gtrule Rule10_Controlled_Exit_of_SC() = { precondition pattern lhs(SC,EX) = { SC(SC); find SC_Exit(SC,EX); check((value(EX))=="True"); } action { setValue(EX,"True"); println("SC About to Exit from Network"); } } gtrule Rule10_Controled_Exit_Preperation_SC() = { precondition pattern lhs(SN,SC,BW,BWR,LK,RS) = { // Controlled Exit of Client from Network SN(SN); SC(SC); LK(LK); RS(RS); find SC_Exit(SC,EX); find RS_rg_SN(RS,SN,RG); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,BWR); find Check_SC_SN_Link(SC,SN,LK); check((value(EX))=="True"); } action { let RG=undef in new (RS.register(RG,RS,SC)); delete(LK); setValue(BW,((toInteger(value(BW)))+5)); setValue(BWR,((toInteger(value(BWR)))+5)); println("SC disconnected from SN due to SC Exit"); } } gtrule Rule10_Controled_Final_Exit_SC() = { precondition pattern lhs(SC,EX) = { SC(SC); find RS_RG_SC(RS,SC,RG); find SC_Exit(SC,EX); neg find SC_Chec_for_Exit(SC); check((value(EX))=="True"); } action { delete(SC); println("SC Departed from Network"); } } gtrule Rule11_UnControled__Exit_SC() = { precondition pattern lhs(SC) = { SC(SC); } action { delete(SC); println("SC Departed from Network due to uncontroled behaviour"); } } pattern Test_SC(SN)= { SN(SN); SC(SC); SN.link(OVI,SN,SC); } pattern OV_Source(OV,SN)= { SN(SN); OV(OV); OV.source(OVR,OV,SN); } pattern OV_Target(OV,SN)= { SN(SN); OV(OV); OV.target(OVT,OV,SN); } pattern Check_OV_Links(SN)= { SN(SN); find OV_Source(OV,SN); find OV_Target(OV,SN); } pattern Check_LK_Links(SN)= { SN(SN); LK(LK); find LK_Check(SN,LK); } pattern LK_Check(SN,LK)= { LK(LK); SN(SN); LK.outTo(LKR,LK,SN); } gtrule Rule12_Controled_Exit_SN_Selected() = { precondition pattern lhs(SN,EX) = { SN(SN); find SN_Exit(SN,EX); check((value(EX))=="True"); } action { setValue(EX,"True"); println("SN selected for controled Exit"); } } gtrule Rule12_Laod_Managed_SN_SNa() = { // This Rule Stablizes the SN by removing the overlay connectiones // the approch is to delete the Link object OV and update the bandwidth precondition pattern lhs(SN,BW,BWR,OV,EX) = { SN(SN); SN(SN1); OV(OV); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SN_Bandwidth(SN1,BWR); find Check_OV(SN,SN1,OV); check((value(EX))=="True"); } action { delete(OV); setValue(BWR,((toInteger(value(BWR)))+5)); setValue(BW,((toInteger(value(BW)))+5)); println("Edge between SN and SN1 removed Due to Controlled Exit of SN "); } } gtrule Rule12_Laod_Managed_SN_Controlled_Exit_Target() = { // This Rule Stablizes the SN by removing the overlay connectiones // the approch is to delete the Link object OV and update the bandwidth precondition pattern lhs(SN,BW,BWR,OV,EX) = { SN(SN); SN(SN1); OV(OV); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SN_Bandwidth(SN1,BWR); find Check_OV(SN1,SN,OV); check((value(EX))=="True"); } action { delete(OV); setValue(BWR,((toInteger(value(BWR)))+5)); setValue(BW,((toInteger(value(BW)))+5)); println("Edge between SN1 and SN removed due to SN controlled Exit"); } } gtrule Rule12_Laod_Managed_SC_SN_c() = { precondition pattern lhs(SN,SC,BW,BWR,LK,RS) = { // Selfish approch // This rule remove the object LK and register back SC with RS SN(SN); SC(SC); LK(LK); RS(RS); find SN_Exit(SN,EX); find RS_rg_SN(RS,SN,RG); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,BWR); find Check_SC_SN_Link(SC,SN,LK); check((value(EX))=="True"); } action { let RG=undef in new (RS.register(RG,RS,SC)); delete(LK); setValue(BW,((toInteger(value(BW)))+5)); setValue(BWR,((toInteger(value(BWR)))+5)); println("SC disconnected from SN due to SN Controlled Exit"); } } gtrule Rule12_departure_of_SN() = { precondition pattern lhs(SN) = { SN(SN); find SN_Exit(SN,EX); neg find Check_OV_Links(SN); neg find Check_LK_Links(SN); check((value(EX))=="True"); } action { delete(SN); println("SN Departed from Network Through Proper exit"); } } gtrule Rule13_departure_of_SN_Uncontrolled() = { precondition pattern lhs(SN) = { SN(SN); } action { delete(SN); println("SN Departed from Network due to Uncontrolled behaviour"); } } pattern OV_Test_Target(OV)= { OV(OV); SN(SN); OV.target(OVR,OV,SN); } gtrule Rule14_Recovery_SN_Source_SN1() = { precondition pattern lhs(BW,SN,OV) = { OV(OV); SN(SN); find SN_Bandwidth(SN,BW); find OV_Source(OV,SN); neg find OV_Test_Target(OV); } action { delete(OV); setValue(BW,((toInteger(value(BW)))+5)); println("Bandwidthe Recovered as Target SN Departed"); } } pattern OV_Test_Source(OV)= { OV(OV); SN(SN); OV.source(OVR,OV,SN); } gtrule Rule14_Recovery_SN_Target_SN1() = { precondition pattern lhs(BW,SN,OV) = { OV(OV); SN(SN); find SN_Bandwidth(SN,BW); find OV_Target(OV,SN); neg find OV_Test_Source(OV); } action { delete(OV); setValue(BW,((toInteger(value(BW)))+5)); println("Bandwidthe Recovered as Target SN Departed"); } } pattern LK_OutTo(LK,SN)= { LK(LK); SN(SN); LK.outTo(LKR,LK,SN); } pattern LK_test_LinkTo(LK)= { LK(LK); find LK_LinkTo(LK,SC); } pattern LK_LinkTo(LK,SC)= { LK(LK); SC(SC); LK.linkto(LKR,LK,SC); } gtrule Rule14_Recovery_SN_OutTO_SC() = { precondition pattern lhs(BW,SN,LK) = { LK(LK); SN(SN); find SN_Bandwidth(SN,BW); find LK_OutTo(LK,SN); neg find LK_test_LinkTo(LK); } action { delete(LK); setValue(BW,((toInteger(value(BW)))+5)); println("Bandwidthe Recovered as Linked SN Departed from Network"); } } pattern SC_Link_with_Two_SN(SC)= { SC(SC); LK(LK); LK(LK1); find Check(SC,LK); find Check(SC,LK1); } pattern Check(SC,LK)= { SC(SC); LK(LK); LK.linkto(LKI,LK,SC); } pattern Test_Connection(LK)= { LK(LK); SC(SC); SN(SN); find Check(SC,LK); find SN_check(SN,LK); } pattern SN_check(SN,LK)= { SN(SN); LK(LK); LK.outTo(LKI,LK,SN); } gtrule Rule15_Recovery_LK_dangling() = { precondition pattern lhs(LK) = { LK(LK); neg find Test_Connection(LK); } action { delete(LK); println("Dangling LK deleted"); } } pattern Test_OV_connection(OV)= { OV(OV); SN(SN); SN(SN1); find Check_Source(SN,OV); find Check_target(SN1,OV); } pattern Check_Source(SN,OV)= { OV(OV); SN(SN); OV.source(OVI,OV,SN); } pattern Check_target(SN,OV)= { OV(OV); SN(SN); OV.target(OVI,OV,SN); } gtrule Rule15_Recovery_OV_dangling() = { precondition pattern lhs(OV) = { OV(OV); neg find Test_OV_connection(OV); } action { delete(OV); println("Dangling OV deleted"); } } gtrule Prob_Rule1() = { precondition pattern lhs(SC) = { SC(SC); find SC_Link_with_Two_SN(SC); } action { println("Found Sc linked With Two Super Nodes"); } } pattern OV_Path_5(SN)= { SN(SN); OV(OV); OV(OV1); OV(OV2); OV(OV3); OV(OV4); find ChecK_OV_Source(SN,OV); find ChecK_OV_Source(SN,OV1); find ChecK_OV_Source(SN,OV2); find ChecK_OV_Source(SN,OV3); find ChecK_OV_Source(SN,OV4); } pattern ChecK_OV_Source(SN,OV)= { SN(SN); OV(OV); OV.source(OVI,OV,SN); } gtrule Prob_Rule2() = { precondition pattern lhs(SN) = { SN(SN); find OV_Path_5(SN); } action { println("Found Supre Node connected with other five Nodes"); } } pattern Check_connection(SN,SN1)= { SN(SN); SN(SN1); OV(OV); OV(OV1); find Test_Edge(SN,SN1,OV); find Test_Edge(SN1,SN,OV1); } pattern Test_Edge(SN,SN1,OV)= { SN(SN); SN(SN1); OV(OV); OV.source(OVT,OV,SN); OV.target(OVI,OV,SN1); } gtrule Prob_Rule3() = { precondition pattern lhs(SN,SN1) = { SN(SN); SN(SN1); neg find Check_connection(SN,SN1); } action { println("Found Supre Node having duplicate edge"); } } pattern Test_LK_Edge(SC)= { SC(SC); LK(LK); LK.linkto(LKI,LK,SC); } pattern Test_RS_For_SC(SC)= { SC(SC); RS(RS); RS.register(RG,RS,SC); } gtrule Prob_Rule4() = { precondition pattern lhs(SC) = { SC(SC); neg find Test_LK_Edge(SC); neg find Test_RS_For_SC(SC); } action { println("Found client Neither registered nor linked "); } } pattern SN_RS_Edge_Check(SN)= { RS(RS); SN(SN); RS.RSoverlay(RSI,RS,SN); } pattern SN_OV_Check(SN)= { SN(SN); OV(OV); OV.source(OVI,OV,SN); } or { SN(SN); OV(OV); OV.target(OVI,OV,SN); } gtrule Prob_Rule5() = { precondition pattern lhs(SN) = { SN(SN); neg find SN_RS_Edge_Check(SN); neg find SN_OV_Check(SN); } action { println("Found Super Node neither overlayed nor registered "); } } pattern SC_Check_SN(SN)= { SN(SN); LK(LK); LK.outTo(LKI,LK,SN); } gtrule Prob_Rule6() = { precondition pattern lhs(SN) = { SN(SN); find SC_Check_SN(SN); neg find SN_RS_Edge_Check(SN); neg find SN_OV_Check(SN); } action { println("Found Super Node neither overlayed nor registered but linked with SC"); } } gtrule nodeCount() = { precondition pattern lhs(X) = { SN(X); } action {println("found node: "+fqn(X));} } rule main() = seq { // Create clients forall with apply Rule1_Create_Client_Firewall_ON()do skip; forall with apply Rule2_Rule1_Create_Client_Firewall_off()do skip; // Select random Super Node for checking latency iterate choose SC, SN with apply Rule3a_Select_Super_Node_to_SN(SC,SN) do skip; // send time stamp Packet (ping) forall with apply Rule3b_Send_Time_Stamp_Packet_to_SN()do skip; // Revers the packet (Ping) forall with apply Rule3c_Revers_Time_Stamp_Packet_to_SN()do skip; // Link client with Super node forall with apply Rule3_Link_SC_to_SN()do skip; // Ruturn DnY packet if Exit Flag is True forall with apply Rule3d_Revers_DnY_Stamp_Packet_to_SN()do skip; // return DnY packet in response to ping if Bandwidth is cratical forall with apply Rule3e_Revers_DnY_Stamp_Packet_to_SN()do skip; // deleted address edge as connection refused try another SN forall with apply Rule3f_delete_ping__andSelect_Another_SN()do skip; // Re-link after loosing connection forall with apply Rule4_Reconfigure_Link_SC_to_link_back_SN() do skip; //Promotion to Super Node forall with apply Rule5_Promote_at_Registration_Super_Node() do skip; forall with apply Rule6_Promote_at_Linked_Super_Node()do skip; //Create Overlay Network Among Super Nodes forall with apply Rule7_connect_SN_SN()do skip; // Laod Managment to Stablize Selfish Approch forall with apply Rule8_Laod_Managed_SN_SNa()do skip; forall with apply Rule8_Laod_Managed_SN_SNb()do skip; forall with apply Rule8_Laod_Managed_SC_SN_c()do skip; // Down Grade to Client based on Bandwidth //forall with apply Rule9_Down_to_SC() do skip; // Controle exit of Client forall with apply Rule10_Controlled_Exit_of_SC()do skip; forall with apply Rule10_Controled_Exit_Preperation_SC()do skip; forall with apply Rule10_Controled_Final_Exit_SC()do skip; //Uncontroled exit of client forall with apply Rule11_UnControled__Exit_SC()do skip; // recovered through Rule4 // Controled exit of Super node forall with apply Rule12_Controled_Exit_SN_Selected() do skip; forall with apply Rule12_Laod_Managed_SN_SNa() do skip; forall with apply Rule12_Laod_Managed_SN_Controlled_Exit_Target() do skip; forall with apply Rule12_Laod_Managed_SC_SN_c()do skip; forall with apply Rule12_departure_of_SN()do skip; //Uncontrolled Exit of Super Node forall with apply Rule13_departure_of_SN_Uncontrolled()do skip; //Recovery Rules after uncontroled Departure of Super Node forall with apply Rule14_Recovery_SN_Source_SN1() do skip; forall with apply Rule14_Recovery_SN_Target_SN1()do skip; forall with apply Rule14_Recovery_SN_OutTO_SC()do skip; // Delete dangling LK nodes forall with apply Rule15_Recovery_LK_dangling()do skip; // Delete dangling OV nodes forall with apply Rule15_Recovery_OV_dangling()do skip; // Probe rules to prevent patterns forall with apply Prob_Rule1()do skip; forall with apply Prob_Rule2()do skip; forall with apply Prob_Rule3()do skip; forall with apply Prob_Rule4()do skip; forall with apply Prob_Rule5()do skip; forall with apply Prob_Rule6()do skip; } }