4 var net = require('net');
9 function createentry(i) {
16 //console.log("i is now: "+i);
18 // if we're above 256....
21 //console.log("i is now: "+i);
25 // if we're still above 256....
28 //console.log("i is now: "+i);
34 function createaspath(i) {
37 var ret = new Array();
39 for(var t=0; t<n; t++) {
41 as = 1024 + (i%30000);
47 console.log("startup....");
50 var num_to_create = 200000;
52 var data = new Array();
54 console.log("start construction");
55 for(var t=0; t<num_to_create; t++) {
56 var thisdata = new Array();
57 thisdata[0] = createentry(t);
58 //console.log("create entry from "+thisdata[0]+" with " + t);
59 thisdata[1] = createaspath(t);
60 // we construct the update messages while we do this
63 thisdata[2] = constructUpdateMessage(thisdata);
67 console.log("finish construction");
70 //console.log("data: " + data.toString());
71 //console.log("Done!: " + data.length);
73 function parseBuffer(b, c) {
74 var len = b.readUInt16BE(16);
75 var type = b.readUInt8(18);
77 console.log("got input: " + len + ", type: " + type);
80 var vers = b.readUInt8(19);
81 var as = b.readUInt16BE(20);
82 var ht = b.readUInt16BE(22);
83 var ot1 = b.readUInt8(24);
84 var ot2 = b.readUInt8(25);
85 var ot3 = b.readUInt8(26);
86 var ot4 = b.readUInt8(27);
87 var opl = b.readUInt8(28);
88 console.log("got open type, vers: "+vers+", as: " + as);
89 console.log("ht: " + ht + ", id: "+ot1+"."+ot2+"."+ot3+"."+ot4+", opl: "+opl);
92 console.log("sending our open type");
93 var out = new Buffer(29);
96 out.fill(0xff, 0, 16);
97 out.writeUInt16BE(29, 16);
98 out.writeUInt8(1, 18);
99 out.writeUInt8(4, 19);
100 out.writeUInt16BE(myas, 20);
101 out.writeUInt16BE(90, 22);
102 out.writeUInt8(10, 24);
103 out.writeUInt8(99, 25);
104 out.writeUInt8(99, 26);
105 out.writeUInt8(1,27);
106 out.writeUInt8(0,28);
109 } else if(type == 4) {
110 console.log("writing keepalive - exact as sent");
112 } else if(type == 2) {
113 console.log("got update...");
116 console.log("sending end...");
123 // this function gets prefix t from data[] and then
124 // creates an update message for it
125 function constructUpdateMessage(localdata) {
126 //console.log("Construction update for "+t);
129 //console.log("localdata0: " + localdata[0]);
130 //console.log("localdata1: " + localdata[1]);
131 //console.log("localdata0 - : " + typeof localdata[1]);
132 //console.log("localdata1 - : " + typeof localdata[1]);
134 // first the header components
137 // next the length component
140 // next the n unfeasible
143 // next, path attr length
147 // now we begin the path attrs
148 // first origin - simple
151 // next as path - hard, flag + type + len + aspath segment
154 // as path segment size = 1 (type), + 1 (len) + as's*2
155 var aspathlen = ((localdata[1].length+1)*2)+1+1;
156 aspathn += aspathlen;
158 // now next hop attrs = flag (1) + type (1) + len (1) + octets (4);
162 // now nlri = prefix len (1) + prefix fixed in our case (3)
168 //console.log("size: " + bsize + ", an: " + aspathn + " al:" + aspathlen);
169 var buf = new Buffer(bsize);
172 // now lets create the buffer
173 buf.fill(0xff, bp, bp+16);
175 buf.writeUInt16BE(bsize, bp);
177 buf.writeUInt8(2, bp);
179 buf.writeUInt16BE(0, bp);
181 buf.writeUInt16BE(aspathn, bp);
186 buf.writeUInt8(0x40, bp);
188 buf.writeUInt8(1, bp);
190 buf.writeUInt8(1, bp);
192 buf.writeUInt8(0, bp);
196 buf.writeUInt8(0x40, bp);
198 buf.writeUInt8(2, bp);
200 buf.writeUInt8(aspathlen, bp);
202 buf.writeUInt8(2, bp);
204 buf.writeUInt8(localdata[1].length+1, bp);
206 //console.log("writing in my aspath: "+myas);
207 buf.writeUInt16BE(myas, bp);
209 localdata[1].forEach(function (ed) {
210 //console.log("writing in aspath: "+ed);
211 buf.writeUInt16BE(ed, bp);
216 buf.writeUInt8(0x40, bp);
218 buf.writeUInt8(3, bp);
220 buf.writeUInt8(4, bp);
222 myip.split(".").forEach(function (ed) {
223 //console.log("writing in next hop info: " + ed);
224 buf.writeUInt8(parseInt(ed), bp);
229 buf.writeUInt8(24, bp);
231 localdata[0].split(".").forEach(function(ed){
232 //console.log("Writing in nlri: "+ed);
233 buf.writeUInt8(parseInt(ed), bp);
240 // start sending updates messages
241 function beginUpdateSend(c) {
242 data.forEach(function(led) {
247 function serverconnection(c) {
251 c.on("end", function() {
252 console.log("Server disconnected");
255 c.on("data", function(buffer) {
256 parseBuffer(buffer, c);
259 console.log("Service connected from: " + c.remoteAddress);
261 //c.write("hello\r\n");
264 console.log("Prefixes created, starting server");
266 var server = net.createServer(serverconnection);
268 server.listen(179, function() {
269 console.log("Server bound");