2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.statistics.manager;
10 import java.net.Inet4Address;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.List;
14 import java.util.concurrent.ConcurrentMap;
16 import org.opendaylight.controller.md.statistics.manager.NodeStatisticsAger.FlowEntry;
17 import org.opendaylight.controller.md.statistics.manager.NodeStatisticsAger.QueueEntry;
18 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsDataBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.aggregate.flow.statistics.AggregateFlowStatisticsBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterConfigStatsBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
110 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
111 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
112 import org.slf4j.Logger;
113 import org.slf4j.LoggerFactory;
116 * Class implement statistics manager related listener interface and augment all the
117 * received statistics data to data stores.
118 * TODO: Need to add error message listener and clean-up the associated tx id
119 * if it exists in the tx-id cache.
120 * @author vishnoianil
123 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
124 OpendaylightMeterStatisticsListener,
125 OpendaylightFlowStatisticsListener,
126 OpendaylightPortStatisticsListener,
127 OpendaylightFlowTableStatisticsListener,
128 OpendaylightQueueStatisticsListener{
130 private final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
132 private final StatisticsProvider statisticsManager;
133 private final MultipartMessageManager messageManager;
135 private int unaccountedFlowsCounter = 1;
141 public StatisticsUpdateCommiter(final StatisticsProvider manager){
143 this.statisticsManager = manager;
144 this.messageManager = this.statisticsManager.getMultipartMessageManager();
147 public StatisticsProvider getStatisticsManager(){
148 return statisticsManager;
152 public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
153 //Check if response is for the request statistics-manager sent.
154 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
157 NodeKey key = new NodeKey(notification.getId());
159 //Add statistics to local cache
160 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
161 if(!cache.containsKey(notification.getId())){
162 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
164 cache.get(notification.getId()).updateMeterConfigStats(notification.getMeterConfigStats());
166 //Publish data to configuration data store
167 List<MeterConfigStats> meterConfigStatsList = notification.getMeterConfigStats();
168 DataModificationTransaction it = this.statisticsManager.startChange();
170 for(MeterConfigStats meterConfigStats : meterConfigStatsList){
171 MeterBuilder meterBuilder = new MeterBuilder();
172 MeterKey meterKey = new MeterKey(meterConfigStats.getMeterId());
173 meterBuilder.setKey(meterKey);
175 InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
176 .augmentation(FlowCapableNode.class)
177 .child(Meter.class,meterKey).toInstance();
179 NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
180 MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
181 stats.fieldsFrom(meterConfigStats);
182 meterConfig.setMeterConfigStats(stats.build());
184 //Update augmented data
185 meterBuilder.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
186 it.putOperationalData(meterRef, meterBuilder.build());
192 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
194 //Check if response is for the request statistics-manager sent.
195 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
198 NodeKey key = new NodeKey(notification.getId());
200 //Publish data to configuration data store
201 List<MeterStats> meterStatsList = notification.getMeterStats();
202 DataModificationTransaction it = this.statisticsManager.startChange();
204 for(MeterStats meterStats : meterStatsList){
206 MeterBuilder meterBuilder = new MeterBuilder();
207 MeterKey meterKey = new MeterKey(meterStats.getMeterId());
208 meterBuilder.setKey(meterKey);
210 InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
211 .augmentation(FlowCapableNode.class)
212 .child(Meter.class,meterKey).toInstance();
214 NodeMeterStatisticsBuilder meterStatsBuilder= new NodeMeterStatisticsBuilder();
215 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
216 stats.fieldsFrom(meterStats);
217 meterStatsBuilder.setMeterStatistics(stats.build());
219 //Update augmented data
220 meterBuilder.addAugmentation(NodeMeterStatistics.class, meterStatsBuilder.build());
221 it.putOperationalData(meterRef, meterBuilder.build());
227 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
229 //Check if response is for the request statistics-manager sent.
230 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
233 NodeKey key = new NodeKey(notification.getId());
235 //Add statistics to local cache
236 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
237 if(!cache.containsKey(notification.getId())){
238 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
240 cache.get(notification.getId()).updateGroupDescStats(notification.getGroupDescStats());
242 //Publish data to configuration data store
243 List<GroupDescStats> groupDescStatsList = notification.getGroupDescStats();
244 DataModificationTransaction it = this.statisticsManager.startChange();
246 for(GroupDescStats groupDescStats : groupDescStatsList){
248 GroupBuilder groupBuilder = new GroupBuilder();
249 GroupKey groupKey = new GroupKey(groupDescStats.getGroupId());
250 groupBuilder.setKey(groupKey);
252 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
253 .augmentation(FlowCapableNode.class)
254 .child(Group.class,groupKey).toInstance();
256 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
257 GroupDescBuilder stats = new GroupDescBuilder();
258 stats.fieldsFrom(groupDescStats);
259 groupDesc.setGroupDesc(stats.build());
261 //Update augmented data
262 groupBuilder.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
264 it.putOperationalData(groupRef, groupBuilder.build());
270 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
272 //Check if response is for the request statistics-manager sent.
273 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
276 //Publish data to configuration data store
277 NodeKey key = new NodeKey(notification.getId());
278 List<GroupStats> groupStatsList = notification.getGroupStats();
279 DataModificationTransaction it = this.statisticsManager.startChange();
281 for(GroupStats groupStats : groupStatsList){
283 GroupBuilder groupBuilder = new GroupBuilder();
284 GroupKey groupKey = new GroupKey(groupStats.getGroupId());
285 groupBuilder.setKey(groupKey);
287 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
288 .augmentation(FlowCapableNode.class)
289 .child(Group.class,groupKey).toInstance();
291 NodeGroupStatisticsBuilder groupStatisticsBuilder= new NodeGroupStatisticsBuilder();
292 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
293 stats.fieldsFrom(groupStats);
294 groupStatisticsBuilder.setGroupStatistics(stats.build());
296 //Update augmented data
297 groupBuilder.addAugmentation(NodeGroupStatistics.class, groupStatisticsBuilder.build());
298 it.putOperationalData(groupRef, groupBuilder.build());
304 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
306 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
307 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
308 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
309 meterFeature.setMaxBands(notification.getMaxBands());
310 meterFeature.setMaxColor(notification.getMaxColor());
311 meterFeature.setMaxMeter(notification.getMaxMeter());
313 //Publish data to configuration data store
314 DataModificationTransaction it = this.statisticsManager.startChange();
315 NodeKey key = new NodeKey(notification.getId());
316 NodeRef ref = getNodeRef(key);
318 final NodeBuilder nodeData = new NodeBuilder();
319 nodeData.setKey(key);
321 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
322 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
324 //Update augmented data
325 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
327 InstanceIdentifier<? extends Object> refValue = ref.getValue();
328 it.putOperationalData(refValue, nodeData.build());
333 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
335 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
336 groupFeatures.setActions(notification.getActions());
337 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
338 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
339 groupFeatures.setMaxGroups(notification.getMaxGroups());
341 //Publish data to configuration data store
342 DataModificationTransaction it = this.statisticsManager.startChange();
343 NodeKey key = new NodeKey(notification.getId());
344 NodeRef ref = getNodeRef(key);
346 final NodeBuilder nodeData = new NodeBuilder();
347 nodeData.setKey(key);
349 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
350 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
352 //Update augmented data
353 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
355 InstanceIdentifier<? extends Object> refValue = ref.getValue();
356 it.putOperationalData(refValue, nodeData.build());
361 public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
363 //Check if response is for the request statistics-manager sent.
364 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
367 NodeKey key = new NodeKey(notification.getId());
368 sucLogger.debug("Received flow stats update : {}",notification.toString());
369 DataModificationTransaction it = this.statisticsManager.startChange();
371 for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
372 short tableId = map.getTableId();
375 boolean foundOriginalFlow = false;
377 FlowBuilder flowBuilder = new FlowBuilder();
379 FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
381 FlowBuilder flow = new FlowBuilder();
382 flow.setContainerName(map.getContainerName());
383 flow.setBufferId(map.getBufferId());
384 flow.setCookie(map.getCookie());
385 flow.setCookieMask(map.getCookieMask());
386 flow.setFlags(map.getFlags());
387 flow.setFlowName(map.getFlowName());
388 flow.setHardTimeout(map.getHardTimeout());
389 if(map.getFlowId() != null)
390 flow.setId(new FlowId(map.getFlowId().getValue()));
391 flow.setIdleTimeout(map.getIdleTimeout());
392 flow.setInstallHw(map.isInstallHw());
393 flow.setInstructions(map.getInstructions());
394 if(map.getFlowId()!= null)
395 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
396 flow.setMatch(map.getMatch());
397 flow.setOutGroup(map.getOutGroup());
398 flow.setOutPort(map.getOutPort());
399 flow.setPriority(map.getPriority());
400 flow.setStrict(map.isStrict());
401 flow.setTableId(tableId);
403 Flow flowRule = flow.build();
405 FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
406 stats.setByteCount(map.getByteCount());
407 stats.setPacketCount(map.getPacketCount());
408 stats.setDuration(map.getDuration());
410 GenericStatistics flowStats = stats.build();
412 //Add statistics to local cache
413 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
414 if(!cache.containsKey(notification.getId())){
415 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
417 NodeStatisticsAger nsa = cache.get(notification.getId());
419 //Augment the data to the flow node
421 FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
422 flowStatistics.setByteCount(flowStats.getByteCount());
423 flowStatistics.setPacketCount(flowStats.getPacketCount());
424 flowStatistics.setDuration(flowStats.getDuration());
425 flowStatistics.setContainerName(map.getContainerName());
426 flowStatistics.setBufferId(map.getBufferId());
427 flowStatistics.setCookie(map.getCookie());
428 flowStatistics.setCookieMask(map.getCookieMask());
429 flowStatistics.setFlags(map.getFlags());
430 flowStatistics.setFlowName(map.getFlowName());
431 flowStatistics.setHardTimeout(map.getHardTimeout());
432 flowStatistics.setIdleTimeout(map.getIdleTimeout());
433 flowStatistics.setInstallHw(map.isInstallHw());
434 flowStatistics.setInstructions(map.getInstructions());
435 flowStatistics.setMatch(map.getMatch());
436 flowStatistics.setOutGroup(map.getOutGroup());
437 flowStatistics.setOutPort(map.getOutPort());
438 flowStatistics.setPriority(map.getPriority());
439 flowStatistics.setStrict(map.isStrict());
440 flowStatistics.setTableId(tableId);
442 flowStatisticsData.setFlowStatistics(flowStatistics.build());
444 sucLogger.debug("Flow : {}",flowRule.toString());
445 sucLogger.debug("Statistics to augment : {}",flowStatistics.build().toString());
447 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
448 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
450 Table table= (Table)it.readConfigurationData(tableRef);
452 //TODO: Not a good way to do it, need to figure out better way.
453 //TODO: major issue in any alternate approach is that flow key is incrementally assigned
454 //to the flows stored in data store.
455 // Augment same statistics to all the matching masked flow
458 for(Flow existingFlow : table.getFlow()){
459 sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
460 if(flowEquals(flowRule,existingFlow)){
461 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
462 .augmentation(FlowCapableNode.class)
463 .child(Table.class, new TableKey(tableId))
464 .child(Flow.class,existingFlow.getKey()).toInstance();
465 flowBuilder.setKey(existingFlow.getKey());
466 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
467 sucLogger.debug("Found matching flow in the datastore, augmenting statistics");
468 foundOriginalFlow = true;
469 // Update entry with timestamp of latest response
470 flow.setKey(existingFlow.getKey());
471 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
472 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
474 it.putOperationalData(flowRef, flowBuilder.build());
479 table= (Table)it.readOperationalData(tableRef);
480 if(!foundOriginalFlow && table != null){
482 for(Flow existingFlow : table.getFlow()){
483 FlowStatisticsData augmentedflowStatisticsData = existingFlow.getAugmentation(FlowStatisticsData.class);
484 if(augmentedflowStatisticsData != null){
485 FlowBuilder existingOperationalFlow = new FlowBuilder();
486 existingOperationalFlow.fieldsFrom(augmentedflowStatisticsData.getFlowStatistics());
487 sucLogger.debug("Existing unaccounted flow in operational data store : {}",existingFlow.toString());
488 if(flowEquals(flowRule,existingOperationalFlow.build())){
489 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
490 .augmentation(FlowCapableNode.class)
491 .child(Table.class, new TableKey(tableId))
492 .child(Flow.class,existingFlow.getKey()).toInstance();
493 flowBuilder.setKey(existingFlow.getKey());
494 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
495 sucLogger.debug("Found matching unaccounted flow in the operational datastore, augmenting statistics");
496 foundOriginalFlow = true;
498 // Update entry with timestamp of latest response
499 flow.setKey(existingFlow.getKey());
500 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
501 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
503 it.putOperationalData(flowRef, flowBuilder.build());
509 if(!foundOriginalFlow){
510 String flowKey = "#UF$TABLE*"+Short.toString(tableId)+"*"+Integer.toString(this.unaccountedFlowsCounter);
511 this.unaccountedFlowsCounter++;
512 FlowKey newFlowKey = new FlowKey(new FlowId(flowKey));
513 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
514 .augmentation(FlowCapableNode.class)
515 .child(Table.class, new TableKey(tableId))
516 .child(Flow.class,newFlowKey).toInstance();
517 flowBuilder.setKey(newFlowKey);
518 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
519 sucLogger.debug("Flow {} is not present in config data store, augmenting statistics as an unaccounted flow",flowBuilder.build());
521 // Update entry with timestamp of latest response
522 flow.setKey(newFlowKey);
523 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
524 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
526 it.putOperationalData(flowRef, flowBuilder.build());
533 public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
534 //Check if response is for the request statistics-manager sent.
535 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
538 NodeKey key = new NodeKey(notification.getId());
540 Short tableId = messageManager.getTableIdForTxId(notification.getId(),notification.getTransactionId());
543 DataModificationTransaction it = this.statisticsManager.startChange();
545 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
546 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
548 AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
549 AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
550 aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
551 aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
552 aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
553 aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
555 sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
557 TableBuilder tableBuilder = new TableBuilder();
558 tableBuilder.setKey(new TableKey(tableId));
559 tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
560 it.putOperationalData(tableRef, tableBuilder.build());
567 public void onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
568 //Check if response is for the request statistics-manager sent.
569 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
572 NodeKey key = new NodeKey(notification.getId());
574 List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
575 DataModificationTransaction it = this.statisticsManager.startChange();
577 for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
579 FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder
580 = new FlowCapableNodeConnectorStatisticsBuilder();
581 statisticsBuilder.setBytes(portStats.getBytes());
582 statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
583 statisticsBuilder.setDuration(portStats.getDuration());
584 statisticsBuilder.setPackets(portStats.getPackets());
585 statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
586 statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
587 statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
588 statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
589 statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
590 statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
591 statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
593 //Augment data to the node-connector
594 FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder =
595 new FlowCapableNodeConnectorStatisticsDataBuilder();
597 statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
599 InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
601 NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
603 if(nodeConnector != null){
604 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
605 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
606 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
607 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
614 public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
615 //Check if response is for the request statistics-manager sent.
616 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
619 NodeKey key = new NodeKey(notification.getId());
621 List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
622 DataModificationTransaction it = this.statisticsManager.startChange();
624 for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
626 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
627 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
629 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
631 FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
632 statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
633 statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
634 statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
636 statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
638 sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
640 TableBuilder tableBuilder = new TableBuilder();
641 tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
642 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
643 it.putOperationalData(tableRef, tableBuilder.build());
649 public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
651 //Check if response is for the request statistics-manager sent.
652 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
655 NodeKey key = new NodeKey(notification.getId());
657 //Add statistics to local cache
658 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
659 if(!cache.containsKey(notification.getId())){
660 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
663 NodeStatisticsAger nsa = cache.get(notification.getId());
665 List<QueueIdAndStatisticsMap> queuesStats = notification.getQueueIdAndStatisticsMap();
666 DataModificationTransaction it = this.statisticsManager.startChange();
668 for(QueueIdAndStatisticsMap swQueueStats : queuesStats){
670 QueueEntry queueEntry = nsa.new QueueEntry(swQueueStats.getNodeConnectorId(),swQueueStats.getQueueId());
671 nsa.updateQueueStats(queueEntry);
673 FlowCapableNodeConnectorQueueStatisticsDataBuilder queueStatisticsDataBuilder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
675 FlowCapableNodeConnectorQueueStatisticsBuilder queueStatisticsBuilder = new FlowCapableNodeConnectorQueueStatisticsBuilder();
677 queueStatisticsBuilder.fieldsFrom(swQueueStats);
679 queueStatisticsDataBuilder.setFlowCapableNodeConnectorQueueStatistics(queueStatisticsBuilder.build());
681 InstanceIdentifier<Queue> queueRef
682 = InstanceIdentifier.builder(Nodes.class)
683 .child(Node.class, key)
684 .child(NodeConnector.class, new NodeConnectorKey(swQueueStats.getNodeConnectorId()))
685 .augmentation(FlowCapableNodeConnector.class)
686 .child(Queue.class, new QueueKey(swQueueStats.getQueueId())).toInstance();
688 QueueBuilder queueBuilder = new QueueBuilder();
689 queueBuilder.addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, queueStatisticsDataBuilder.build());
690 queueBuilder.setKey(new QueueKey(swQueueStats.getQueueId()));
692 sucLogger.debug("Augmenting queue statistics {} of queue {} to port {}"
693 ,queueStatisticsDataBuilder.build().toString(),
694 swQueueStats.getQueueId(),
695 swQueueStats.getNodeConnectorId());
697 it.putOperationalData(queueRef, queueBuilder.build());
702 private static NodeRef getNodeRef(NodeKey nodeKey){
703 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
704 return new NodeRef(builder.toInstance());
707 public static boolean flowEquals(Flow statsFlow, Flow storedFlow) {
708 if (statsFlow.getClass() != storedFlow.getClass()) {
711 if (statsFlow.getContainerName()== null) {
712 if (storedFlow.getContainerName()!= null) {
715 } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
718 if (statsFlow.getMatch()== null) {
719 if (storedFlow.getMatch() != null) {
722 } //else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
723 else if(!matchEquals(statsFlow.getMatch(), storedFlow.getMatch())) {
726 if (storedFlow.getPriority() == null) {
727 if (statsFlow.getPriority() != null && statsFlow.getPriority()!= 0x8000) {
730 } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
733 if (statsFlow.getTableId() == null) {
734 if (storedFlow.getTableId() != null) {
737 } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {
744 * Explicit equals method to compare the 'match' for flows stored in the data-stores and flow fetched from the switch.
745 * Flow installation process has three steps
746 * 1) Store flow in config data store
747 * 2) and send it to plugin for installation
748 * 3) Flow gets installed in switch
750 * The flow user wants to install and what finally gets installed in switch can be slightly different.
751 * E.g, If user installs flow with src/dst ip=10.0.0.1/24, when it get installed in the switch
752 * src/dst ip will be changes to 10.0.0.0/24 because of netmask of 24. When statistics manager fetch
753 * stats it gets 10.0.0.0/24 rather then 10.0.0.1/24. Custom match takes care of by using masked ip
754 * while comparing two ip addresses.
756 * Sometimes when user don't provide few values that is required by flow installation request, like
757 * priority,hard timeout, idle timeout, cookies etc, plugin usages default values before sending
758 * request to the switch. So when statistics manager gets flow statistics, it gets the default value.
759 * But the flow stored in config data store don't have those defaults value. I included those checks
760 * in the customer flow/match equal function.
768 public static boolean matchEquals(Match statsFlow, Match storedFlow) {
769 if (statsFlow == storedFlow) {
772 if (storedFlow.getClass() != statsFlow.getClass()) {
775 if (storedFlow.getEthernetMatch() == null) {
776 if (statsFlow.getEthernetMatch() != null) {
779 } else if(!storedFlow.getEthernetMatch().equals(statsFlow.getEthernetMatch())) {
782 if (storedFlow.getIcmpv4Match()== null) {
783 if (statsFlow.getIcmpv4Match() != null) {
786 } else if(!storedFlow.getIcmpv4Match().equals(statsFlow.getIcmpv4Match())) {
789 if (storedFlow.getIcmpv6Match() == null) {
790 if (statsFlow.getIcmpv6Match() != null) {
793 } else if(!storedFlow.getIcmpv6Match().equals(statsFlow.getIcmpv6Match())) {
796 if (storedFlow.getInPhyPort() == null) {
797 if (statsFlow.getInPhyPort() != null) {
800 } else if(!storedFlow.getInPhyPort().equals(statsFlow.getInPhyPort())) {
803 if (storedFlow.getInPort()== null) {
804 if (statsFlow.getInPort() != null) {
807 } else if(!storedFlow.getInPort().equals(statsFlow.getInPort())) {
810 if (storedFlow.getIpMatch()== null) {
811 if (statsFlow.getIpMatch() != null) {
814 } else if(!storedFlow.getIpMatch().equals(statsFlow.getIpMatch())) {
817 if (storedFlow.getLayer3Match()== null) {
818 if (statsFlow.getLayer3Match() != null) {
821 } else if(!layer3MatchEquals(statsFlow.getLayer3Match(),storedFlow.getLayer3Match())) {
824 if (storedFlow.getLayer4Match()== null) {
825 if (statsFlow.getLayer4Match() != null) {
828 } else if(!storedFlow.getLayer4Match().equals(statsFlow.getLayer4Match())) {
831 if (storedFlow.getMetadata() == null) {
832 if (statsFlow.getMetadata() != null) {
835 } else if(!storedFlow.getMetadata().equals(statsFlow.getMetadata())) {
838 if (storedFlow.getProtocolMatchFields() == null) {
839 if (statsFlow.getProtocolMatchFields() != null) {
842 } else if(!storedFlow.getProtocolMatchFields().equals(statsFlow.getProtocolMatchFields())) {
845 if (storedFlow.getTunnel()== null) {
846 if (statsFlow.getTunnel() != null) {
849 } else if(!storedFlow.getTunnel().equals(statsFlow.getTunnel())) {
852 if (storedFlow.getVlanMatch()== null) {
853 if (statsFlow.getVlanMatch() != null) {
856 } else if(!storedFlow.getVlanMatch().equals(statsFlow.getVlanMatch())) {
862 protected static boolean layer3MatchEquals(Layer3Match statsLayer3Match, Layer3Match storedLayer3Match){
863 boolean verdict = true;
864 if(statsLayer3Match instanceof Ipv4Match && storedLayer3Match instanceof Ipv4Match){
865 Ipv4Match statsIpv4Match = (Ipv4Match)statsLayer3Match;
866 Ipv4Match storedIpv4Match = (Ipv4Match)storedLayer3Match;
869 verdict = compareNullSafe(
870 storedIpv4Match.getIpv4Destination(), statsIpv4Match.getIpv4Destination());
873 verdict = compareNullSafe(
874 statsIpv4Match.getIpv4Source(), storedIpv4Match.getIpv4Source());
877 Boolean nullCheckOut = checkNullValues(storedLayer3Match, statsLayer3Match);
878 if (nullCheckOut != null) {
879 verdict = nullCheckOut;
881 verdict = storedLayer3Match.equals(statsLayer3Match);
888 private static boolean compareNullSafe(Ipv4Prefix statsIpv4, Ipv4Prefix storedIpv4) {
889 boolean verdict = true;
890 Boolean checkDestNullValuesOut = checkNullValues(storedIpv4, statsIpv4);
891 if (checkDestNullValuesOut != null) {
892 verdict = checkDestNullValuesOut;
893 } else if(!IpAddressEquals(statsIpv4, storedIpv4)){
900 private static Boolean checkNullValues(Object v1, Object v2) {
901 Boolean verdict = null;
902 if (v1 == null && v2 != null) {
903 verdict = Boolean.FALSE;
904 } else if (v1 != null && v2 == null) {
905 verdict = Boolean.FALSE;
906 } else if (v1 == null && v2 == null) {
907 verdict = Boolean.TRUE;
914 * TODO: why don't we use the default Ipv4Prefix.equals()?
916 * @param statsIpAddress
917 * @param storedIpAddress
918 * @return true if IPv4prefixes equals
920 private static boolean IpAddressEquals(Ipv4Prefix statsIpAddress, Ipv4Prefix storedIpAddress) {
921 IntegerIpAddress statsIpAddressInt = StrIpToIntIp(statsIpAddress.getValue());
922 IntegerIpAddress storedIpAddressInt = StrIpToIntIp(storedIpAddress.getValue());
924 if(IpAndMaskBasedMatch(statsIpAddressInt,storedIpAddressInt)){
927 if(IpBasedMatch(statsIpAddressInt,storedIpAddressInt)){
933 private static boolean IpAndMaskBasedMatch(IntegerIpAddress statsIpAddressInt,IntegerIpAddress storedIpAddressInt){
934 return ((statsIpAddressInt.getIp() & statsIpAddressInt.getMask()) == (storedIpAddressInt.getIp() & storedIpAddressInt.getMask()));
937 private static boolean IpBasedMatch(IntegerIpAddress statsIpAddressInt,IntegerIpAddress storedIpAddressInt){
938 return (statsIpAddressInt.getIp() == storedIpAddressInt.getIp());
942 * Method return integer version of ip address. Converted int will be mask if
945 private static IntegerIpAddress StrIpToIntIp(String ipAddresss){
947 String[] parts = ipAddresss.split("/");
948 String ip = parts[0];
951 if (parts.length < 2) {
954 prefix = Integer.parseInt(parts[1]);
957 IntegerIpAddress integerIpAddress = null;
959 Inet4Address addr = (Inet4Address) InetAddress.getByName(ip);
960 byte[] addrBytes = addr.getAddress();
961 int ipInt = ((addrBytes[0] & 0xFF) << 24) |
962 ((addrBytes[1] & 0xFF) << 16) |
963 ((addrBytes[2] & 0xFF) << 8) |
964 ((addrBytes[3] & 0xFF) << 0);
966 int mask = 0xffffffff << 32 - prefix;
968 integerIpAddress = new IntegerIpAddress(ipInt, mask);
969 } catch (UnknownHostException e){
970 sucLogger.error("Failed to determine host IP address by name: {}", e.getMessage(), e);
973 return integerIpAddress;
976 static class IntegerIpAddress{
979 public IntegerIpAddress(int ip, int mask) {
986 public int getMask() {