Merge "Introducing the Modification classses"
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / packet / TCP.java
index c7c7f99279d7528d6b5393ead637a02c4295aaf5..d27494599c280418044e4ef78210678562852cc0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,22 +15,24 @@ import java.util.Map;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 /**
  * Class that represents the TCP segment objects
  */
 public class TCP extends Packet {
 
-    private static final String SRCPORT = "SourcePort";
-    private static final String DESTPORT = "DestinationPort";
-    private static final String SEQNUMBER = "SequenceNumber";
-    private static final String ACKNUMBER = "AcknoledgementNumber";
-    private static final String DATAOFFSET = "DataOffset";
-    private static final String RESERVED = "Reserved";
-    private static final String HEADERLENFLAGS = "HeaderLenFlags";
-    private static final String WINDOWSIZE = "WindowSize";
-    private static final String CHECKSUM = "Checksum";
-    private static final String URGENTPOINTER = "UrgentPointer";
+    public static final String SRCPORT = "SourcePort";
+    public static final String DESTPORT = "DestinationPort";
+    public static final String SEQNUMBER = "SequenceNumber";
+    public static final String ACKNUMBER = "AcknowledgementNumber";
+    public static final String DATAOFFSET = "DataOffset";
+    public static final String RESERVED = "Reserved";
+    public static final String HEADERLENFLAGS = "HeaderLenFlags";
+    public static final String WINDOWSIZE = "WindowSize";
+    public static final String CHECKSUM = "Checksum";
+    public static final String URGENTPOINTER = "UrgentPointer";
 
     private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
         private static final long serialVersionUID = 1L;
@@ -230,4 +232,17 @@ public class TCP extends Packet {
         return (BitBufferHelper.getShort(fieldValues.get(DESTPORT)));
     }
 
+    /**
+     * Get the stored checksum value of the TCP header
+     * @return short - the checksum
+     */
+    public short getChecksum() {
+        return (BitBufferHelper.getShort(fieldValues.get(CHECKSUM)));
+    }
+
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.TP_SRC, this.getSourcePort());
+        match.setField(MatchType.TP_DST, this.getDestinationPort());
+    }
 }