[Gd-chatter] r11635 - in trunk/libraries: layer packetizer protocols

hannes at gwydiondylan.org hannes at gwydiondylan.org
Fri Jan 18 04:51:52 CET 2008


Author: hannes
Date: Fri Jan 18 04:51:51 2008
New Revision: 11635

Modified:
   trunk/libraries/layer/dhcp.dylan
   trunk/libraries/packetizer/protocol-definer-macro.dylan
   trunk/libraries/protocols/dhcp.dylan
   trunk/libraries/protocols/ipv4.dylan
Log:
Job: 7299
make usage of enum fields


Modified: trunk/libraries/layer/dhcp.dylan
==============================================================================
--- trunk/libraries/layer/dhcp.dylan	(original)
+++ trunk/libraries/layer/dhcp.dylan	Fri Jan 18 04:51:51 2008
@@ -10,8 +10,8 @@
                              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)
+    if (frame.operation == #"boot-reply")
+      if (message-type-frame.message-type == #"dhcpoffer")
         node.offer := frame;
         process-event(node, #"receive-offer");
         process-event(node, #"send-request");
@@ -20,12 +20,12 @@
   end;
   if (instance?(node.state, type-union(<requesting>, <rebinding>,
                                        <renewing>, <rebooting>)))
-    if (frame.operation = 2)
-      if (message-type-frame.message-type = 5) //ack
+    if (frame.operation == #"boot-reply")
+      if (message-type-frame.message-type == #"dhcpack")
         process-event(node, #"receive-ack");
         node.received-response-callback(frame);
         //format-out("received ack %s\n", as(<string>, frame));
-      elseif (message-type-frame.message-type = 6) //nak
+      elseif (message-type-frame.message-type == #"dhcpnak")
         process-event(node, #"receive-nak")
       end
     end
@@ -49,7 +49,7 @@
                     transaction-id: state.xid,
                     client-hardware-address: $hardware-address,
                     dhcp-options: list(make(<dhcp-message-type-option>,
-                                            message-type: 1)));
+                                            message-type: #"dhcpdiscover")));
   send(state.send-socket, $broadcast-address, packet);
 end;
 
@@ -70,17 +70,18 @@
                                 new-state :: <requesting>) => ()
 //  if (matches-requirements?(state.offer))
   let server-option = find-option(state.offer, <dhcp-server-identifier-option>);
+  let options = list(make(<dhcp-message-type-option>,
+                          message-type: #"dhcprequest"),
+                     make(<dhcp-requested-ip-address-option>,
+                          requested-ip: state.offer.your-ip-address),
+                     make(<dhcp-server-identifier-option>,
+                          selected-server: server-option.selected-server));
   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: state.offer.your-ip-address),
-                                       make(<dhcp-server-identifier-option>,
-                                            selected-server: server-option.selected-server)));
+                    dhcp-options: options);
   send(state.send-socket, $broadcast-address, packet);
-//
+//  end
 end;
 
 

Modified: trunk/libraries/packetizer/protocol-definer-macro.dylan
==============================================================================
--- trunk/libraries/packetizer/protocol-definer-macro.dylan	(original)
+++ trunk/libraries/packetizer/protocol-definer-macro.dylan	Fri Jan 18 04:51:51 2008
@@ -44,8 +44,9 @@
               end;
             end;
           end;
-            
-      key/value-pairs[pos] := enum-field-symbol-to-int(ele, key);
+      if (key & instance?(key, <symbol>))
+        key/value-pairs[pos] := enum-field-symbol-to-int(ele, key);
+      end;
     end;
   end;
 end;

Modified: trunk/libraries/protocols/dhcp.dylan
==============================================================================
--- trunk/libraries/protocols/dhcp.dylan	(original)
+++ trunk/libraries/protocols/dhcp.dylan	Fri Jan 18 04:51:51 2008
@@ -5,7 +5,9 @@
 //from rfc2131
 define protocol dhcp-message (container-frame)
   over <udp-frame> 67;
-  field operation :: <unsigned-byte> = 1;
+  enum field operation :: <unsigned-byte> = 1,
+    mappings: { 1 <=> #"bootrequest",
+                2 <=> #"bootreply" };
   field hardware-address-type :: <unsigned-byte> = 1;
   field hardware-address-length :: <unsigned-byte> = 6;
   field hops :: <unsigned-byte> = 0;
@@ -53,6 +55,7 @@
 
 define protocol dhcp-subnet-mask (dhcp-option-with-data)
   over <dhcp-option> 1;
+  summary "%=", subnet-mask;
   field subnet-mask :: <ipv4-address>;
 end;
 
@@ -282,8 +285,11 @@
 
 define protocol dhcp-netbios-node-type-option (dhcp-option-with-data)
   over <dhcp-option> 46;
-  field node-type :: <unsigned-byte>;
-//0x1 -> b-node; 0x2 -> p-node; 0x4 -> m-node; 0x8 -> h-node
+  enum field node-type :: <unsigned-byte>,
+    mappings: { #x1 <=> #"b-node",
+                #x2 <=> #"p-node",
+                #x4 <=> #"m-node",
+                #x8 <=> #"h-node" };
 end;
 
 define protocol dhcp-netbios-scope-option (dhcp-option-with-data)
@@ -362,6 +368,7 @@
 
 define protocol dhcp-tftp-server-name-option (dhcp-option-with-data)
   over <dhcp-option> 66;
+  summary "%=", tftp-server-name;
   field tftp-server-name :: <externally-delimited-string>;
 end;
 
@@ -372,19 +379,21 @@
 
 define protocol dhcp-message-type-option (dhcp-option-with-data)
   over <dhcp-option> 53;
-  field message-type :: <unsigned-byte>;
-//    1     DHCPDISCOVER
-//    2     DHCPOFFER
-//    3     DHCPREQUEST
-//    4     DHCPDECLINE
-//    5     DHCPACK
-//    6     DHCPNAK
-//    7     DHCPRELEASE
-//    8     DHCPINFORM
+  summary "%=", message-type;
+  enum field message-type :: <unsigned-byte>,
+    mappings: { 1 <=> #"dhcpdiscover",
+                2 <=> #"dhcpoffer",
+                3 <=> #"dhcprequest",
+                4 <=> #"dhcpdecline",
+                5 <=> #"dhcpack",
+                6 <=> #"dhcpnak",
+                7 <=> #"dhcprelease",
+                8 <=> #"dhcpinform" };
 end;
 
 define protocol dhcp-server-identifier-option (dhcp-option-with-data)
   over <dhcp-option> 54;
+  summary "%=", selected-server;
   field selected-server :: <ipv4-address>;
 end;
 

Modified: trunk/libraries/protocols/ipv4.dylan
==============================================================================
--- trunk/libraries/protocols/ipv4.dylan	(original)
+++ trunk/libraries/protocols/ipv4.dylan	Fri Jan 18 04:51:51 2008
@@ -129,9 +129,9 @@
   field mac-address-size :: <unsigned-byte> = byte-offset(field-size(<mac-address>));
   field protocol-address-size :: <unsigned-byte> 
     = byte-offset(field-size(<ipv4-address>));
-  field operation :: <2byte-big-endian-unsigned-integer>;
-//    enum: { #x1 => #"arp-request", "ARP WHO HAS %= TELL %=";
-//            #x2 => #"arp-response", "ARP %= IS AT %="; };
+  enum field operation :: <2byte-big-endian-unsigned-integer>,
+    mappings: { #x1 <=> #"arp-request",
+                #x2 <=> #"arp-response" };
   field source-mac-address :: <mac-address>;
   field source-ip-address :: <ipv4-address>;
   field target-mac-address :: <mac-address>;
@@ -139,11 +139,11 @@
 end;
 
 define method summary (frame :: <arp-frame>) => (res :: <string>)
-  if(frame.operation = 1)
+  if(frame.operation = #"arp-request")
     format-to-string("ARP WHO-HAS %= tell %=",
                      frame.target-ip-address,
                      frame.source-ip-address)
-  elseif(frame.operation = 2)
+  elseif(frame.operation = #"arp-response")
     format-to-string("ARP %= IS-AT %=",
                      frame.source-ip-address,
                      frame.source-mac-address)



More information about the chatter mailing list