Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
floodlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
croft1
floodlight
Commits
fb5f2553
Commit
fb5f2553
authored
9 years ago
by
Jacob Chappell
Browse files
Options
Downloads
Patches
Plain Diff
Add SPUD BasePacket class.
parent
cab1487c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/net/floodlightcontroller/packet/SPUD.java
+150
-0
150 additions, 0 deletions
src/main/java/net/floodlightcontroller/packet/SPUD.java
with
150 additions
and
0 deletions
src/main/java/net/floodlightcontroller/packet/SPUD.java
0 → 100644
+
150
−
0
View file @
fb5f2553
package
net.floodlightcontroller.packet
;
import
java.nio.ByteBuffer
;
/**
* @author Jacob Chappell (jacob.chappell@uky.edu)
*/
public
class
SPUD
extends
BasePacket
{
public
static
final
int
MAGIC_CONSTANT
=
0xd80000d8
;
public
static
final
int
HEADER_LENGTH
=
13
;
public
static
final
byte
COMMAND_DATA
=
0x0
;
public
static
final
byte
COMMAND_OPEN
=
0x1
;
public
static
final
byte
COMMAND_CLOSE
=
0x2
;
public
static
final
byte
COMMAND_ACK
=
0x3
;
protected
long
tubeID
;
protected
byte
command
;
protected
boolean
adec
;
protected
boolean
pdec
;
protected
byte
reserved
;
public
long
getTubeID
()
{
return
tubeID
;
}
public
SPUD
setTubeID
(
long
tubeID
)
{
this
.
tubeID
=
tubeID
;
return
this
;
}
public
byte
getCommand
()
{
return
command
;
}
public
SPUD
setCommand
(
byte
command
)
{
this
.
command
=
command
;
return
this
;
}
public
boolean
getADEC
()
{
return
adec
;
}
public
SPUD
setADEC
(
boolean
adec
)
{
this
.
adec
=
adec
;
return
this
;
}
public
boolean
getPDEC
()
{
return
pdec
;
}
public
SPUD
setPDEC
(
boolean
pdec
)
{
this
.
pdec
=
pdec
;
return
this
;
}
public
byte
getReserved
()
{
return
reserved
;
}
public
SPUD
setReserved
(
byte
reserved
)
{
this
.
reserved
=
reserved
;
return
this
;
}
@Override
public
byte
[]
serialize
()
{
byte
[]
payloadData
=
null
;
if
(
payload
!=
null
)
{
payload
.
setParent
(
this
);
payloadData
=
payload
.
serialize
();
}
int
length
=
HEADER_LENGTH
+
((
payloadData
==
null
)
?
0
:
payloadData
.
length
);
byte
[]
data
=
new
byte
[
length
];
ByteBuffer
bb
=
ByteBuffer
.
wrap
(
data
);
bb
.
putInt
(
MAGIC_CONSTANT
);
bb
.
putLong
(
tubeID
);
byte
adecBit
=
(
byte
)
((
adec
)
?
1
:
0
);
byte
pdecBit
=
(
byte
)
((
pdec
)
?
1
:
0
);
byte
lastByte
=
(
byte
)
(((
command
&
0x3
)
<<
6
)
|
((
adecBit
&
0x1
)
<<
5
)
|
((
pdecBit
&
0x1
)
<<
4
)
|
(
reserved
&
0xf
));
bb
.
put
(
lastByte
);
if
(
payloadData
!=
null
)
{
bb
.
put
(
payloadData
);
}
return
data
;
}
@Override
public
IPacket
deserialize
(
byte
[]
data
,
int
offset
,
int
length
)
throws
PacketParsingException
{
ByteBuffer
bb
=
ByteBuffer
.
wrap
(
data
,
offset
,
length
);
int
magicConstant
=
bb
.
getInt
();
if
(
magicConstant
!=
MAGIC_CONSTANT
)
{
throw
new
PacketParsingException
(
"Magic constant is incorrect."
);
}
tubeID
=
bb
.
getLong
();
byte
lastByte
=
bb
.
get
();
command
=
(
byte
)
((
lastByte
&
0xc0
)
>>>
6
);
adec
=
((
lastByte
&
0x20
)
!=
0
);
pdec
=
((
lastByte
&
0x10
)
!=
0
);
reserved
=
(
byte
)
(
lastByte
&
0xF
);
// TODO: make sure reserved bits are 0 for this version.
this
.
payload
=
new
Data
();
this
.
payload
=
payload
.
deserialize
(
data
,
bb
.
position
(),
bb
.
limit
()-
bb
.
position
());
this
.
payload
.
setParent
(
this
);
return
this
;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
super
.
hashCode
();
result
=
prime
*
result
+
(
adec
?
1231
:
1237
);
result
=
prime
*
result
+
command
;
result
=
prime
*
result
+
(
pdec
?
1231
:
1237
);
result
=
prime
*
result
+
reserved
;
result
=
prime
*
result
+
(
int
)
(
tubeID
^
(
tubeID
>>>
32
));
return
result
;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(!
super
.
equals
(
obj
))
return
false
;
if
(!(
obj
instanceof
SPUD
))
return
false
;
SPUD
other
=
(
SPUD
)
obj
;
if
(
adec
!=
other
.
adec
)
return
false
;
if
(
command
!=
other
.
command
)
return
false
;
if
(
pdec
!=
other
.
pdec
)
return
false
;
if
(
reserved
!=
other
.
reserved
)
return
false
;
if
(
tubeID
!=
other
.
tubeID
)
return
false
;
return
true
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment