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); setValue(EX,"False");// set default Exit to false new(SkypeNode.exit(EXR,SC1,EX)); new(Network.nodes(NR,Network,SC1)); 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)); } } } 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, LOC=undef, LR=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(56,2000)); // 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.Location(LOC) in SC1); new(SkypeNode.location(LR,SC1,LOC)); setValue(LOC,skypesim.random(1,24)); 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)); } } } pattern test_links(SC)= { SC(SC); find Link_SN(SC); } pattern Link_SN(SC)= { LK(LK); SC(SC); LK.linkto(CO,LK,SC); } gtrule Rule3_Link_SC_to_SN() = { precondition pattern lhs(RS,SC,SN,CRO,RG,BW,SCBW,Network) = { SN(SN); Network(Network); find RS_RG_SC(RS,SC,RG); find SC_Chronos(SC,CRO); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find SC_Bandwidth(SC,SCBW); neg find Link_SN(SC); check((toInteger(value(BW)))>256); check((value(EX))=="False"); } 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)); println("connected/Linked "); } }} 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(LK,SN,SC,BW) = { LK(LK); SN(SN); SC(SC); find SN_Exit(SN,EX); find SN_Bandwidth(SN,BW); find Link_SC_LK(SC,LK); neg find Link_SN_LK(SN,LK); neg find Test_SN_LK(LK); check((toInteger(value(BW)))>256); check((value(EX))=="False"); } action { let OU=undef in seq{ new(LK.outTo(OU,LK,SN)); setValue(BW,((toInteger(value(BW)))-5)); } println("Re-linked Back to New Super Node"); } } 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)))>= 1500); } 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)))>= 1500); } 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_SN_a() = { // 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 Rule16_Decrement_SN_Bandwidth() = { precondition pattern lhs(SN,BW) = { SN(SN); find SN_Bandwidth(SN,BW); check((toInteger(value(BW)))>256); } action { setValue(BW,((toInteger(value(BW)))-80)); println("Bandwidth reduced due to traffic laod"); } } gtrule Rule16_Increment_SN_Bandwidth() = { precondition pattern lhs(SN,BW) = { SN(SN); find SN_Bandwidth(SN,BW); check((toInteger(value(BW)))>256); } action { setValue(BW,((toInteger(value(BW)))+80)); println("Bandwidth Increased "); } } gtrule Rule17_SC_Happy_with_SN_Bandwidth() = { precondition pattern lhs(SC,LK,SN,BW) = { SN(SN); SC(SC); LK(LK); find LK_LinkTo(LK,SC); find LK_OutTo(LK,SN); find SN_Bandwidth(SN,BW); check((toInteger(value(BW)))>1000); } action { println("SC is happy with existing SN"); } } gtrule Rule18_SC_UN_Happy_with_SN_Bandwidth() = { precondition pattern lhs(SC,LK,SN,BW) = { SN(SN); SC(SC); LK(LK); find LK_LinkTo(LK,SC); find LK_OutTo(LK,SN); find SN_Bandwidth(SN,BW); check((toInteger(value(BW)))<1000); } action { println("SC is Un-happy with existing SN"); } } gtrule Rule19_SC_connected_SN() = { precondition pattern lhs(SC,LK,SN) = { SN(SN); SC(SC); LK(LK); find LK_LinkTo(LK,SC); find LK_OutTo(LK,SN); } action { println("SC onnected with SN"); } } gtrule Rule20_Reconfigure_Link_SC() = { precondition pattern lhs(LK,SC) = { LK(LK); SC(SC); find Link_SC_LK(SC,LK); neg find Test_SN_LK(LK); } action { println("Re-linked Back to New Super Node"); } } 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 scCount() = { precondition pattern lhs(X) = { SC(X); } action {println("found node: "+fqn(X));} } gtrule snCount() = { 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; // Link client with Super node //forall with apply Rule3_Link_SC_to_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_SN_a() 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; // Create Traffic Load forall with apply Rule16_Increment_SN_Bandwidth()do skip; // Reduce Traffic Laod forall with apply Rule16_Decrement_SN_Bandwidth()do skip; // Prob rule to find happy SC forall with apply Rule17_SC_Happy_with_SN_Bandwidth()do skip; // Prob Rule to Find Unhappy Sc forall with apply Rule18_SC_UN_Happy_with_SN_Bandwidth()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; } }