[Gd-chatter] r11474 - trunk/libraries/layer
hannes at gwydiondylan.org
hannes at gwydiondylan.org
Sun Oct 28 02:48:09 CEST 2007
Author: hannes
Date: Sun Oct 28 02:48:08 2007
New Revision: 11474
Added:
trunk/libraries/layer/dhcp.dylan (contents, props changed)
Modified:
trunk/libraries/layer/layer.hdp
trunk/libraries/layer/library.dylan
trunk/libraries/layer/module.dylan
trunk/libraries/layer/udp.dylan
Log:
Job: 7299
forgot those during the last commit
Added: trunk/libraries/layer/dhcp.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/layer/dhcp.dylan Sun Oct 28 02:48:08 2007
@@ -0,0 +1,94 @@
+module: layer
+
+define class <dhcp-client> (<filter>, <dhcp-client-state>)
+ slot send-socket, init-keyword: send-socket:;
+end;
+
+define method push-data-aux (input :: <push-input>,
+ node :: <dhcp-client>,
+ frame :: <dhcp-message>)
+ let message-type-frame = find-option(frame, <dhcp-message-type-option>);
+ if (instance?(node.state, <selecting>))
+ if (frame.operation = 2)
+ if (message-type-frame.message-type = 2)
+ node.offer := frame;
+ process-event(node, #"receive-offer");
+ end;
+ end;
+ end;
+ if (instance?(node.state, type-union(<requesting>, <rebinding>,
+ <renewing>, <rebooting>)))
+ if (frame.operation = 2)
+ if (message-type-frame.message-type = 5) //ack
+ process-event(node, #"receive-ack");
+ format-out("received ack %=\n", frame);
+ elseif (message-type-frame.message-type = 6) //nak
+ process-event(node, #"receive-nak")
+ end
+ end
+ end
+end;
+
+define constant $hardware-address
+ = make(<raw-frame>,
+ data: mac-address("00:de:ad:be:ef:00").data);
+
+define constant $broadcast-address = ipv4-address("255.255.255.255");
+
+define method state-transition (state :: <dhcp-client>,
+ old-state :: <init>,
+ new-state :: <selecting>) => ()
+ let random = random(2 ^ 16 - 1);
+ let (r1, r2) = values(logand(#xff, ash(random, -2)), logand(#xff, random));
+ let transaction-id = big-endian-unsigned-integer-4byte(list(#xde,#xad,r1,r2));
+ state.xid := transaction-id;
+ let packet = make(<dhcp-message>,
+ transaction-id: state.xid,
+ client-hardware-address: $hardware-address,
+ dhcp-options: list(make(<dhcp-message-type-option>,
+ message-type: 1)));
+ send(state.send-socket, $broadcast-address, packet);
+end;
+
+
+define function find-option (dhcp :: <dhcp-message>, option-class)
+ => (res)
+ block(ret)
+ for (i in dhcp.dhcp-options)
+ if (instance?(i, option-class))
+ ret(i)
+ end
+ end
+ end
+end;
+
+define method state-transition (state :: <dhcp-client-state>,
+ old-state :: <selecting>,
+ new-state :: <requesting>) => ()
+// if (matches-requirements?(state.offer))
+ let server-option = find-option(state.offer, <dhcp-server-identifier-option>);
+ let packet = make(<dhcp-message>,
+ transaction-id: state.xid,
+ client-hardware-address: $hardware-address,
+ dhcp-options: list(make(<dhcp-message-type-option>,
+ message-type: 3),
+ make(<dhcp-requested-ip-address-option>,
+ requested-ip: offer.your-ip-address),
+ make(<dhcp-server-identifier-option>,
+ selected-server: server-option.server-ip-address)));
+ send(state.send-socket, $broadcast-address, packet);
+//
+end;
+
+
+define method main()
+ let eth = build-ethernet-layer("ath0", promiscuous?: #t);
+ let ip-layer = build-ip-layer(eth);
+ let udp = make(<udp-layer>, ip-layer: ip-layer);
+ let socket = create-socket(udp, 67);
+ let dhcp = make(<dhcp-client>, send-socket: socket);
+ connect(socket.decapsulator, dhcp);
+ process-event(dhcp, #"send-discover");
+end;
+
+//main();
\ No newline at end of file
Modified: trunk/libraries/layer/layer.hdp
==============================================================================
--- trunk/libraries/layer/layer.hdp (original)
+++ trunk/libraries/layer/layer.hdp Sun Oct 28 02:48:08 2007
@@ -3,4 +3,5 @@
module
layer
tcp
- udp
\ No newline at end of file
+ udp
+ dhcp
\ No newline at end of file
Modified: trunk/libraries/layer/library.dylan
==============================================================================
--- trunk/libraries/layer/library.dylan (original)
+++ trunk/libraries/layer/library.dylan Sun Oct 28 02:48:08 2007
@@ -13,7 +13,9 @@
use vector-table;
use system, import: { date };
use tcp-state-machine;
+ use state-machine;
use protocols;
+ use dhcp-state-machine;
// Add any more module exports here.
export layer;
Modified: trunk/libraries/layer/module.dylan
==============================================================================
--- trunk/libraries/layer/module.dylan (original)
+++ trunk/libraries/layer/module.dylan Sun Oct 28 02:48:08 2007
@@ -17,9 +17,12 @@
use byte-vector;
use date, import: {<date>, current-date };
use tcp-state-machine;
+ use state-machine;
use simple-random;
use streams;
use ipv4;
+ use dhcp;
+ use dhcp-state-machine;
use tcp;
use icmp;
use ethernet;
Modified: trunk/libraries/layer/udp.dylan
==============================================================================
--- trunk/libraries/layer/udp.dylan (original)
+++ trunk/libraries/layer/udp.dylan Sun Oct 28 02:48:08 2007
@@ -31,7 +31,10 @@
socket;
end;
-define method send (socket :: <udp-socket>, destination :: <ipv4-address>, payload :: <container-frame>);
+define method send (socket :: <udp-socket>,
+ destination :: <ipv4-address>,
+ payload :: <container-frame>);
+ //push-data-aux(socket.completer.the-input, socket.completer, payload)
end;
define function udp-begin()
More information about the chatter
mailing list