blob: 8be75d4409e6641d541aef9faa8327ad395edf42 [file] [log] [blame]
Rusty Eddy1da61a22015-09-01 00:48:58 +00001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.packet;
17
18import java.nio.ByteBuffer;
19import java.util.ArrayList;
20import java.util.List;
21
22/**
23 * A class to represent Groups for membership query and reports.
24 */
25public abstract class IGMPGroup {
26
27 protected int auxInfo;
28 protected IpAddress gaddr;
29 protected List<IpAddress> sources = new ArrayList<>();
30
31 public IGMPGroup() {
32 }
33
34 /**
35 * Initialize this object with a multicast group address and additional info.
36 *
37 * @param gaddr: the multicast group address for this message type.
38 * @param auxInfo: additional info potentially used by IGMPQuery
39 */
40 public IGMPGroup(IpAddress gaddr, int auxInfo) {
41 this.gaddr = gaddr;
42 this.auxInfo = auxInfo;
43 }
44
45 /**
46 * Get the multicast group address.
47 *
48 * @return the group address
49 */
50 public IpAddress getGaddr() {
51 return this.gaddr;
52 }
53
54 /**
55 * Get the auxillary info.
56 *
57 * @return the auxillary info
58 */
59 public int getAuxInfo() {
60 return this.auxInfo;
61 }
62
63 /**
64 * Add a unicast source address to this message.
65 *
66 * @param saddr IPv4 unicast source address
67 */
68 public void addSource(IpAddress saddr) {
69 sources.add(saddr);
70 }
71
72 /**
73 * Return the list of source addresses.
74 *
75 * @return list of source addresses
76 */
77 public List<IpAddress> getSources() {
78 return sources;
79 }
80
81 /**
82 * Deserialize an IGMPQuery or IGMPMembership message.
83 *
84 * @param bb the ByteBuffer wrapping the serialized message. The position of the
85 * ByteBuffer should be pointing at the head of either message type.
86 * @return An object populated with the respective IGMPGroup subclass
87 * @throws DeserializationException in case deserialization goes wrong
88 */
89 public abstract IGMPGroup deserialize(ByteBuffer bb) throws DeserializationException;
90
91 /**
92 * Serialize the IGMPGroup subclass.
93 *
94 * @param bb the ByteBuffer to write into, positioned at the next spot to be written to.
95 * @return The serialized message
96 */
97 public abstract byte[] serialize(ByteBuffer bb);
Jian Li5fc14292015-12-04 11:30:46 -080098
99 @Override
100 public String toString() {
101 StringBuilder sb = new StringBuilder();
102 sb.append("[");
103 sb.append("auxInfo= ");
104 sb.append(auxInfo);
105 sb.append("gaddr= ");
106 sb.append(gaddr);
107 sb.append("sources= ");
108 sb.append(sources.toString());
109 sb.append("]");
110 return sb.toString();
111 }
Rusty Eddy1da61a22015-09-01 00:48:58 +0000112}