From f4e6b57ec1524f7b21998758c780bcaa738c6d21 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sun, 24 Aug 2014 00:48:30 +1000 Subject: [PATCH] moved bgp test harness to its own repo --- bgpfake/bf.js | 296 ---------------------- bgpfake/bf2.js | 710 ---------------------------------------------------- bgpfake/bgp_stuff | Bin 1869 -> 0 bytes bgpfake/bgp_stuff2 | Bin 1691 -> 0 bytes 4 files changed, 0 insertions(+), 1006 deletions(-) delete mode 100644 bgpfake/bf.js delete mode 100644 bgpfake/bf2.js delete mode 100644 bgpfake/bgp_stuff delete mode 100644 bgpfake/bgp_stuff2 diff --git a/bgpfake/bf.js b/bgpfake/bf.js deleted file mode 100644 index a8a66e3..0000000 --- a/bgpfake/bf.js +++ /dev/null @@ -1,296 +0,0 @@ -var myas=4321; -var myip="10.10.40.1"; -var number_of_route_adverts = 6; -var routes_per_advert = 4; - -var net = require('net'); - -var updateSent = 0; - -var scon; - - -function createentry(i) { - // split into octets - var a = 0; - var b = 0; - var c = 0; - - var x = 45<<16; - - //console.log("var x is "+x); - i = i+x; - //console.log("i now: "+i+" i>>8 "+i+" i>>16 "+(i>>16)); - - c = i&255; - b = (i>>8)&255; - a = (i>>16)&255; - - - //console.log("created "+a+"."+b+"."+c+" from "+i); - return a+"."+b+"."+c; -} - -function createaspath(i) { - var n=(i%5)+2; - var as = 1024; - var ret = new Array(); - - for(var t=0; t0) thisdata[2] += constructUpdateMessage(thisdata, true, routes_per_advert); - else thisdata[2] = constructUpdateMessage(thisdata, false, routes_per_advert); - } - console.log("thisdata is..."); - console.log(thisdata); - //console.log(thisdata.toJSON()); - console.log(thisdata[2].length); - console.log(thisdata[2].toString()); - data[t] = thisdata; -} -console.log("finish construction"); - - -//console.log("data: " + data.toString()); -//console.log(data); -//console.log("Done!: " + data.length); - -function parseBuffer(b, c) { - var len = b.readUInt16BE(16); - var type = b.readUInt8(18); - - //console.log("got input: " + len + ", type: " + type); - - if(type == 1) { - var vers = b.readUInt8(19); - var as = b.readUInt16BE(20); - var ht = b.readUInt16BE(22); - var ot1 = b.readUInt8(24); - var ot2 = b.readUInt8(25); - var ot3 = b.readUInt8(26); - var ot4 = b.readUInt8(27); - var opl = b.readUInt8(28); - console.log("got open type, vers: "+vers+", as: " + as); - console.log("ht: " + ht + ", id: "+ot1+"."+ot2+"."+ot3+"."+ot4+", opl: "+opl); - - - console.log("sending our open type"); - var out = new Buffer(29); - - - out.fill(0xff, 0, 16); - out.writeUInt16BE(29, 16); - out.writeUInt8(1, 18); - out.writeUInt8(4, 19); - out.writeUInt16BE(myas, 20); - out.writeUInt16BE(90, 22); - out.writeUInt8(10, 24); - out.writeUInt8(99, 25); - out.writeUInt8(99, 26); - out.writeUInt8(1,27); - out.writeUInt8(0,28); - - c.write(out); - } else if(type == 4) { - console.log("writing keepalive - exact as sent"); - c.write(b); - //if(updateSent ==0) beginUpdateSend(c); - } else if(type == 2) { - console.log("got update..."); - if(updateSent ==0) beginUpdateSend(c); - } else { - console.log("sending end..."); - c.end(); - } - - -} - -// this function gets prefix t from data[] and then -// creates an update message for it -function constructUpdateMessage(localdata, onlynlri, n_up) { - console.log("Construction update for "+t); - var bsize = 0; - - console.log("localdata0: " + localdata[0]); - console.log("localdata1: " + localdata[1]); - console.log("localdata0 - : " + typeof localdata[1]); - console.log("localdata1 - : " + typeof localdata[1]); - - // first the header components - bsize += 16; - - // next the length component - bsize += 2; - - // next the n unfeasible - bsize += 2; - - // next, path attr length - bsize += 2; - - - // now we begin the path attrs - // first origin - simple - var aspathn = 4; - - // next as path - hard, flag + type + len + aspath segment - aspathn += 3; - - // as path segment size = 1 (type), + 1 (len) + as's*2 - var aspathlen = ((localdata[1].length+1)*2)+1+1; - aspathn += aspathlen; - - // now next hop attrs = flag (1) + type (1) + len (1) + octets (4); - aspathn += 7; - bsize += aspathn; - - // now nlri = prefix len (1) + prefix fixed in our case (3) - bsize += 4; - - // fudge - bsize+=1; - - // now figure out t_bsize; - var t_bsize = bsize + (4*(n_up-1)); - - //console.log("size: " + bsize + ", an: " + aspathn + " al:" + aspathlen); - var buf = new Buffer(bsize); - var bp = 0; - - // now lets create the buffer - buf.fill(0xff, bp, bp+16); - bp+=16; - buf.writeUInt16BE(t_bsize, bp); - bp+=2; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt16BE(0, bp); - bp+=2; - buf.writeUInt16BE(aspathn, bp); - bp+=2; - - // path attr - // origin - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(1, bp); - bp++; - buf.writeUInt8(1, bp); - bp++; - buf.writeUInt8(0, bp); - bp++; - - // as path - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt8(aspathlen, bp); - bp++; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt8(localdata[1].length+1, bp); - bp++; - //console.log("writing in my aspath: "+myas); - buf.writeUInt16BE(myas, bp); - bp+=2; - localdata[1].forEach(function (ed) { - //console.log("writing in aspath: "+ed); - buf.writeUInt16BE(ed, bp); - bp+=2; - }); - - // next hop - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(3, bp); - bp++; - buf.writeUInt8(4, bp); - bp++; - myip.split(".").forEach(function (ed) { - //console.log("writing in next hop info: " + ed); - buf.writeUInt8(parseInt(ed), bp); - bp++; - }); - - // last, nlri - if(onlynlri) { - console.log("constructing new buffer for only nlri"); - buf = new Buffer(4); - bp = 0; - } - buf.writeUInt8(24, bp); - bp++; - localdata[0].split(".").forEach(function(ed){ - console.log("Writing in nlri: "+ed); - buf.writeUInt8(parseInt(ed), bp); - bp++; - }); - - console.log("buf is:"); - console.log(buf); - console.log(buf.length); - - return buf; -} - -// start sending updates messages -function beginUpdateSend(c) { - updateSent = 1; - var n = 0; - data.forEach(function(led) { - c.write(led[2]); - n++; - }); - console.log("finished publishing - "+n); -} - -function serverconnection(c) { - - scon = c; - - c.on("end", function() { - console.log("Server disconnected"); - }); - - c.on("data", function(buffer) { - parseBuffer(buffer, c); - }); - - console.log("Service connected from: " + c.remoteAddress); - - //c.write("hello\r\n"); -} - -console.log("Prefixes created, starting server"); - -var server = net.createServer(serverconnection); - -server.listen(179, function() { - console.log("Server bound"); -}); diff --git a/bgpfake/bf2.js b/bgpfake/bf2.js deleted file mode 100644 index b9c0220..0000000 --- a/bgpfake/bf2.js +++ /dev/null @@ -1,710 +0,0 @@ -var readline = require('readline'); -var net = require('net'); - - - -// ---- vars - -var asPaths = new Array(); -var readyToSend = false; -var currentPrompt; -var rl; -var nCons = 0; -var nSent = 0; -var myAS; -var myIP; -var server; -var cState = "starting"; -var currentIPa = 1; -var currentIPb = 0; -var currentIPc = 0; -var timerIntervalObject; -var currentCon = 0; -var sequentialIPs = true; -var usePrivateRanges = false; -var randomNextHop = false; -var timeBetweenUpdates = 20; -var routesPerUpdate = 100; -var updatesPerInterval = 40; - -// ---- vars - - -if(typeof process.argv[2] == "undefined") { - usage(); -} - -if(typeof process.argv[3] == "undefined") { - usage(); -} - -function usage() { - console.log("Usage: "+process.argv[1]+" MyAS MyIP"); - process.exit(1); -} - - - - - -// ----------- startup - -myAS = process.argv[2]; -myIP = process.argv[3]; - - -startCLI(); -doPrompt(); -createAsPathArray(1048576); -startServer(); -cState = "idle"; -doPrompt(); - -// ----------- startup - - - - - - - - - - -// --------- CLI - -function updatePrompt() { - currentPrompt = "("+myAS+"/"+myIP+") "+cState+":"+nCons+"/"+nSent+" ("+currentIPa+"."+currentIPb+"."+currentIPc+") > "; -} - -function startCLI() { - currentPrompt = "("+myAS+"/"+myIP+") starting... > "; - - rl = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - - rl.on('line', function (cmd) { - switch(cmd) { - - case "?": - case "help": - case "h": - printCLIUsage(); - break; - case "r": - currentIPa = 1; - currentIPb = 0; - currentIPc = 0; - break; - case "a": - togglePrivateRange(); - break; - case "t": - toggleIPChoice(); - break; - case "m": - toggleRandomNextHop(); - break; - case "s": - printStatus(); - break; - case "u": - startUpdates(); - break; - case "p": - stopUpdates(); - break; - case "q": - case "quit": - case "end": - rl.close(); - process.exit(0); - break; - case "": - break; - } - - doPrompt(); - }); -} - - -function printStatus() { - console.log("---- Status ----"); - console.log("Currently "+cState); - console.log("Private ranges: "+usePrivateRanges); - console.log("Sequential publication: "+sequentialIPs); - console.log("Random NextHop: "+randomNextHop); - console.log("Number of connected peers: " + nCons); - console.log("Number of routes published: " + nSent); - console.log("My IP address: " + myIP); - console.log("My ASN: " + myAS); - console.log("Current IP (for sequential publications): " + currentIPa + "." + currentIPb + "." + currentIPc + "0/24"); - console.log("AS path table size: "+asPaths.length); -} - -function togglePrivateRange() { - if(usePrivateRanges) { - console.log("Switching off private range publication"); - usePrivateRanges = false; - } else { - console.log("Switching on private range publication"); - usePrivateRanges = true; - } -} - -function toggleIPChoice() { - if(sequentialIPs) { - sequentialIPs = false; - console.log("Switching to random IP addresses"); - } else { - console.log("Switching to sequential IP addresses"); - sequentialIPs = true; - } -} - - -function toggleRandomNextHop() { - if(randomNextHop) { - randomNextHop = false; - console.log("Switching form random next-hop to next-hop-self"); - } else { - randomNextHop = true; - console.log("Switching form next-hop-self to random next-hop"); - } - -} - -function doPrompt() { - updatePrompt(); - rl.setPrompt(currentPrompt); - rl.prompt(); -} - -function printCLIUsage() { - console.log("Help"); - console.log("\th[elp],? - this help menu"); - console.log("\tu - start sending route updates to connected peers"); - console.log("\tp - pause sending route updates to connected peers"); - console.log("\ta - toggle use of private ranges"); - console.log("\tm - toggle between random next hop and my ip as next hop (randomise last octet - assumes /24 on the ip address of this node)"); - console.log("\ts - status"); - console.log("\tt - toggles between random and sequential addressing"); - console.log("\tr - reset IP range back to beginning"); - console.log("\tq[uit],exit,end - Quit"); - console.log("Prompt layout"); - console.log("\t(AS/IP) state:connections/updates-sent (current-route)"); -} - -function updateState(newstate) { - if(cState == newstate) { - doPrompt(); - return; - } - - //starting - if(newstate == "starting") { - cState = newstate; - doPrompt(); - return; - } - - // idle - if(newstate == "idle") { - cState = newstate; - doPrompt(); - return; - } - - // connected - if(newstate == "connected") { - cState = newstate; - doPrompt(); - return; - } - - // ready - if(newstate == "ready") { - if(cState == "sending") return; - cState = newstate; - doPrompt(); - return; - } - - // sending - if(newstate == "sending") { - cState = newstate; - doPrompt(); - return; - } - - if(newstate == "stopping") { - cState = "stopping"; - doPrompt(); - return; - } - - -} - -// ------------- CLI - - - - - - - - - - - - - -//------------- network - -function startUpdates() { - if(cState == "sending") { - console.log("LOG: already sending..."); - return; - } - - if(cState != "ready") { - console.log("LOG: not ready to send yet"); - return; - } - - - // here goes nothing - console.log("LOG: starting update sending"); - updateState("sending"); - timerIntervalObject = setInterval(sendUpdate, timeBetweenUpdates); - //console.log("LOG: stopped sending updates"); -} - - -function sendUpdate() -{ - if(cState != "sending") { - console.log("oh, your killing me now?"); - clearInterval(timerIntervalObject); - updateState("ready"); - } else { - for(var i=0; i 254) { - - currentIPb++; - currentIPc = 0; - if(!usePrivateRanges) if(currentIPb == 168 && currentIPa == 192) currentIPb++; - if(currentIPb > 254) { - currentIPa++; - currentIPb = 0; - - // dont publish bogons or 127 - if(!usePrivateRanges) { - if(currentIPa == 10) currentIPa++; - if(currentIPa == 127) currentIPa++; - if(currentIPa == 128) currentIPa++; - if(currentIPa == 172) currentIPa++; - } - } - } - - if(currentIPa > 223) { - console.log("LOG: hit the end of the range, wrapping"); - currentIPa = 1; - currentIPb = 0; - currentIPc = 0; - } - - //console.log("created "+a+"."+b+"."+c+" from "+i); - return currentIPa+"."+currentIPb+"."+currentIPc; - } else { - ipa = 1+Math.round(Math.random()*223); - ipb = 1+Math.round(Math.random()*254); - ipc = 1+Math.round(Math.random()*254); - - - if(!usePrivateRanges) { - if(ipb == 168 && ipa == 192) ipb++; - if(ipa == 10) ipa++; - if(ipa == 127) ipa++; - if(ipa == 128) ipa++; - if(ipa == 172) ipa++; - } - - return ipa+"."+ipb+"."+ipc; - } - -} - -function getASPath() { - var n = Math.random(); - - return asPaths[Math.round(asPaths.length*n)]; -} - -function constructUpdateMessage(n_up) { - var bsize = 0; - - var aspath = getASPath(); - //console.log("aspath is"); - //console.log(aspath); - - // first the header components - bsize += 16; - - // next the length component - bsize += 2; - - // next the n unfeasible - bsize += 2; - - // next, path attr length - bsize += 2; - - - // now we begin the path attrs - // first origin - simple - var aspathn = 4; - - // next as path - hard, flag + type + len + aspath segment - aspathn += 3; - - // as path segment size = 1 (type), + 1 (len) + as's*2 - var aspathlen = ((aspath.length+1)*2)+1+1; - aspathn += aspathlen; - - // now next hop attrs = flag (1) + type (1) + len (1) + octets (4); - aspathn += 7; - bsize += aspathn; - - // now nlri = prefix len (1) + prefix fixed in our case (3) - bsize += 4*n_up; - - // fudge - bsize+=1; - - //console.log("size: " + bsize + ", an: " + aspathn + " al:" + aspathlen); - var buf = new Buffer(bsize); - var bp = 0; - - // now lets create the buffer - buf.fill(0xff, bp, bp+16); - bp+=16; - buf.writeUInt16BE(bsize, bp); - bp+=2; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt16BE(0, bp); - bp+=2; - buf.writeUInt16BE(aspathn, bp); - bp+=2; - - // path attr - // origin - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(1, bp); - bp++; - buf.writeUInt8(1, bp); - bp++; - buf.writeUInt8(0, bp); - bp++; - - // as path - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt8(aspathlen, bp); - bp++; - buf.writeUInt8(2, bp); - bp++; - buf.writeUInt8(aspath.length+1, bp); - bp++; - //console.log("writing in my aspath: "+myas); - buf.writeUInt16BE(myAS, bp); - bp+=2; - aspath.forEach(function (ed) { - //console.log("writing in aspath: "+ed); - buf.writeUInt16BE(ed, bp); - bp+=2; - }); - - // next hop - buf.writeUInt8(0x40, bp); - bp++; - buf.writeUInt8(3, bp); - bp++; - buf.writeUInt8(4, bp); - bp++; - -// if(randomNextHop) { -// rnh = getRandomNextHop(); -// rnh.split(".").forEach(function (ed) { -// //console.log("writing in next hop info: " + ed); -// buf.writeUInt8(parseInt(ed), bp); -// bp++; -// }); - myIP.split(".").forEach(function (ed) { - //console.log("writing in next hop info: " + ed); - buf.writeUInt8(parseInt(ed), bp); - bp++; - }); - - if(randomNextHop) { - nhns = Math.round(1+(Math.random()*250)); - bp-- - buf.writeUInt8(nhns, bp); - bp++; - } - - // last, nlri - for(var nn=0; nn < n_up; nn++) { - //console.log("bsize: "+bsize+" bp "+bp); - buf.writeUInt8(24, bp); - bp++; - var ip = getNextIP(); - ip.split(".").forEach(function(ed){ - //console.log("Writing in nlri: "+ed); - buf.writeUInt8(parseInt(ed), bp); - bp++; - }); - } - - - nSent += n_up; - - //console.log("buf is:"); - //console.log(buf); - //console.log(buf.length); - - return buf; -} - -function createAsPathArray(size) { - for(var i=0; iU(Oh?CGiYk9HPkG-QbvhMD&|TX(Uq34rwU5C z5WQ3oMGs*altr+zK?MaN23;)D1c~TPdI{S8f5tXvCSCZK*)!*SxAUK~y_x&hS>WLB zCz}Oe@W;~XpVfydy|50SsbKO#;dKRmKR-KrBCJk>;eU@aJgo!y3WmC&^Tzr4 z12nmVHQ-?v0Lx8yz~tot!%QrI<@Z+5JC3!`AJy2<5!d3d&_nAD$a;=t2$>k5bEuoo z?0tj`UpuB5FxBTkublUW82+N4ZuY_|WTSFvSNtDL?Q0y`zam3d$`|`m@e|)$nqz>- zl*T1QJdR*gF2scYqlsv09hHWK$j81^J+&id9UmxRIIah_lcFNl!*I9@49li~Wm$~T zVBrw!S&93^^^lnAV>U7N@Dia7Bl%Mg!W(91m5Sj-NOj52Ir-#jp5LQJi!94jsqGAW7e`k=Q#v?*C*u5gblLKGTqo zPTI?wa!$(8$-6N~ELmVo3R%2>D!EJ=?q$G-UhLkUO0!(RIXh<>Hkc!GsBK- zN->*e%x1}vySZ$tFq=LXk>=FM^;jAUO^xZ>EZ-JbgJ>@f?D%T*z(=gVm7`EKfSyRA^X;E3kuzpJ#^6-WN_*Far@Ox_4T0~^9vZXbp zH82#eKN@UEBoFLrY&j5I7Eq$1tSGW1gag5Y_4|{Ji548)A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