0c9a899584088678dd29ebfbac6e84fa666ee261
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / IcmpPacket.java
1 // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2 package edu.uci.iotproject;
3
4 import io.kaitai.struct.ByteBufferKaitaiStream;
5 import io.kaitai.struct.KaitaiStruct;
6 import io.kaitai.struct.KaitaiStream;
7 import java.io.IOException;
8 import java.util.Map;
9 import java.util.HashMap;
10
11 public class IcmpPacket extends KaitaiStruct {
12     public static IcmpPacket fromFile(String fileName) throws IOException {
13         return new IcmpPacket(new ByteBufferKaitaiStream(fileName));
14     }
15
16     public enum IcmpTypeEnum {
17         ECHO_REPLY(0),
18         DESTINATION_UNREACHABLE(3),
19         SOURCE_QUENCH(4),
20         REDIRECT(5),
21         ECHO(8),
22         TIME_EXCEEDED(11);
23
24         private final long id;
25         IcmpTypeEnum(long id) { this.id = id; }
26         public long id() { return id; }
27         private static final Map<Long, IcmpTypeEnum> byId = new HashMap<Long, IcmpTypeEnum>(6);
28         static {
29             for (IcmpTypeEnum e : IcmpTypeEnum.values())
30                 byId.put(e.id(), e);
31         }
32         public static IcmpTypeEnum byId(long id) { return byId.get(id); }
33     }
34
35     public IcmpPacket(KaitaiStream _io) {
36         this(_io, null, null);
37     }
38
39     public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent) {
40         this(_io, _parent, null);
41     }
42
43     public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent, IcmpPacket _root) {
44         super(_io);
45         this._parent = _parent;
46         this._root = _root == null ? this : _root;
47         _read();
48     }
49     private void _read() {
50         this.icmpType = IcmpTypeEnum.byId(this._io.readU1());
51         if (icmpType() == IcmpTypeEnum.DESTINATION_UNREACHABLE) {
52             this.destinationUnreachable = new DestinationUnreachableMsg(this._io, this, _root);
53         }
54         if (icmpType() == IcmpTypeEnum.TIME_EXCEEDED) {
55             this.timeExceeded = new TimeExceededMsg(this._io, this, _root);
56         }
57         if ( ((icmpType() == IcmpTypeEnum.ECHO) || (icmpType() == IcmpTypeEnum.ECHO_REPLY)) ) {
58             this.echo = new EchoMsg(this._io, this, _root);
59         }
60     }
61     public static class DestinationUnreachableMsg extends KaitaiStruct {
62         public static DestinationUnreachableMsg fromFile(String fileName) throws IOException {
63             return new DestinationUnreachableMsg(new ByteBufferKaitaiStream(fileName));
64         }
65
66         public enum DestinationUnreachableCode {
67             NET_UNREACHABLE(0),
68             HOST_UNREACHABLE(1),
69             PROTOCOL_UNREACHABLE(2),
70             PORT_UNREACHABLE(3),
71             FRAGMENTATION_NEEDED_AND_DF_SET(4),
72             SOURCE_ROUTE_FAILED(5),
73             DST_NET_UNKOWN(6),
74             SDT_HOST_UNKOWN(7),
75             SRC_ISOLATED(8),
76             NET_PROHIBITED_BY_ADMIN(9),
77             HOST_PROHIBITED_BY_ADMIN(10),
78             NET_UNREACHABLE_FOR_TOS(11),
79             HOST_UNREACHABLE_FOR_TOS(12),
80             COMMUNICATION_PROHIBITED_BY_ADMIN(13),
81             HOST_PRECEDENCE_VIOLATION(14),
82             PRECEDENCE_CUTTOFF_IN_EFFECT(15);
83
84             private final long id;
85             DestinationUnreachableCode(long id) { this.id = id; }
86             public long id() { return id; }
87             private static final Map<Long, DestinationUnreachableCode> byId = new HashMap<Long, DestinationUnreachableCode>(16);
88             static {
89                 for (DestinationUnreachableCode e : DestinationUnreachableCode.values())
90                     byId.put(e.id(), e);
91             }
92             public static DestinationUnreachableCode byId(long id) { return byId.get(id); }
93         }
94
95         public DestinationUnreachableMsg(KaitaiStream _io) {
96             this(_io, null, null);
97         }
98
99         public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent) {
100             this(_io, _parent, null);
101         }
102
103         public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
104             super(_io);
105             this._parent = _parent;
106             this._root = _root;
107             _read();
108         }
109         private void _read() {
110             this.code = DestinationUnreachableCode.byId(this._io.readU1());
111             this.checksum = this._io.readU2be();
112         }
113         private DestinationUnreachableCode code;
114         private int checksum;
115         private IcmpPacket _root;
116         private IcmpPacket _parent;
117         public DestinationUnreachableCode code() { return code; }
118         public int checksum() { return checksum; }
119         public IcmpPacket _root() { return _root; }
120         public IcmpPacket _parent() { return _parent; }
121     }
122     public static class TimeExceededMsg extends KaitaiStruct {
123         public static TimeExceededMsg fromFile(String fileName) throws IOException {
124             return new TimeExceededMsg(new ByteBufferKaitaiStream(fileName));
125         }
126
127         public enum TimeExceededCode {
128             TIME_TO_LIVE_EXCEEDED_IN_TRANSIT(0),
129             FRAGMENT_REASSEMBLY_TIME_EXCEEDED(1);
130
131             private final long id;
132             TimeExceededCode(long id) { this.id = id; }
133             public long id() { return id; }
134             private static final Map<Long, TimeExceededCode> byId = new HashMap<Long, TimeExceededCode>(2);
135             static {
136                 for (TimeExceededCode e : TimeExceededCode.values())
137                     byId.put(e.id(), e);
138             }
139             public static TimeExceededCode byId(long id) { return byId.get(id); }
140         }
141
142         public TimeExceededMsg(KaitaiStream _io) {
143             this(_io, null, null);
144         }
145
146         public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent) {
147             this(_io, _parent, null);
148         }
149
150         public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
151             super(_io);
152             this._parent = _parent;
153             this._root = _root;
154             _read();
155         }
156         private void _read() {
157             this.code = TimeExceededCode.byId(this._io.readU1());
158             this.checksum = this._io.readU2be();
159         }
160         private TimeExceededCode code;
161         private int checksum;
162         private IcmpPacket _root;
163         private IcmpPacket _parent;
164         public TimeExceededCode code() { return code; }
165         public int checksum() { return checksum; }
166         public IcmpPacket _root() { return _root; }
167         public IcmpPacket _parent() { return _parent; }
168     }
169     public static class EchoMsg extends KaitaiStruct {
170         public static EchoMsg fromFile(String fileName) throws IOException {
171             return new EchoMsg(new ByteBufferKaitaiStream(fileName));
172         }
173
174         public EchoMsg(KaitaiStream _io) {
175             this(_io, null, null);
176         }
177
178         public EchoMsg(KaitaiStream _io, IcmpPacket _parent) {
179             this(_io, _parent, null);
180         }
181
182         public EchoMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
183             super(_io);
184             this._parent = _parent;
185             this._root = _root;
186             _read();
187         }
188         private void _read() {
189             this.code = this._io.ensureFixedContents(new byte[] { 0 });
190             this.checksum = this._io.readU2be();
191             this.identifier = this._io.readU2be();
192             this.seqNum = this._io.readU2be();
193             this.data = this._io.readBytesFull();
194         }
195         private byte[] code;
196         private int checksum;
197         private int identifier;
198         private int seqNum;
199         private byte[] data;
200         private IcmpPacket _root;
201         private IcmpPacket _parent;
202         public byte[] code() { return code; }
203         public int checksum() { return checksum; }
204         public int identifier() { return identifier; }
205         public int seqNum() { return seqNum; }
206         public byte[] data() { return data; }
207         public IcmpPacket _root() { return _root; }
208         public IcmpPacket _parent() { return _parent; }
209     }
210     private IcmpTypeEnum icmpType;
211     private DestinationUnreachableMsg destinationUnreachable;
212     private TimeExceededMsg timeExceeded;
213     private EchoMsg echo;
214     private IcmpPacket _root;
215     private KaitaiStruct _parent;
216     public IcmpTypeEnum icmpType() { return icmpType; }
217     public DestinationUnreachableMsg destinationUnreachable() { return destinationUnreachable; }
218     public TimeExceededMsg timeExceeded() { return timeExceeded; }
219     public EchoMsg echo() { return echo; }
220     public IcmpPacket _root() { return _root; }
221     public KaitaiStruct _parent() { return _parent; }
222 }