How to use getinstance method in tempest

Best Python code snippet using tempest_python

launcher.py

Source:launcher.py Github

copy

Full Screen

1import logging2import sys3import time4import json5import PostcardGernerator6from PostCardProcessor import *7TIME_WAIT = 18class Sender:9 def __init__(self):10 self.name = "packets"11 def send(self,pkt):12 import socket13 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)14 sock.connect(self.name)15 sock.send(json.dumps(pkt))16 #print sock.recv(1024)17 sock.close()18def launcherA(dag_file):19 #set the log mode20 #logging.basicConfig(level=logging.DEBUG)21 #logging.basicConfig(level=logging.INFO)22 #logging.basicConfig(level=logging.WARNING)23 logging.basicConfig(level=logging.WARNING)24 #logging.basicConfig(level=logging.ERROR)25 #generate rules and install them on switch 126 pcg = PostcardGernerator.PostcardGernerator(dag_file)27 pcg.start()28 #collect postcard29 #post = PostCardProcessor('s1-eth4')30 #post.start()31 PostCardProcessor.Start()32 time.sleep(0.1)33 #logging.info("1# start to collect %.8f" %time.time())34 #start to generate packets35 from timelog import TimeLog36 TimeLog.GetInstance().reset()37 import parser, FaulDete38 types = parser.type_parse("typename.txt")39 rule_list,edge_dict = parser.DAGLoader(dag_file);40 pairs = FaulDete.packetGenerator(edge_dict, rule_list, types)41 #logging.info("2# packets generated %.8f" %time.time())42 if pairs == False:43 flag = False44 return flag, TimeLog.GetInstance().getCost()45 #print pairs46 #send the packets47 #logging.info("3# packets flushed to datapath %.8f" %time.time())48 TimeLog.GetInstance().addCalc()49 sender = Sender()50 pid2rid = {}51 for i,pair in enumerate(pairs):52 rid = pair[0]53 pkt = pair[1]54 pkt['pid'] = i55 pid2rid[i] = rid56 #logging.debug("10# pid to rid: %d - %d." % (i,rid))57 sender.send(pkt)58 TimeLog.GetInstance().addSend()59 TimeLog.GetInstance().addPackets(len(pairs))60 #process with the postcard61 matched = 062 unmatch = 063 flag = True64 while True:65 #print postCardQueue.qsize()66 try:67 TimeLog.GetInstance().addTotal()68 card = postCardQueue.get(True,TIME_WAIT)69 #print card70 except Exception:71 TimeLog.GetInstance().clock()72 #logging.warn("Post Card Queue is empty.")73 if len(pid2rid) > 0:74 #logging.info("55#Failed!")75 print "Failed!",TimeLog.GetInstance().getCost()76 flag = False77 return flag, TimeLog.GetInstance().getCost()78 else:79 #logging.info("56#Success!")80 print "Success!",TimeLog.GetInstance().getCost()81 flag = True82 return flag, TimeLog.GetInstance().getCost()83 break84 pid = card[0]85 rid = card[1]86 if pid in pid2rid:87 rrid = pid2rid[pid]88 if rid == pid2rid[pid]:89 matched += 190 pid2rid.pop(pid)91 #logging.debug("11# actually, Y pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))92 else:93 unmatch += 194 #logging.info("55#Unfinished!")95 #logging.warn("11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))96 #print "11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid)97 pkt = pairs[pid][1]98 warn = ""99 for typ in ['src-ip','dst-ip','src-port','dst-port']:100 warn += typ+":"+str(pkt[typ])+";"101 #logging.warn("12#"+warn)102 #break103 #print "Failed!",TimeLog.GetInstance().getCost()104 TimeLog.GetInstance().addFirst()105 #return flag, TimeLog.GetInstance().getCost()106 #return flag,time.time()-delta-TIME_WAIT107 #logging.info("56# Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch) )108 #logging.info("57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT))109 print "Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch)110 print "57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT)111 Flag = False112 return flag,time.time()-delta-TIME_WAIT113def launcherAWithWrongTable(dag_file, wrong_dag):114 #set the log mode115 #logging.basicConfig(level=logging.DEBUG)116 #logging.basicConfig(level=logging.INFO)117 logging.basicConfig(level=logging.WARNING)118 #logging.basicConfig(level=logging.WARNING)119 #generate rules and install them on switch 1120 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)121 pcg.start()122 #collect postcard123 #post = PostCardProcessor('s1-eth4')124 #post.start()125 PostCardProcessor.Start()126 time.sleep(0.1)127 #logging.info("1# start to collect %.8f" %time.time())128 #start to generate packets129 from timelog import TimeLog130 TimeLog.GetInstance().reset()131 import parser, FaulDete132 types = parser.type_parse("typename.txt")133 rule_list,edge_dict = parser.DAGLoader(dag_file);134 pairs = FaulDete.packetGenerator(edge_dict, rule_list, types)135 TimeLog.GetInstance().addCalc()136 #logging.info("2# packets generated %.8f" %time.time())137 #send the packets138 #logging.info("3# packets flushed to datapath %.8f" %time.time())139 sender = Sender()140 pid2rid = {}141 for i,pair in enumerate(pairs):142 rid = pair[0]143 pkt = pair[1]144 pkt['pid'] = i145 pid2rid[i] = rid146 #logging.debug("10# pid to rid: %d - %d." % (i,rid))147 sender.send(pkt)148 TimeLog.GetInstance().addSend()149 TimeLog.GetInstance().addPackets(len(pairs))150 #process with the postcard151 matched = 0152 unmatch = 0153 flag = True154 while True:155 #print postCardQueue.qsize()156 try:157 TimeLog.GetInstance().addTotal()158 card = postCardQueue.get(True,TIME_WAIT)159 #print card160 except Exception:161 TimeLog.GetInstance().clock()162 #logging.warn("Post Card Queue is empty.")163 if len(pid2rid) > 0:164 print "Failed!",TimeLog.GetInstance().getCost()165 flag = False166 return flag,TimeLog.GetInstance().getCost()167 else:168 print "Success!",TimeLog.GetInstance().getCost()169 flag = True170 return flag,TimeLog.GetInstance().getCost()171 break172 pid = card[0]173 rid = card[1]174 if pid in pid2rid:175 rrid = pid2rid[pid]176 if rid == pid2rid[pid]:177 matched += 1178 pid2rid.pop(pid)179 #logging.debug("11# actually, Y pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))180 else:181 unmatch += 1182 #logging.info("55#Unfinished!")183 #logging.warn("11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))184 #print "11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid)185 pkt = pairs[pid][1]186 warn = ""187 for typ in ['src-ip','dst-ip','src-port','dst-port']:188 warn += typ+":"+str(pkt[typ])+";"189 #logging.warn("12#"+warn)190 #break191 #print "Failed!",TimeLog.GetInstance().getCost()192 TimeLog.GetInstance().addFirst()193 #return flag,TimeLog.GetInstance().getCost()194 #logging.info("56# Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch) )195 #logging.info("57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT))196 Flag = False197 return flag,time.time()-delta-TIME_WAIT198def launcherB(dag_file):199 #set the log mode200 #logging.basicConfig(level=logging.DEBUG)201 #logging.basicConfig(level=logging.INFO)202 #logging.basicConfig(level=logging.WARNING)203 logging.basicConfig(level=logging.WARNING)204 #logging.basicConfig(level=logging.ERROR)205 #generate rules and install them on switch 1206 pcg = PostcardGernerator.PostcardGernerator(dag_file)207 pcg.start()208 #collect postcard209 #post = PostCardProcessor('s1-eth4')210 #post.start()211 PostCardProcessor.Start()212 time.sleep(0.1)213 #logging.info("1# start to collect %.8f" %time.time())214 #start to generate packets215 from timelog import TimeLog216 TimeLog.GetInstance().reset()217 import parser, NonaTrou218 types = parser.type_parse("typename.txt")219 rule_list,edge_dict = parser.DAGLoader(dag_file);220 pairs = NonaTrou.packetGenerator(edge_dict, rule_list, types)221 #logging.info("2# packets generated %.8f" %time.time())222 #send the packets223 #logging.info("3# packets flushed to datapath %.8f" %time.time())224 TimeLog.GetInstance().addTotal()225 sender = Sender()226 pid2rid = {}227 for i,pair in enumerate(pairs):228 rid = pair[0]229 pkt = pair[1]230 pkt['pid'] = i231 pid2rid[i] = rid232 #logging.debug("10# pid to rid: %d - %d." % (i,rid))233 sender.send(pkt)234 TimeLog.GetInstance().addSend()235 #process with the postcard236 matched = 0237 unmatch = 0238 flag = True239 VV = []240 EE = []241 while True:242 #print postCardQueue.qsize()243 try:244 TimeLog.GetInstance().addTotal()245 card = postCardQueue.get(True,TIME_WAIT)246 #print card247 except Exception:248 TimeLog.GetInstance().clock()249 #logging.warn("Post Card Queue is empty.")250 flag = NonaTrou.dagCompare(edge_dict, rule_list, VV, EE)251 if flag == False:252 #logging.info("55#Failed!")253 print "Failed!",TimeLog.GetInstance().getCost()254 flag = False255 return flag, TimeLog.GetInstance().getCost()256 else:257 #logging.info("56#Success!")258 print "Success!",TimeLog.GetInstance().getCost()259 flag = True260 return flag, TimeLog.GetInstance().getCost()261 break262 pid = card[0]263 rid = card[1]264 if pid in pid2rid:265 if not rid in VV:266 VV.append(rid)267 rrid = pid2rid[pid]268 for r in rrid:269 if r != rid:270 EE.append([r,rid])271def launcherBWithWrongTable(dag_file, wrong_dag):272 #set the log mode273 #logging.basicConfig(level=logging.DEBUG)274 #logging.basicConfig(level=logging.INFO)275 #logging.basicConfig(level=logging.WARNING)276 logging.basicConfig(level=logging.WARNING)277 #logging.basicConfig(level=logging.ERROR)278 #generate rules and install them on switch 1279 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)280 pcg.start()281 #collect postcard282 #post = PostCardProcessor('s1-eth4')283 #post.start()284 PostCardProcessor.Start()285 time.sleep(0.1)286 #logging.info("1# start to collect %.8f" %time.time())287 #start to generate packets288 from timelog import TimeLog289 TimeLog.GetInstance().reset()290 import parser, NonaTrou291 types = parser.type_parse("typename.txt")292 rule_list,edge_dict = parser.DAGLoader(dag_file);293 pairs = NonaTrou.packetGenerator(edge_dict, rule_list, types)294 #logging.info("2# packets generated %.8f" %time.time())295 #send the packets296 #logging.info("3# packets flushed to datapath %.8f" %time.time())297 TimeLog.GetInstance().addCalc()298 sender = Sender()299 pid2rid = {}300 for i,pair in enumerate(pairs):301 rid = pair[0]302 pkt = pair[1]303 pkt['pid'] = i304 pid2rid[i] = rid305 #logging.debug("10# pid to rid: %d - %d." % (i,rid))306 sender.send(pkt)307 TimeLog.GetInstance().addSend()308 #process with the postcard309 matched = 0310 unmatch = 0311 flag = True312 VV = []313 EE = []314 while True:315 #print postCardQueue.qsize()316 try:317 TimeLog.GetInstance().addTotal()318 card = postCardQueue.get(True,TIME_WAIT)319 #print card320 except Exception:321 TimeLog.GetInstance().clock()322 #logging.warn("Post Card Queue is empty.")323 flag = NonaTrou.dagCompare(edge_dict, rule_list, VV, EE)324 if flag == False:325 #logging.info("55#Failed!")326 print "Failed!",TimeLog.GetInstance().getCost()327 flag = False328 return flag, TimeLog.GetInstance().getCost()329 else:330 #logging.info("56#Success!")331 print "Success!",TimeLog.GetInstance().getCost()332 flag = True333 return flag, TimeLog.GetInstance().getCost()334 break335 pid = card[0]336 rid = card[1]337 if pid in pid2rid:338 if not rid in VV:339 VV.append(rid)340 rrid = pid2rid[pid]341 for r in rrid:342 if r != rid:343 EE.append([r,rid])344def launcherC(dag_file):345 #set the log mode346 #logging.basicConfig(level=logging.DEBUG)347 #logging.basicConfig(level=logging.INFO)348 #logging.basicConfig(level=logging.WARNING)349 logging.basicConfig(level=logging.WARNING)350 #logging.basicConfig(level=logging.ERROR)351 #generate rules and install them on switch 1352 pcg = PostcardGernerator.PostcardGernerator(dag_file)353 pcg.start()354 #collect postcard355 #post = PostCardProcessor('s1-eth4')356 #post.start()357 PostCardProcessor.Start()358 time.sleep(1)359 #logging.info("1# start to collect %.8f" %time.time())360 #start to generate packets361 from timelog import TimeLog362 TimeLog.GetInstance().reset()363 TimeLog.GetInstance().clock()364 import parser, FullAdap365 types = parser.type_parse("typename.txt")366 rule_list,edge_dict = parser.DAGLoader(dag_file);367 flag = FullAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)368 TimeLog.GetInstance().addTotal()369 if flag == False:370 print "Failed!",TimeLog.GetInstance().getCost()371 elif flag == True:372 print "Success!",TimeLog.GetInstance().getCost()373 else:374 print "Unexpected!",TimeLog.GetInstance().getCost()375 Flag = False376 time.sleep(0.1)377 return flag,TimeLog.GetInstance().getCost()378 #return flag,time.time()-delta-TIME_WAIT379def launcherCWithWrongTable(dag_file, wrong_dag):380 #set the log mode381 #logging.basicConfig(level=logging.DEBUG)382 #logging.basicConfig(level=logging.INFO)383 #logging.basicConfig(level=logging.WARNING)384 logging.basicConfig(level=logging.WARNING)385 #logging.basicConfig(level=logging.ERROR)386 from timelog import TimeLog387 TimeLog.GetInstance().reset()388 #generate rules and install them on switch 1389 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)390 pcg.start()391 #collect postcard392 #post = PostCardProcessor('s1-eth4')393 PostCardProcessor.Start()394 #post.start()395 time.sleep(1)396 #logging.info("1# start to collect %.8f" %time.time())397 #start to generate packets398 TimeLog.GetInstance().clock()399 import parser, FullAdap400 types = parser.type_parse("typename.txt")401 rule_list,edge_dict = parser.DAGLoader(dag_file);402 flag = FullAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)403 if flag == False:404 print "Failed!",TimeLog.GetInstance().getCost()405 elif flag == True:406 print "Success!",TimeLog.GetInstance().getCost()407 else:408 print "Unexpected!",TimeLog.GetInstance().getCost()409 Flag = False410 time.sleep(0.1)411 return flag,TimeLog.GetInstance().getCost()412 #return flag,time.time()-delta-TIME_WAIT413def launcherD(dag_file):414 #set the log mode415 #logging.basicConfig(level=logging.DEBUG)416 #logging.basicConfig(level=logging.INFO)417 #logging.basicConfig(level=logging.WARNING)418 logging.basicConfig(level=logging.WARNING)419 #logging.basicConfig(level=logging.ERROR)420 from timelog import TimeLog421 TimeLog.GetInstance().reset()422 #generate rules and install them on switch 1423 pcg = PostcardGernerator.PostcardGernerator(dag_file)424 pcg.start()425 #collect postcard426 #post = PostCardProcessor('s1-eth4')427 #post.start()428 PostCardProcessor.Start()429 time.sleep(1)430 #logging.info("1# start to collect %.8f" %time.time())431 #start to generate packets432 TimeLog.GetInstance().clock()433 import parser, SemiAdap434 types = parser.type_parse("typename.txt")435 rule_list,edge_dict = parser.DAGLoader(dag_file);436 flag = SemiAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)437 if flag == False:438 print "Failed!",TimeLog.GetInstance().getCost()439 elif flag == True:440 print "Success!",TimeLog.GetInstance().getCost()441 else:442 print "Unexpected!",TimeLog.GetInstance().getCost()443 Flag = False444 time.sleep(0.1)445 return flag,TimeLog.GetInstance().getCost()446 #return flag,time.time()-delta-TIME_WAIT447def launcherDWithWrongTable(dag_file, wrong_dag):448 #set the log mode449 #logging.basicConfig(level=logging.DEBUG)450 #logging.basicConfig(level=logging.INFO)451 #logging.basicConfig(level=logging.WARNING)452 logging.basicConfig(level=logging.WARNING)453 #logging.basicConfig(level=logging.ERROR)454 from timelog import TimeLog455 TimeLog.GetInstance().reset()456 #generate rules and install them on switch 1457 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)458 pcg.start()459 #collect postcard460 #post = PostCardProcessor('s1-eth4')461 PostCardProcessor.Start()462 #post.start()463 time.sleep(1)464 #logging.info("1# start to collect %.8f" %time.time())465 #start to generate packets466 TimeLog.GetInstance().clock()467 import parser, SemiAdap468 types = parser.type_parse("typename.txt")469 rule_list,edge_dict = parser.DAGLoader(dag_file);470 flag = SemiAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)471 if flag == False:472 print "Failed!",TimeLog.GetInstance().getCost()473 elif flag == True:474 print "Success!",TimeLog.GetInstance().getCost()475 else:476 print "Unexpected!",TimeLog.GetInstance().getCost()477 Flag = False478 time.sleep(0.1)479 return flag,TimeLog.GetInstance().getCost()480 #return flag,time.time()-delta-TIME_WAIT481def preTest(dag_file):482 import parser, PreTest483 types = parser.type_parse("typename.txt")484 rule_list,edge_dict = parser.DAGLoader(dag_file);485 pairs = PreTest.packetGenerator(edge_dict, rule_list, types)486 #logging.info("2# packets generated %.8f" %time.time())487 if pairs[0] == False:488 flag = False489 return pairs490 return True,0491def launcherE(dag_file, pre_file):492 #set the log mode493 logging.basicConfig(level=logging.WARNING)494 #generate rules and install them on switch 1495 pcg = PostcardGernerator.PostcardGernerator(dag_file)496 pcg.start()497 PostCardProcessor.Start()498 time.sleep(0.1)499 from timelog import TimeLog500 import parser, IncrFaulDete501 types = parser.type_parse("typename.txt")502 rule_list,edge_dict = parser.DAGLoader(dag_file)503 rule_lists,edge_dicts = parser.DAGLoader(pre_file)504 table = []505 for i in rule_list.keys():506 for j in rule_lists.keys():507 ret = cmp(rule_list[i], rule_lists[j])508 if ret == 0:509 #print rule_list[i]510 #print rule_lists[j]511 table.append(i)512 #print table513 TimeLog.GetInstance().reset()514 pairs = IncrFaulDete.packetGenerator(edge_dict, rule_list, types, table)515 if pairs == False:516 flag = False517 return flag, TimeLog.GetInstance().getCost()518 TimeLog.GetInstance().addCalc()519 sender = Sender()520 pid2rid = {}521 for i,pair in enumerate(pairs):522 rid = pair[0]523 pkt = pair[1]524 pkt['pid'] = i525 pid2rid[i] = rid526 sender.send(pkt)527 TimeLog.GetInstance().addSend()528 TimeLog.GetInstance().addPackets(len(pairs))529 matched = 0530 unmatch = 0531 flag = True532 while True:533 try:534 TimeLog.GetInstance().addTotal()535 card = postCardQueue.get(True,TIME_WAIT)536 except Exception:537 TimeLog.GetInstance().clock()538 if len(pid2rid) > 0:539 print "Failed!",TimeLog.GetInstance().getCost()540 flag = False541 return flag, TimeLog.GetInstance().getCost()542 else:543 print "Success!",TimeLog.GetInstance().getCost()544 flag = True545 return flag, TimeLog.GetInstance().getCost()546 break547 pid = card[0]548 rid = card[1]549 if pid in pid2rid:550 rrid = pid2rid[pid]551 if rid == pid2rid[pid]:552 matched += 1553 pid2rid.pop(pid)554 else:555 unmatch += 1556 pkt = pairs[pid][1]557 warn = ""558 for typ in ['src-ip','dst-ip','src-port','dst-port']:559 warn += typ+":"+str(pkt[typ])+";"560 TimeLog.GetInstance().addFirst()561 print "Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch)562 print "57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT)563 Flag = False564 return flag,time.time()-delta-TIME_WAIT565def launcherF(dag_file, pre_file):566 #set the log mode567 #logging.basicConfig(level=logging.DEBUG)568 #logging.basicConfig(level=logging.INFO)569 #logging.basicConfig(level=logging.WARNING)570 logging.basicConfig(level=logging.WARNING)571 #logging.basicConfig(level=logging.ERROR)572 #generate rules and install them on switch 1573 pcg = PostcardGernerator.PostcardGernerator(dag_file)574 pcg.start()575 #collect postcard576 #post = PostCardProcessor('s1-eth4')577 #post.start()578 PostCardProcessor.Start()579 time.sleep(1)580 #logging.info("1# start to collect %.8f" %time.time())581 #start to generate packets582 from timelog import TimeLog583 TimeLog.GetInstance().reset()584 import parser, IncrFullAdap585 types = parser.type_parse("typename.txt")586 rule_list,edge_dict = parser.DAGLoader(dag_file);587 rule_lists,edge_dicts = parser.DAGLoader(pre_file)588 table = []589 for i in rule_list.keys():590 for j in rule_lists.keys():591 ret = cmp(rule_list[i], rule_lists[j])592 if ret == 0:593 #print rule_list[i]594 #print rule_lists[j]595 table.append(i)596 #print len(table),table597 TimeLog.GetInstance().clock()598 flag = IncrFullAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue, table)599 TimeLog.GetInstance().addTotal()600 if flag == False:601 print "Failed!",TimeLog.GetInstance().getCost()602 elif flag == True:603 print "Success!",TimeLog.GetInstance().getCost()604 else:605 print "Unexpected!",TimeLog.GetInstance().getCost()606 Flag = False607 time.sleep(0.1)608 return flag,TimeLog.GetInstance().getCost()609def launcherG(dag_file, pre_file):610 logging.basicConfig(level=logging.WARNING)611 from timelog import TimeLog612 TimeLog.GetInstance().reset()613 #generate rules and install them on switch 1614 pcg = PostcardGernerator.PostcardGernerator(dag_file)615 pcg.start()616 PostCardProcessor.Start()617 time.sleep(1)618 #start to generate packets619 import parser, IncrSemiAdap620 types = parser.type_parse("typename.txt")621 rule_list,edge_dict = parser.DAGLoader(dag_file);622 rule_lists,edge_dicts = parser.DAGLoader(pre_file)623 table = []624 tbN = []625 hs = {}626 for i in rule_list.keys():627 for j in rule_lists.keys():628 ret = cmp(rule_list[i], rule_lists[j])629 if ret == 0:630 #print rule_list[i]631 #print rule_lists[j]632 table.append(i)633 if not j in tbN:634 tbN.append(j)635 hs[j] = i636 #print table637 edges_pre = []638 for i in edge_dicts.keys():639 if not i in tbN:640 continue641 for j in edge_dicts[i]:642 if not j in tbN:643 continue644 edges_pre.append([hs[i], hs[j]])645 TimeLog.GetInstance().clock()646 flag = IncrSemiAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue, table, edges_pre)647 if flag == False:648 print "Failed!",TimeLog.GetInstance().getCost()649 elif flag == True:650 print "Success!",TimeLog.GetInstance().getCost()651 else:652 print "Unexpected!",TimeLog.GetInstance().getCost()653 Flag = False654 time.sleep(0.1)655 return flag,TimeLog.GetInstance().getCost()656if __name__ == "__main__":657 #parse the input arguments658 if len(sys.argv) != 2 and len(sys.argv) != 3:659 print "Or Usage: python launcher.py dag_file"660 print "Or Usage: python launcher.py dag_file pre_file"661 exit(0)662 dag_file = sys.argv[1]663 pre_file = ""664 if len(sys.argv) == 3:665 pre_file = sys.argv[2]666 #launcherA(dag_file)667 #launcherAWithWrongTable(dag_file,dag_file+".miss")668 #launcherAWithWrongTable(dag_file,dag_file+".order")669 #launcherB(dag_file)670 #launcherBWithWrongTable(dag_file,dag_file+".miss")671 #launcherBWithWrongTable(dag_file,dag_file+".order")672 #launcherC(dag_file)673 #launcherCWithWrongTable(dag_file,dag_file+".miss")674 #launcherCWithWrongTable(dag_file,dag_file+".order")675 #launcherD(dag_file)676 #launcherDWithWrongTable(dag_file,dag_file+".miss")677 #launcherDWithWrongTable(dag_file,dag_file+".order")678 #launcherDWithWrongTable(dag_file,dag_file+"_8.mix")679 launcherE(dag_file, pre_file)680 #launcherF(dag_file, pre_file)...

Full Screen

Full Screen

ltest.py

Source:ltest.py Github

copy

Full Screen

1import logging2import sys3import time4import json5import PostcardGernerator6from PostCardProcessor import *7TIME_WAIT = 18class Sender:9 def __init__(self):10 self.name = "packets"11 def send(self,pkt):12 import socket13 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)14 sock.connect(self.name)15 sock.send(json.dumps(pkt))16 #print sock.recv(1024)17 sock.close()18def launcherA(dag_file):19 #set the log mode20 #logging.basicConfig(level=logging.DEBUG)21 #logging.basicConfig(level=logging.INFO)22 #logging.basicConfig(level=logging.WARNING)23 logging.basicConfig(level=logging.WARNING)24 #logging.basicConfig(level=logging.ERROR)25 #generate rules and install them on switch 126 pcg = PostcardGernerator.PostcardGernerator(dag_file)27 pcg.start()28 #collect postcard29 #post = PostCardProcessor('s1-eth4')30 #post.start()31 PostCardProcessor.Start()32 time.sleep(0.1)33 #logging.info("1# start to collect %.8f" %time.time())34 #start to generate packets35 from timelog import TimeLog36 TimeLog.GetInstance().reset()37 import parser, FaulDete38 types = parser.type_parse("typename.txt")39 rule_list,edge_dict = parser.DAGLoader(dag_file);40 pairs = FaulDete.packetGenerator(edge_dict, rule_list, types)41 #logging.info("2# packets generated %.8f" %time.time())42 if pairs == False:43 flag = False44 return flag, TimeLog.GetInstance().getCost()45 #print pairs46 #send the packets47 #logging.info("3# packets flushed to datapath %.8f" %time.time())48 TimeLog.GetInstance().addCalc()49 sender = Sender()50 pid2rid = {}51 for i,pair in enumerate(pairs):52 rid = pair[0]53 pkt = pair[1]54 pkt['pid'] = i55 pid2rid[i] = rid56 #logging.debug("10# pid to rid: %d - %d." % (i,rid))57 sender.send(pkt)58 TimeLog.GetInstance().addSend()59 TimeLog.GetInstance().addPackets(len(pairs))60 #process with the postcard61 matched = 062 unmatch = 063 flag = True64 while True:65 #print postCardQueue.qsize()66 try:67 TimeLog.GetInstance().addTotal()68 card = postCardQueue.get(True,TIME_WAIT)69 #print card70 except Exception:71 TimeLog.GetInstance().clock()72 #logging.warn("Post Card Queue is empty.")73 if len(pid2rid) > 0:74 #logging.info("55#Failed!")75 print "Failed!",TimeLog.GetInstance().getCost()76 flag = False77 return flag, TimeLog.GetInstance().getCost()78 else:79 #logging.info("56#Success!")80 print "Success!",TimeLog.GetInstance().getCost()81 flag = True82 return flag, TimeLog.GetInstance().getCost()83 break84 pid = card[0]85 rid = card[1]86 if pid in pid2rid:87 rrid = pid2rid[pid]88 if rid == pid2rid[pid]:89 matched += 190 pid2rid.pop(pid)91 #logging.debug("11# actually, Y pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))92 else:93 unmatch += 194 #logging.info("55#Unfinished!")95 #logging.warn("11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))96 #print "11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid)97 pkt = pairs[pid][1]98 warn = ""99 for typ in ['src-ip','dst-ip','src-port','dst-port']:100 warn += typ+":"+str(pkt[typ])+";"101 #logging.warn("12#"+warn)102 #break103 #print "Failed!",TimeLog.GetInstance().getCost()104 TimeLog.GetInstance().addFirst()105 #return flag, TimeLog.GetInstance().getCost()106 #return flag,time.time()-delta-TIME_WAIT107 #logging.info("56# Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch) )108 #logging.info("57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT))109 print "Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch) 110 print "57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT)111 Flag = False112 return flag,time.time()-delta-TIME_WAIT113def launcherAWithWrongTable(dag_file, wrong_dag):114 #set the log mode115 #logging.basicConfig(level=logging.DEBUG)116 #logging.basicConfig(level=logging.INFO)117 logging.basicConfig(level=logging.WARNING)118 #logging.basicConfig(level=logging.WARNING)119 #generate rules and install them on switch 1120 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)121 pcg.start()122 #collect postcard123 #post = PostCardProcessor('s1-eth4')124 #post.start()125 PostCardProcessor.Start()126 time.sleep(0.1)127 #logging.info("1# start to collect %.8f" %time.time())128 #start to generate packets129 from timelog import TimeLog130 TimeLog.GetInstance().reset()131 import parser, FaulDete132 types = parser.type_parse("typename.txt")133 rule_list,edge_dict = parser.DAGLoader(dag_file);134 pairs = FaulDete.packetGenerator(edge_dict, rule_list, types)135 TimeLog.GetInstance().addCalc()136 #logging.info("2# packets generated %.8f" %time.time())137 #send the packets138 #logging.info("3# packets flushed to datapath %.8f" %time.time())139 sender = Sender()140 pid2rid = {}141 for i,pair in enumerate(pairs):142 rid = pair[0]143 pkt = pair[1]144 pkt['pid'] = i145 pid2rid[i] = rid146 #logging.debug("10# pid to rid: %d - %d." % (i,rid))147 sender.send(pkt)148 TimeLog.GetInstance().addSend()149 TimeLog.GetInstance().addPackets(len(pairs))150 #process with the postcard151 matched = 0152 unmatch = 0153 flag = True154 while True:155 #print postCardQueue.qsize()156 try:157 TimeLog.GetInstance().addTotal()158 card = postCardQueue.get(True,TIME_WAIT)159 #print card160 except Exception:161 TimeLog.GetInstance().clock()162 #logging.warn("Post Card Queue is empty.")163 if len(pid2rid) > 0:164 print "Failed!",TimeLog.GetInstance().getCost()165 flag = False166 return flag,TimeLog.GetInstance().getCost()167 else:168 print "Success!",TimeLog.GetInstance().getCost()169 flag = True170 return flag,TimeLog.GetInstance().getCost()171 break172 pid = card[0]173 rid = card[1]174 if pid in pid2rid:175 rrid = pid2rid[pid]176 if rid == pid2rid[pid]:177 matched += 1178 pid2rid.pop(pid)179 #logging.debug("11# actually, Y pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))180 else:181 unmatch += 1182 #logging.info("55#Unfinished!")183 #logging.warn("11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid))184 #print "11# actually, N pid to rid, should match: %d - %d - %d." %(pid,rid,rrid)185 pkt = pairs[pid][1]186 warn = ""187 for typ in ['src-ip','dst-ip','src-port','dst-port']:188 warn += typ+":"+str(pkt[typ])+";"189 #logging.warn("12#"+warn)190 #break191 #print "Failed!",TimeLog.GetInstance().getCost()192 TimeLog.GetInstance().addFirst()193 #return flag,TimeLog.GetInstance().getCost()194 #logging.info("56# Finally, %d packets matched right, %d packets mismatched." %(matched,unmatch) )195 #logging.info("57#time count: %.6f seconds" % (time.time() - delta - TIME_WAIT))196 Flag = False197 return flag,time.time()-delta-TIME_WAIT198def launcherB(dag_file):199 #set the log mode200 #logging.basicConfig(level=logging.DEBUG)201 #logging.basicConfig(level=logging.INFO)202 #logging.basicConfig(level=logging.WARNING)203 logging.basicConfig(level=logging.WARNING)204 #logging.basicConfig(level=logging.ERROR)205 #generate rules and install them on switch 1206 pcg = PostcardGernerator.PostcardGernerator(dag_file)207 pcg.start()208 #collect postcard209 #post = PostCardProcessor('s1-eth4')210 #post.start()211 PostCardProcessor.Start()212 time.sleep(0.1)213 #logging.info("1# start to collect %.8f" %time.time())214 #start to generate packets215 from timelog import TimeLog216 TimeLog.GetInstance().reset()217 import parser, NonaTrou218 types = parser.type_parse("typename.txt")219 rule_list,edge_dict = parser.DAGLoader(dag_file);220 pairs = NonaTrou.packetGenerator(edge_dict, rule_list, types)221 #logging.info("2# packets generated %.8f" %time.time())222 #send the packets223 #logging.info("3# packets flushed to datapath %.8f" %time.time())224 TimeLog.GetInstance().addTotal()225 sender = Sender()226 pid2rid = {}227 for i,pair in enumerate(pairs):228 rid = pair[0]229 pkt = pair[1]230 pkt['pid'] = i231 pid2rid[i] = rid232 #logging.debug("10# pid to rid: %d - %d." % (i,rid))233 sender.send(pkt)234 TimeLog.GetInstance().addSend()235 #process with the postcard236 matched = 0237 unmatch = 0238 flag = True239 VV = []240 EE = []241 while True:242 #print postCardQueue.qsize()243 try:244 TimeLog.GetInstance().addTotal()245 card = postCardQueue.get(True,TIME_WAIT)246 #print card247 except Exception:248 TimeLog.GetInstance().clock()249 #logging.warn("Post Card Queue is empty.")250 flag = NonaTrou.dagCompare(edge_dict, rule_list, VV, EE)251 if flag == False:252 #logging.info("55#Failed!")253 print "Failed!",TimeLog.GetInstance().getCost()254 flag = False255 return flag, TimeLog.GetInstance().getCost()256 else:257 #logging.info("56#Success!")258 print "Success!",TimeLog.GetInstance().getCost()259 flag = True260 return flag, TimeLog.GetInstance().getCost()261 break262 pid = card[0]263 rid = card[1]264 if pid in pid2rid:265 if not rid in VV:266 VV.append(rid)267 rrid = pid2rid[pid]268 for r in rrid:269 if r != rid:270 EE.append([r,rid])271def launcherBWithWrongTable(dag_file, wrong_dag):272 #set the log mode273 #logging.basicConfig(level=logging.DEBUG)274 #logging.basicConfig(level=logging.INFO)275 #logging.basicConfig(level=logging.WARNING)276 logging.basicConfig(level=logging.WARNING)277 #logging.basicConfig(level=logging.ERROR)278 #generate rules and install them on switch 1279 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)280 pcg.start()281 #collect postcard282 #post = PostCardProcessor('s1-eth4')283 #post.start()284 PostCardProcessor.Start()285 time.sleep(0.1)286 #logging.info("1# start to collect %.8f" %time.time())287 #start to generate packets288 from timelog import TimeLog289 TimeLog.GetInstance().reset()290 import parser, NonaTrou291 types = parser.type_parse("typename.txt")292 rule_list,edge_dict = parser.DAGLoader(dag_file);293 pairs = NonaTrou.packetGenerator(edge_dict, rule_list, types)294 #logging.info("2# packets generated %.8f" %time.time())295 #send the packets296 #logging.info("3# packets flushed to datapath %.8f" %time.time())297 TimeLog.GetInstance().addCalc()298 sender = Sender()299 pid2rid = {}300 for i,pair in enumerate(pairs):301 rid = pair[0]302 pkt = pair[1]303 pkt['pid'] = i304 pid2rid[i] = rid305 #logging.debug("10# pid to rid: %d - %d." % (i,rid))306 sender.send(pkt)307 TimeLog.GetInstance().addSend()308 #process with the postcard309 matched = 0310 unmatch = 0311 flag = True312 VV = []313 EE = []314 while True:315 #print postCardQueue.qsize()316 try:317 TimeLog.GetInstance().addTotal()318 card = postCardQueue.get(True,TIME_WAIT)319 #print card320 except Exception:321 TimeLog.GetInstance().clock()322 #logging.warn("Post Card Queue is empty.")323 flag = NonaTrou.dagCompare(edge_dict, rule_list, VV, EE)324 if flag == False:325 #logging.info("55#Failed!")326 print "Failed!",TimeLog.GetInstance().getCost()327 flag = False328 return flag, TimeLog.GetInstance().getCost()329 else:330 #logging.info("56#Success!")331 print "Success!",TimeLog.GetInstance().getCost()332 flag = True333 return flag, TimeLog.GetInstance().getCost()334 break335 pid = card[0]336 rid = card[1]337 if pid in pid2rid:338 if not rid in VV:339 VV.append(rid)340 rrid = pid2rid[pid]341 for r in rrid:342 if r != rid:343 EE.append([r,rid])344def launcherC(dag_file):345 #set the log mode346 #logging.basicConfig(level=logging.DEBUG)347 #logging.basicConfig(level=logging.INFO)348 #logging.basicConfig(level=logging.WARNING)349 logging.basicConfig(level=logging.WARNING)350 #logging.basicConfig(level=logging.ERROR)351 #generate rules and install them on switch 1352 pcg = PostcardGernerator.PostcardGernerator(dag_file)353 pcg.start()354 #collect postcard355 #post = PostCardProcessor('s1-eth4')356 #post.start()357 PostCardProcessor.Start()358 time.sleep(1)359 #logging.info("1# start to collect %.8f" %time.time())360 #start to generate packets361 from timelog import TimeLog362 TimeLog.GetInstance().reset()363 TimeLog.GetInstance().clock()364 import parser, FullAdap365 types = parser.type_parse("typename.txt")366 rule_list,edge_dict = parser.DAGLoader(dag_file);367 flag = FullAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)368 TimeLog.GetInstance().addTotal()369 if flag == False:370 print "Failed!",TimeLog.GetInstance().getCost()371 elif flag == True:372 print "Success!",TimeLog.GetInstance().getCost()373 else:374 print "Unexpected!",TimeLog.GetInstance().getCost()375 Flag = False376 time.sleep(0.1)377 return flag,TimeLog.GetInstance().getCost()378 #return flag,time.time()-delta-TIME_WAIT379def launcherCWithWrongTable(dag_file, wrong_dag):380 #set the log mode381 #logging.basicConfig(level=logging.DEBUG)382 #logging.basicConfig(level=logging.INFO)383 #logging.basicConfig(level=logging.WARNING)384 logging.basicConfig(level=logging.WARNING)385 #logging.basicConfig(level=logging.ERROR)386 from timelog import TimeLog387 TimeLog.GetInstance().reset()388 #generate rules and install them on switch 1389 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)390 pcg.start()391 #collect postcard392 #post = PostCardProcessor('s1-eth4')393 PostCardProcessor.Start()394 #post.start()395 time.sleep(1)396 #logging.info("1# start to collect %.8f" %time.time())397 #start to generate packets398 TimeLog.GetInstance().clock()399 import parser, FullAdap400 types = parser.type_parse("typename.txt")401 rule_list,edge_dict = parser.DAGLoader(dag_file);402 flag = FullAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)403 if flag == False:404 print "Failed!",TimeLog.GetInstance().getCost()405 elif flag == True:406 print "Success!",TimeLog.GetInstance().getCost()407 else:408 print "Unexpected!",TimeLog.GetInstance().getCost()409 Flag = False410 time.sleep(0.1)411 return flag,TimeLog.GetInstance().getCost()412 #return flag,time.time()-delta-TIME_WAIT413def launcherD(dag_file):414 #set the log mode415 #logging.basicConfig(level=logging.DEBUG)416 #logging.basicConfig(level=logging.INFO)417 #logging.basicConfig(level=logging.WARNING)418 logging.basicConfig(level=logging.WARNING)419 #logging.basicConfig(level=logging.ERROR)420 from timelog import TimeLog421 TimeLog.GetInstance().reset()422 #generate rules and install them on switch 1423 pcg = PostcardGernerator.PostcardGernerator(dag_file)424 pcg.start()425 #collect postcard426 #post = PostCardProcessor('s1-eth4')427 #post.start()428 PostCardProcessor.Start()429 time.sleep(1)430 #logging.info("1# start to collect %.8f" %time.time())431 #start to generate packets432 TimeLog.GetInstance().clock()433 import parser, SemiAdap434 types = parser.type_parse("typename.txt")435 rule_list,edge_dict = parser.DAGLoader(dag_file);436 flag = SemiAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)437 if flag == False:438 print "Failed!",TimeLog.GetInstance().getCost()439 elif flag == True:440 print "Success!",TimeLog.GetInstance().getCost()441 else:442 print "Unexpected!",TimeLog.GetInstance().getCost()443 Flag = False444 time.sleep(0.1)445 return flag,TimeLog.GetInstance().getCost()446 #return flag,time.time()-delta-TIME_WAIT447def launcherDWithWrongTable(dag_file, wrong_dag):448 #set the log mode449 #logging.basicConfig(level=logging.DEBUG)450 #logging.basicConfig(level=logging.INFO)451 #logging.basicConfig(level=logging.WARNING)452 logging.basicConfig(level=logging.WARNING)453 #logging.basicConfig(level=logging.ERROR)454 from timelog import TimeLog455 TimeLog.GetInstance().reset()456 #generate rules and install them on switch 1457 pcg = PostcardGernerator.PostcardGernerator(wrong_dag)458 pcg.start()459 #collect postcard460 #post = PostCardProcessor('s1-eth4')461 PostCardProcessor.Start()462 #post.start()463 time.sleep(1)464 #logging.info("1# start to collect %.8f" %time.time())465 #start to generate packets466 TimeLog.GetInstance().clock()467 import parser, SemiAdap468 types = parser.type_parse("typename.txt")469 rule_list,edge_dict = parser.DAGLoader(dag_file);470 flag = SemiAdap.packetGenerator(edge_dict, rule_list, types, postCardQueue)471 if flag == False:472 print "Failed!",TimeLog.GetInstance().getCost()473 elif flag == True:474 print "Success!",TimeLog.GetInstance().getCost()475 else:476 print "Unexpected!",TimeLog.GetInstance().getCost()477 Flag = False478 time.sleep(0.1)479 return flag,TimeLog.GetInstance().getCost()480 #return flag,time.time()-delta-TIME_WAIT481def preTest(dag_file):482 import parser, PreTest483 types = parser.type_parse("typename.txt")484 rule_list,edge_dict = parser.DAGLoader(dag_file);485 pairs = PreTest.packetGenerator(edge_dict, rule_list, types)486 #logging.info("2# packets generated %.8f" %time.time())487 if pairs[0] == False:488 flag = False489 return pairs490 return True,0491if __name__ == "__main__":492 #parse the input arguments493 if len(sys.argv) != 2:494 print "Usage: python launcher.py dag_file"495 exit(0)496 dag_file = sys.argv[1]497 #launcherA(dag_file)498 #launcherAWithWrongTable(dag_file,dag_file+".miss")499 #launcherAWithWrongTable(dag_file,dag_file+".order")500 #launcherB(dag_file)501 #launcherBWithWrongTable(dag_file,dag_file+".miss")502 #launcherBWithWrongTable(dag_file,dag_file+".order")503 #launcherC(dag_file)504 #launcherCWithWrongTable(dag_file,dag_file+".miss")505 #launcherCWithWrongTable(dag_file,dag_file+".order")506 launcherD(dag_file)507 #launcherDWithWrongTable(dag_file,dag_file+".miss")508 #launcherDWithWrongTable(dag_file,dag_file+".order")...

Full Screen

Full Screen

replace.py

Source:replace.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3__author__ = "xyjxyf"4"替换枚举类型"5import sys6import os7import re8walk_path = '../'9# 需要替换的字典:key->旧值, value->新值10#======================= special',11replace_dic = {12'\<msg.status\>\s*=[^=]\(.*\);': 'msg.setStatus(\1);',13'\<msg.status\>\s*[^=]': 'msg.status() ',14'\<msg.status\>\s*==': 'msg.status() ==',15'\<msg.direct\>\s*=[^=]\(.*\);': 'msg.setdirect(\1);',16'\<msg.direct\>\s*==': 'msg.direct() ==',17'\<msg.type\>\s*==': 'msg.getType() ==',18'\<msg.msgTime\>\s*=[^=]\(.*\);': 'msg.setMsgTime(\1);',19'\<msg.msgTime\>\s*==': 'msg.getMsgTime() ==',20'\<msg.chatType\>\s*=[^=]\(.*\);': 'msg.getChatType(\1);',21'\<msg.chatType\>\s*==': 'msg.getChatType() ==',22'\<msg.progress\>\s*==': 'msg.progress() ==',23'\<msg.unread\>\s*=[^=]\(.*\);': 'msg.setUnread(\1);',24'\<msg.unread\>\s*==': 'msg.isUnread() ==',25'\<msg.isAcked\>\s*==': 'msg.isAcked() ==',26'\<msg.msgId\>\s*=[^=]\(.*\);': 'msg.setMsgId(\1);',27'\<msg.msgId\>\s*==': 'msg.getMsgId() ==',28'\<msg.isListened\>\s*=[^=]\(.*\);': 'msg.setisListened(\1);',29'\<msg.isListened\>\s*==': 'msg.isListened() ==',30'\<msg.isDelivered\>\s*=[^=]\(.*\);': 'msg.setDelivered(\1);',31'\<msg.isDelivered\>\s*==': 'msg.isDelivered() ==',32'\<msg.from\>\s*=[^=]\(.*\);': 'msg.setFrom(\1);',33'\<msg.from\>\s*==': 'msg.getFrom() ==',34'\<msg.to\>\s*=[^=]\(.*\);': 'msg.setTo(\1);',35'\<msg.to\>\s*==': 'msg.getTo() ==',36'\<message.status\>\s*=[^=]\(.*\);': 'message.setStatus(\1);',37'\<message.status\>\s*==': 'message.status() ==',38'\<message.direct\>\s*=[^=]\(.*\);': 'message.setdirect(\1);',39'\<message.direct\>\s*==': 'message.direct() ==',40'\<message.type\>\s*==': 'message.getType() ==',41'\<message.msgTime\>\s*=[^=]\(.*\);': 'message.setMsgTime(\1);',42'\<message.msgTime\>\s*==': 'message.getMsgTime() ==',43'\<message.chatType\>\s*=[^=]\(.*\);': 'message.setChatType(\1);',44'\<message.chatType\>\s*==': 'message.getChatType() ==',45'\<message.progress\>\s*==': 'message.progress() ==',46'\<message.unread\>\s*=[^=]\(.*\);': 'message.setUnread(\1);',47'\<message.unread\>\s*==': 'message.isUnread() ==',48'\<message.isAcked\>\s*==': 'message.isAcked() ==',49'\<message.msgId\>\s*=[^=]\(.*\);': 'message.setMsgId(\1);',50'\<message.msgId\>\s*==': 'message.getMsgId() ==',51'\<message.isListened\>\s*=[^=]\(.*\);': 'message.setisListened(\1);',52'\<message.isListened\>\s*==': 'message.isListened() ==',53'\<message.isDelivered\>\s*=[^=]\(.*\);': 'message.setDelivered(\1);',54'\<message.isDelivered\>\s*==': 'message.isDelivered() ==',55'\<message.from\>\s*=[^=]\(.*\);': 'message.setFrom(\1);',56'\<message.from\>\s*==': 'message.getFrom() ==',57'\<message.to\>\s*=[^=]\(.*\);': 'message.setTo(\1);',58'\<message.to\>\s*==': 'message.getTo() ==',59#======================= normal',60'\<EMChatOptions\>': 'EMOptions',61'\<CmdMessageBody\>': 'EMCmdMessageBody',62'\<FileMessageBody\>': 'EMFileMessageBody',63'\<ImageMessageBody\>': 'EMImageMessageBody',64'\<LocationMessageBody\>': 'EMLocationMessageBody',65'\<TextMessageBody\>': 'EMTextMessageBody',66'\<VideoMessageBody\>': 'EMVideoMessageBody',67'\<VoiceMessageBody\>': 'EMVoiceMessageBody',68'\<conversation.loadMoreGroupMsgFromDB\>': 'conversation.loadMoreMsgFromDB',69'EMChat.getInstance().isLoggedIn()': 'EMClient.getInstance().isLoggedInBefore()',70'EMChat.getInstance().setDebugMode': 'EMClient.getInstance().setDebugMode',71'EMChat.getInstance().uploadLog': 'EMClient.getInstance().uploadLog',72'EMChatManager.getInstance().ackMessageRead': 'EMClient.getInstance().chatManager().ackMessageRead',73'EMChatManager.getInstance().addCallStateChangeListener': 'EMClient.getInstance().callManager().addCallStateChangeListener',74'EMChatManager.getInstance().addChatRoomChangeListener': 'EMClient.getInstance().chatroomManager().addChatRoomChangeListener',75'EMChatManager.getInstance().addConnectionListener': 'EMClient.getInstance().addConnectionListener',76'EMChatManager.getInstance().answerCall();': 'EMClient.getInstance().callManager().answerCall();',77'EMChatManager.getInstance().asyncFetchMessage': 'EMClient.getInstance().chatManager().downloadThumbnail',78'EMChatManager.getInstance().clearConversation': 'EMClient.getInstance().chatManager().deleteConversation',79'EMChatManager.getInstance().createAccountOnServer': 'EMClient.getInstance().createAccount',80'EMChatManager.getInstance().downloadFile': 'EMClient.getInstance().chatManager().downloadFile',81'EMChatManager.getInstance': 'EMClient.getInstance',82'EMChatManager.getInstance().endCall();': 'EMClient.getInstance().callManager().endCall();',83'EMChatManager.getInstance().fetchChatRoomFromServer': 'EMClient.getInstance().chatroomManager().fetchChatRoomFromServer',84'EMChatManager.getInstance().fetchPublicChatRoomsFromServer': 'EMClient.getInstance().chatroomManager().fetchPublicChatRoomsFromServer',85'EMChatManager.getInstance().getAllChatRooms();': 'EMClient.getInstance().chatroomManager().getAllChatRooms();',86'EMChatManager.getInstance().getAllConversations()': 'EMClient.getInstance().chatManager().getAllConversations()',87'EMChatManager.getInstance().getChatOptions()': 'EMClient.getInstance().getOptions()',88'EMChatManager.getInstance().getChatRoom': 'EMClient.getInstance().chatroomManager().getChatRoom',89'EMChatManager.getInstance().getConversation': 'EMClient.getInstance().chatManager().getConversation',90'EMChatManager.getInstance().getCurrentUser();': 'EMClient.getInstance().getCurrentUser();',91'EMChatManager.getInstance().getCurrentUser()': 'EMClient.getInstance().getCurrentUser()',92'EMChatManager.getInstance().getIncomingCallBroadcastAction()': 'EMClient.getInstance().callManager().getIncomingCallBroadcastAction()',93'EMChatManager.getInstance().getMessage': 'EMClient.getInstance().chatManager().getMessage',94'EMChatManager.getInstance().getRobotsFromServer();': 'EMClient.getInstance().getRobotsFromServer();',95'EMChatManager().getInstance().getUnreadMsgsCount();': 'EMClient.getInstance().chatManager().getUnreadMsgsCount();',96'EMChatManager.getInstance().isConnected()': 'EMClient.getInstance().isConnected()',97'EMChatManager.getInstance().isDirectCall()': 'EMClient.getInstance().callManager().isDirectCall()',98'EMChatManager.getInstance().isSlientMessage': 'EMClient.getInstance().chatManager().isSlientMessage',99'EMChatManager.getInstance().joinChatRoom': 'EMClient.getInstance().chatroomManager().joinChatRoom',100'EMChatManager.getInstance().leaveChatRoom': 'EMClient.getInstance().chatroomManager().leaveChatRoom',101'EMChatManager.getInstance().loadAllConversations();': 'EMClient.getInstance().chatManager().loadAllConversations();',102'EMChatManager.getInstance().login': 'EMClient.getInstance().login',103'EMChatManager.getInstance().makeVideoCall': 'EMClient.getInstance().callManager().makeVideoCall',104'EMChatManager.getInstance().makeVoiceCall': 'EMClient.getInstance().callManager().makeVoiceCall',105'EMChatManager.getInstance().rejectCall();': 'EMClient.getInstance().callManager().rejectCall();',106'EMChatManager.getInstance().removeCallStateChangeListener': 'EMClient.getInstance().callManager().removeCallStateChangeListener',107'EMChatManager.getInstance().removeConnectionListener': 'EMClient.getInstance().removeConnectionListener',108'EMChatManager.getInstance().saveMessage': 'EMClient.getInstance().chatManager().saveMessage',109'EMChatManager.getInstance().sendMessage': 'EMClient.getInstance().chatManager().sendMessage',110'EMChatManager.getInstance().setMessageListened': 'EMClient.getInstance().chatManager().setMessageListened',111'EMChatManager.getInstance().updateCurrentUserNick': 'EMClient.getInstance().updateCurrentUserNick',112'EMContactManager.getInstance().addContact': 'EMClient.getInstance().contactManager().addContact',113'EMContactManager.getInstance().addUserToBlackList': 'EMClient.getInstance().contactManager().addUserToBlackList',114'EMContactManager.getInstance().deleteContact': 'EMClient.getInstance().contactManager().deleteContact',115'EMContactManager.getInstance().deleteUserFromBlackList': 'EMClient.getInstance().contactManager().removeUserFromBlackList',116'EMContactManager.getInstance().getBlackListUsernames();': 'EMClient.getInstance().contactManager().getBlackListUsernames();',117'EMContactManager.getInstance().getBlackListUsernamesFromServer();': 'EMClient.getInstance().contactManager().getBlackListFromServer();',118'EMContactManager.getInstance().getContactUserNames();': 'EMClient.getInstance().contactManager().getAllContacts();',119'EMContactManager.getInstance().setContactListener': 'EMClient.getInstance().contactManager().setContactListener',120'EMGroupManager.getInstance().addGroupChangeListener': 'EMClient.getInstance().groupManager().addGroupChangeListener',121'EMGroupManager.getInstance().addUsersToGroup': 'EMClient.getInstance().groupManager().addUsersToGroup',122'EMGroupManager.getInstance().applyJoinToGroup': 'EMClient.getInstance().groupManager().applyJoinToGroup',123'EMGroupManager.getInstance().asyncGetGroupsFromServer': 'EMClient.getInstance().groupManager().asyncGetGroupsFromServer',124'EMGroupManager.getInstance().blockGroupMessage': 'EMClient.getInstance().groupManager().blockGroupMessage',125'EMGroupManager.getInstance().blockUser': 'EMClient.getInstance().groupManager().blockUser',126'EMGroupManager.getInstance().changeGroupName': 'EMClient.getInstance().groupManager().changeGroupName',127'EMGroupManager.getInstance().createOrUpdateLocalGroup': 'EMClient.getInstance().groupManager().createOrUpdateLocalGroup',128'EMGroupManager.getInstance().createPrivateGroup': 'EMClient.getInstance().groupManager().createPrivateGroup',129'EMGroupManager.getInstance().createPublicGroup': 'EMClient.getInstance().groupManager().createPublicGroup',130'EMGroupManager.getInstance()': 'EMClient.getInstance().groupManager()',131'EMGroupManager.getInstance().exitAndDeleteGroup': 'EMClient.getInstance().groupManager().exitAndDeleteGroup',132'EMGroupManager.getInstance().exitFromGroup': 'EMClient.getInstance().groupManager().exitFromGroup',133'EMGroupManager.getInstance().getAllGroups();': 'EMClient.getInstance().groupManager().getAllGroups();',134'EMGroupManager.getInstance().getBlockedUsers': 'EMClient.getInstance().groupManager().getBlockedUsers',135'EMGroupManager.getInstance().getGroup': 'EMClient.getInstance().groupManager().getGroup',136'EMGroupManager.getInstance().getGroupFromServer': 'EMClient.getInstance().groupManager().getGroupFromServer',137'EMGroupManager.getInstance().getGroupsFromServer();': 'EMClient.getInstance().groupManager().getGroupsFromServer();',138'EMGroupManager.getInstance().getPublicGroupsFromServer': 'EMClient.getInstance().groupManager().getPublicGroupsFromServer',139'EMGroupManager.getInstance().inviteUser': 'EMClient.getInstance().groupManager().inviteUser',140'EMGroupManager.getInstance().joinGroup': 'EMClient.getInstance().groupManager().joinGroup',141'EMGroupManager.getInstance().loadAllGroups': 'EMClient.getInstance().groupManager().loadAllGroups',142'EMGroupManager.getInstance().removeUserFromGroup': 'EMClient.getInstance().groupManager().removeUserFromGroup',143'EMGroupManager.getInstance().unblockGroupMessage': 'EMClient.getInstance().groupManager().unblockGroupMessage',144'EMGroupManager.getInstance().unblockUser': 'EMClient.getInstance().groupManager().unblockUser'145}146def check_main(root_path):147 if (len(sys.argv) < 2):148 print "Please input source folder path"149 return 1150 for root, dirs, files in os.walk(sys.argv[1]):151 for file_path in files:152 if file_path.endswith('.java'):153 full_path = os.path.join(root, file_path)154 print full_path155 fr = open(full_path, 'r')156 content = fr.read()157 fr.close()158 for key in replace_dic:159 match = re.search(key, content)160 if match:161 #替换162 content = re.sub(key, replace_dic[key], content);163 #重新写入文件164 open(full_path,'w').write(content)165if __name__ == '__main__':...

Full Screen

Full Screen

options.js

Source:options.js Github

copy

Full Screen

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4var AddLanguageOverlay = options.AddLanguageOverlay;5var AlertOverlay = options.AlertOverlay;6var AutofillEditAddressOverlay = options.AutofillEditAddressOverlay;7var AutofillEditCreditCardOverlay = options.AutofillEditCreditCardOverlay;8var AutofillOptions = options.AutofillOptions;9var BrowserOptions = options.BrowserOptions;10var ClearBrowserDataOverlay = options.ClearBrowserDataOverlay;11var ContentSettings = options.ContentSettings;12var ContentSettingsExceptionsArea =13 options.contentSettings.ContentSettingsExceptionsArea;14var CookiesView = options.CookiesView;15var FontSettings = options.FontSettings;16var HandlerOptions = options.HandlerOptions;17var HomePageOverlay = options.HomePageOverlay;18var ImportDataOverlay = options.ImportDataOverlay;19var InstantConfirmOverlay = options.InstantConfirmOverlay;20var LanguageOptions = options.LanguageOptions;21var OptionsPage = options.OptionsPage;22var PasswordManager = options.PasswordManager;23var Preferences = options.Preferences;24var PreferredNetworks = options.PreferredNetworks;25var ManageProfileOverlay = options.ManageProfileOverlay;26var SearchEngineManager = options.SearchEngineManager;27var SearchPage = options.SearchPage;28var SessionRestoreOverlay = options.SessionRestoreOverlay;29var StartupOverlay = options.StartupOverlay;30var SyncSetupOverlay = options.SyncSetupOverlay;31var VirtualKeyboardManager = options.VirtualKeyboardManager;32/**33 * DOMContentLoaded handler, sets up the page.34 */35function load() {36 // Decorate the existing elements in the document.37 cr.ui.decorate('input[pref][type=checkbox]', options.PrefCheckbox);38 cr.ui.decorate('input[pref][type=number]', options.PrefNumber);39 cr.ui.decorate('input[pref][type=radio]', options.PrefRadio);40 cr.ui.decorate('input[pref][type=range]', options.PrefRange);41 cr.ui.decorate('select[pref]', options.PrefSelect);42 cr.ui.decorate('input[pref][type=text]', options.PrefTextField);43 cr.ui.decorate('input[pref][type=url]', options.PrefTextField);44 cr.ui.decorate('button[pref]', options.PrefButton);45 cr.ui.decorate('#content-settings-page input[type=radio]:not(.handler-radio)',46 options.ContentSettingsRadio);47 cr.ui.decorate('#content-settings-page input[type=radio].handler-radio',48 options.HandlersEnabledRadio);49 cr.ui.decorate('span.controlled-setting-indicator',50 options.ControlledSettingIndicator);51 localStrings = new LocalStrings();52 // Top level pages.53 OptionsPage.register(SearchPage.getInstance());54 OptionsPage.register(BrowserOptions.getInstance());55 // Overlays.56 OptionsPage.registerOverlay(AddLanguageOverlay.getInstance(),57 LanguageOptions.getInstance());58 OptionsPage.registerOverlay(AlertOverlay.getInstance());59 OptionsPage.registerOverlay(AutofillEditAddressOverlay.getInstance(),60 AutofillOptions.getInstance());61 OptionsPage.registerOverlay(AutofillEditCreditCardOverlay.getInstance(),62 AutofillOptions.getInstance());63 OptionsPage.registerOverlay(AutofillOptions.getInstance(),64 BrowserOptions.getInstance(),65 [$('autofill-settings')]);66 OptionsPage.registerOverlay(ClearBrowserDataOverlay.getInstance(),67 BrowserOptions.getInstance(),68 [$('privacyClearDataButton')]);69 OptionsPage.registerOverlay(ContentSettings.getInstance(),70 BrowserOptions.getInstance(),71 [$('privacyContentSettingsButton')]);72 OptionsPage.registerOverlay(ContentSettingsExceptionsArea.getInstance(),73 ContentSettings.getInstance());74 OptionsPage.registerOverlay(CookiesView.getInstance(),75 ContentSettings.getInstance(),76 [$('privacyContentSettingsButton'),77 $('show-cookies-button')]);78 OptionsPage.registerOverlay(FontSettings.getInstance(),79 BrowserOptions.getInstance(),80 [$('fontSettingsCustomizeFontsButton')]);81 if (HandlerOptions && $('manage-handlers-button')) {82 OptionsPage.registerOverlay(HandlerOptions.getInstance(),83 ContentSettings.getInstance(),84 [$('manage-handlers-button')]);85 }86 OptionsPage.registerOverlay(HomePageOverlay.getInstance(),87 BrowserOptions.getInstance(),88 [$('change-home-page')]);89 OptionsPage.registerOverlay(ImportDataOverlay.getInstance(),90 BrowserOptions.getInstance());91 OptionsPage.registerOverlay(InstantConfirmOverlay.getInstance(),92 BrowserOptions.getInstance());93 OptionsPage.registerOverlay(LanguageOptions.getInstance(),94 BrowserOptions.getInstance(),95 [$('language-button')]);96 OptionsPage.registerOverlay(ManageProfileOverlay.getInstance(),97 BrowserOptions.getInstance());98 OptionsPage.registerOverlay(PasswordManager.getInstance(),99 BrowserOptions.getInstance(),100 [$('manage-passwords')]);101 OptionsPage.registerOverlay(SearchEngineManager.getInstance(),102 BrowserOptions.getInstance(),103 [$('manage-default-search-engines')]);104 OptionsPage.registerOverlay(SessionRestoreOverlay.getInstance(),105 BrowserOptions.getInstance());106 OptionsPage.registerOverlay(StartupOverlay.getInstance(),107 BrowserOptions.getInstance());108 OptionsPage.registerOverlay(SyncSetupOverlay.getInstance(),109 BrowserOptions.getInstance());110 if (cr.isChromeOS) {111 OptionsPage.registerOverlay(AccountsOptions.getInstance(),112 BrowserOptions.getInstance(),113 [$('manage-accounts-button')]);114 OptionsPage.registerOverlay(BluetoothOptions.getInstance(),115 BrowserOptions.getInstance(),116 [$('bluetooth-add-device')]);117 OptionsPage.registerOverlay(BluetoothPairing.getInstance(),118 BrowserOptions.getInstance());119 OptionsPage.registerOverlay(ChangePictureOptions.getInstance(),120 BrowserOptions.getInstance(),121 [$('account-picture')]);122 OptionsPage.registerOverlay(DetailsInternetPage.getInstance(),123 BrowserOptions.getInstance());124 OptionsPage.registerOverlay(InternetOptions.getInstance(),125 BrowserOptions.getInstance());126 OptionsPage.registerOverlay(KeyboardOverlay.getInstance(),127 BrowserOptions.getInstance(),128 [$('keyboard-settings-button')]);129 OptionsPage.registerOverlay(PointerOverlay.getInstance(),130 BrowserOptions.getInstance(),131 [$('pointer-settings-button')]);132 OptionsPage.registerOverlay(PreferredNetworks.getInstance(),133 BrowserOptions.getInstance());134 OptionsPage.registerOverlay(135 new OptionsPage('languageChewing',136 templateData.languageChewingPageTabTitle,137 'languageChewingPage'),138 LanguageOptions.getInstance());139 OptionsPage.registerOverlay(140 new OptionsPage('languageHangul',141 templateData.languageHangulPageTabTitle,142 'languageHangulPage'),143 LanguageOptions.getInstance());144 OptionsPage.registerOverlay(145 new OptionsPage('languageMozc',146 templateData.languageMozcPageTabTitle,147 'languageMozcPage'),148 LanguageOptions.getInstance());149 OptionsPage.registerOverlay(150 new OptionsPage('languagePinyin',151 templateData.languagePinyinPageTabTitle,152 'languagePinyinPage'),153 LanguageOptions.getInstance());154 // Only use the VirtualKeyboardManager if the keyboard DOM elements (which155 // it will assume exists) are present (i.e. if we were built with156 // use_virtual_keyboard=1).157 if ($('language-options-virtual-keyboard')) {158 OptionsPage.registerOverlay(VirtualKeyboardManager.getInstance(),159 LanguageOptions.getInstance());160 }161 }162<if expr="pp_ifdef('chromeos') and pp_ifdef('use_ash')">163 if (SetWallpaperOptions) {164 OptionsPage.registerOverlay(SetWallpaperOptions.getInstance(),165 BrowserOptions.getInstance(),166 [$('set-wallpaper')]);167 }168</if>169 if (!cr.isWindows && !cr.isMac) {170 OptionsPage.registerOverlay(CertificateBackupOverlay.getInstance(),171 CertificateManager.getInstance());172 OptionsPage.registerOverlay(CertificateEditCaTrustOverlay.getInstance(),173 CertificateManager.getInstance());174 OptionsPage.registerOverlay(CertificateImportErrorOverlay.getInstance(),175 CertificateManager.getInstance());176 OptionsPage.registerOverlay(CertificateManager.getInstance(),177 BrowserOptions.getInstance(),178 [$('certificatesManageButton')]);179 OptionsPage.registerOverlay(CertificateRestoreOverlay.getInstance(),180 CertificateManager.getInstance());181 }182 Preferences.getInstance().initialize();183 OptionsPage.initialize();184 var path = document.location.pathname;185 if (path.length > 1) {186 // Skip starting slash and remove trailing slash (if any).187 var pageName = path.slice(1).replace(/\/$/, '');188 if (pageName == 'proxy') {189 // The following page doesn't have a unique URL at the moment, so do190 // something sensible if a user pastes this link or refreshes on this URL.191 pageName = ProxyOptions ? ProxyOptions.getInstance().parentPage.name :192 AdvancedOptions.getInstance().name;193 }194 OptionsPage.showPageByName(pageName, true, {replaceState: true});195 } else {196 OptionsPage.showDefaultPage();197 }198 var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');199 for (var i = 0; i < subpagesNavTabs.length; i++) {200 subpagesNavTabs[i].onclick = function(event) {201 OptionsPage.showTab(event.srcElement);202 };203 }204 if (navigator.plugins['Shockwave Flash'])205 document.documentElement.setAttribute('hasFlashPlugin', '');206 window.setTimeout(function() {207 document.documentElement.classList.remove('loading');208 });209}210document.documentElement.classList.add('loading');211document.addEventListener('DOMContentLoaded', load);212/**213 * Listener for the |beforeunload| event.214 */215window.onbeforeunload = function() {216 options.OptionsPage.willClose();217};218/**219 * Listener for the |popstate| event.220 * @param {Event} e The |popstate| event.221 */222window.onpopstate = function(e) {223 options.OptionsPage.setState(e.state);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful