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();
169 for(MeterConfigStats meterConfigStats : meterConfigStatsList){
170 DataModificationTransaction it = this.statisticsManager.startChange();
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());
193 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
195 //Check if response is for the request statistics-manager sent.
196 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
199 NodeKey key = new NodeKey(notification.getId());
201 List<MeterStats> meterStatsList = notification.getMeterStats();
203 for(MeterStats meterStats : meterStatsList){
205 //Publish data to configuration data store
206 DataModificationTransaction it = this.statisticsManager.startChange();
207 MeterBuilder meterBuilder = new MeterBuilder();
208 MeterKey meterKey = new MeterKey(meterStats.getMeterId());
209 meterBuilder.setKey(meterKey);
211 InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
212 .augmentation(FlowCapableNode.class)
213 .child(Meter.class,meterKey).toInstance();
215 NodeMeterStatisticsBuilder meterStatsBuilder= new NodeMeterStatisticsBuilder();
216 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
217 stats.fieldsFrom(meterStats);
218 meterStatsBuilder.setMeterStatistics(stats.build());
220 //Update augmented data
221 meterBuilder.addAugmentation(NodeMeterStatistics.class, meterStatsBuilder.build());
222 it.putOperationalData(meterRef, meterBuilder.build());
228 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
230 //Check if response is for the request statistics-manager sent.
231 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
234 NodeKey key = new NodeKey(notification.getId());
236 //Add statistics to local cache
237 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
238 if(!cache.containsKey(notification.getId())){
239 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
241 cache.get(notification.getId()).updateGroupDescStats(notification.getGroupDescStats());
243 //Publish data to configuration data store
244 List<GroupDescStats> groupDescStatsList = notification.getGroupDescStats();
246 for(GroupDescStats groupDescStats : groupDescStatsList){
247 DataModificationTransaction it = this.statisticsManager.startChange();
249 GroupBuilder groupBuilder = new GroupBuilder();
250 GroupKey groupKey = new GroupKey(groupDescStats.getGroupId());
251 groupBuilder.setKey(groupKey);
253 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
254 .augmentation(FlowCapableNode.class)
255 .child(Group.class,groupKey).toInstance();
257 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
258 GroupDescBuilder stats = new GroupDescBuilder();
259 stats.fieldsFrom(groupDescStats);
260 groupDesc.setGroupDesc(stats.build());
262 //Update augmented data
263 groupBuilder.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
265 it.putOperationalData(groupRef, groupBuilder.build());
271 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
273 //Check if response is for the request statistics-manager sent.
274 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
277 //Publish data to configuration data store
278 NodeKey key = new NodeKey(notification.getId());
279 List<GroupStats> groupStatsList = notification.getGroupStats();
281 for(GroupStats groupStats : groupStatsList){
282 DataModificationTransaction it = this.statisticsManager.startChange();
284 GroupBuilder groupBuilder = new GroupBuilder();
285 GroupKey groupKey = new GroupKey(groupStats.getGroupId());
286 groupBuilder.setKey(groupKey);
288 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
289 .augmentation(FlowCapableNode.class)
290 .child(Group.class,groupKey).toInstance();
292 NodeGroupStatisticsBuilder groupStatisticsBuilder= new NodeGroupStatisticsBuilder();
293 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
294 stats.fieldsFrom(groupStats);
295 groupStatisticsBuilder.setGroupStatistics(stats.build());
297 //Update augmented data
298 groupBuilder.addAugmentation(NodeGroupStatistics.class, groupStatisticsBuilder.build());
299 it.putOperationalData(groupRef, groupBuilder.build());
305 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
307 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
308 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
309 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
310 meterFeature.setMaxBands(notification.getMaxBands());
311 meterFeature.setMaxColor(notification.getMaxColor());
312 meterFeature.setMaxMeter(notification.getMaxMeter());
314 //Publish data to configuration data store
315 DataModificationTransaction it = this.statisticsManager.startChange();
316 NodeKey key = new NodeKey(notification.getId());
317 NodeRef ref = getNodeRef(key);
319 final NodeBuilder nodeData = new NodeBuilder();
320 nodeData.setKey(key);
322 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
323 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
325 //Update augmented data
326 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
328 InstanceIdentifier<? extends Object> refValue = ref.getValue();
329 it.putOperationalData(refValue, nodeData.build());
334 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
336 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
337 groupFeatures.setActions(notification.getActions());
338 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
339 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
340 groupFeatures.setMaxGroups(notification.getMaxGroups());
342 //Publish data to configuration data store
343 DataModificationTransaction it = this.statisticsManager.startChange();
344 NodeKey key = new NodeKey(notification.getId());
345 NodeRef ref = getNodeRef(key);
347 final NodeBuilder nodeData = new NodeBuilder();
348 nodeData.setKey(key);
350 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
351 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
353 //Update augmented data
354 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
356 InstanceIdentifier<? extends Object> refValue = ref.getValue();
357 it.putOperationalData(refValue, nodeData.build());
362 public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
364 //Check if response is for the request statistics-manager sent.
365 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
368 NodeKey key = new NodeKey(notification.getId());
369 sucLogger.debug("Received flow stats update : {}",notification.toString());
371 for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
372 short tableId = map.getTableId();
374 DataModificationTransaction it = this.statisticsManager.startChange();
376 boolean foundOriginalFlow = false;
378 FlowBuilder flowBuilder = new FlowBuilder();
380 FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
382 FlowBuilder flow = new FlowBuilder();
383 flow.setContainerName(map.getContainerName());
384 flow.setBufferId(map.getBufferId());
385 flow.setCookie(map.getCookie());
386 flow.setCookieMask(map.getCookieMask());
387 flow.setFlags(map.getFlags());
388 flow.setFlowName(map.getFlowName());
389 flow.setHardTimeout(map.getHardTimeout());
390 if(map.getFlowId() != null)
391 flow.setId(new FlowId(map.getFlowId().getValue()));
392 flow.setIdleTimeout(map.getIdleTimeout());
393 flow.setInstallHw(map.isInstallHw());
394 flow.setInstructions(map.getInstructions());
395 if(map.getFlowId()!= null)
396 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
397 flow.setMatch(map.getMatch());
398 flow.setOutGroup(map.getOutGroup());
399 flow.setOutPort(map.getOutPort());
400 flow.setPriority(map.getPriority());
401 flow.setStrict(map.isStrict());
402 flow.setTableId(tableId);
404 Flow flowRule = flow.build();
406 FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
407 stats.setByteCount(map.getByteCount());
408 stats.setPacketCount(map.getPacketCount());
409 stats.setDuration(map.getDuration());
411 GenericStatistics flowStats = stats.build();
413 //Add statistics to local cache
414 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
415 if(!cache.containsKey(notification.getId())){
416 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
418 NodeStatisticsAger nsa = cache.get(notification.getId());
420 //Augment the data to the flow node
422 FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
423 flowStatistics.setByteCount(flowStats.getByteCount());
424 flowStatistics.setPacketCount(flowStats.getPacketCount());
425 flowStatistics.setDuration(flowStats.getDuration());
426 flowStatistics.setContainerName(map.getContainerName());
427 flowStatistics.setBufferId(map.getBufferId());
428 flowStatistics.setCookie(map.getCookie());
429 flowStatistics.setCookieMask(map.getCookieMask());
430 flowStatistics.setFlags(map.getFlags());
431 flowStatistics.setFlowName(map.getFlowName());
432 flowStatistics.setHardTimeout(map.getHardTimeout());
433 flowStatistics.setIdleTimeout(map.getIdleTimeout());
434 flowStatistics.setInstallHw(map.isInstallHw());
435 flowStatistics.setInstructions(map.getInstructions());
436 flowStatistics.setMatch(map.getMatch());
437 flowStatistics.setOutGroup(map.getOutGroup());
438 flowStatistics.setOutPort(map.getOutPort());
439 flowStatistics.setPriority(map.getPriority());
440 flowStatistics.setStrict(map.isStrict());
441 flowStatistics.setTableId(tableId);
443 flowStatisticsData.setFlowStatistics(flowStatistics.build());
445 sucLogger.debug("Flow : {}",flowRule.toString());
446 sucLogger.debug("Statistics to augment : {}",flowStatistics.build().toString());
448 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
449 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
451 Table table= (Table)it.readConfigurationData(tableRef);
453 //TODO: Not a good way to do it, need to figure out better way.
454 //TODO: major issue in any alternate approach is that flow key is incrementally assigned
455 //to the flows stored in data store.
456 // Augment same statistics to all the matching masked flow
459 for(Flow existingFlow : table.getFlow()){
460 sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
461 if(flowEquals(flowRule,existingFlow)){
462 it = this.statisticsManager.startChange();
463 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
464 .augmentation(FlowCapableNode.class)
465 .child(Table.class, new TableKey(tableId))
466 .child(Flow.class,existingFlow.getKey()).toInstance();
467 flowBuilder.setKey(existingFlow.getKey());
468 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
469 sucLogger.debug("Found matching flow in the datastore, augmenting statistics");
470 foundOriginalFlow = true;
471 // Update entry with timestamp of latest response
472 flow.setKey(existingFlow.getKey());
473 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
474 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
476 it.putOperationalData(flowRef, flowBuilder.build());
482 table= (Table)it.readOperationalData(tableRef);
483 if(!foundOriginalFlow && table != null){
485 for(Flow existingFlow : table.getFlow()){
486 FlowStatisticsData augmentedflowStatisticsData = existingFlow.getAugmentation(FlowStatisticsData.class);
487 if(augmentedflowStatisticsData != null){
488 FlowBuilder existingOperationalFlow = new FlowBuilder();
489 existingOperationalFlow.fieldsFrom(augmentedflowStatisticsData.getFlowStatistics());
490 sucLogger.debug("Existing unaccounted flow in operational data store : {}",existingFlow.toString());
491 if(flowEquals(flowRule,existingOperationalFlow.build())){
492 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
493 .augmentation(FlowCapableNode.class)
494 .child(Table.class, new TableKey(tableId))
495 .child(Flow.class,existingFlow.getKey()).toInstance();
496 flowBuilder.setKey(existingFlow.getKey());
497 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
498 sucLogger.debug("Found matching unaccounted flow in the operational datastore, augmenting statistics");
499 foundOriginalFlow = true;
501 // Update entry with timestamp of latest response
502 flow.setKey(existingFlow.getKey());
503 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
504 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
506 it.putOperationalData(flowRef, flowBuilder.build());
513 if(!foundOriginalFlow){
514 String flowKey = "#UF$TABLE*"+Short.toString(tableId)+"*"+Integer.toString(this.unaccountedFlowsCounter);
515 this.unaccountedFlowsCounter++;
516 FlowKey newFlowKey = new FlowKey(new FlowId(flowKey));
517 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
518 .augmentation(FlowCapableNode.class)
519 .child(Table.class, new TableKey(tableId))
520 .child(Flow.class,newFlowKey).toInstance();
521 flowBuilder.setKey(newFlowKey);
522 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
523 sucLogger.debug("Flow {} is not present in config data store, augmenting statistics as an unaccounted flow",flowBuilder.build());
525 // Update entry with timestamp of latest response
526 flow.setKey(newFlowKey);
527 FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flow.build());
528 cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
530 it.putOperationalData(flowRef, flowBuilder.build());
537 public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
538 //Check if response is for the request statistics-manager sent.
539 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
542 NodeKey key = new NodeKey(notification.getId());
544 Short tableId = messageManager.getTableIdForTxId(notification.getId(),notification.getTransactionId());
547 DataModificationTransaction it = this.statisticsManager.startChange();
549 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
550 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
552 AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
553 AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
554 aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
555 aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
556 aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
557 aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
559 sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
561 TableBuilder tableBuilder = new TableBuilder();
562 tableBuilder.setKey(new TableKey(tableId));
563 tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
564 it.putOperationalData(tableRef, tableBuilder.build());
571 public void onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
572 //Check if response is for the request statistics-manager sent.
573 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
576 NodeKey key = new NodeKey(notification.getId());
578 List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
579 for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
581 DataModificationTransaction it = this.statisticsManager.startChange();
583 FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder
584 = new FlowCapableNodeConnectorStatisticsBuilder();
585 statisticsBuilder.setBytes(portStats.getBytes());
586 statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
587 statisticsBuilder.setDuration(portStats.getDuration());
588 statisticsBuilder.setPackets(portStats.getPackets());
589 statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
590 statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
591 statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
592 statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
593 statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
594 statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
595 statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
597 //Augment data to the node-connector
598 FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder =
599 new FlowCapableNodeConnectorStatisticsDataBuilder();
601 statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
603 InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
605 NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
607 if(nodeConnector != null){
608 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
609 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
610 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
611 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
618 public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
619 //Check if response is for the request statistics-manager sent.
620 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
623 NodeKey key = new NodeKey(notification.getId());
625 List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
626 for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
628 DataModificationTransaction it = this.statisticsManager.startChange();
630 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
631 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
633 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
635 FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
636 statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
637 statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
638 statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
640 statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
642 sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
644 TableBuilder tableBuilder = new TableBuilder();
645 tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
646 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
647 it.putOperationalData(tableRef, tableBuilder.build());
653 public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
655 //Check if response is for the request statistics-manager sent.
656 if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
659 NodeKey key = new NodeKey(notification.getId());
661 //Add statistics to local cache
662 ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
663 if(!cache.containsKey(notification.getId())){
664 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
667 NodeStatisticsAger nsa = cache.get(notification.getId());
669 List<QueueIdAndStatisticsMap> queuesStats = notification.getQueueIdAndStatisticsMap();
670 for(QueueIdAndStatisticsMap swQueueStats : queuesStats){
672 QueueEntry queueEntry = nsa.new QueueEntry(swQueueStats.getNodeConnectorId(),swQueueStats.getQueueId());
673 nsa.updateQueueStats(queueEntry);
675 FlowCapableNodeConnectorQueueStatisticsDataBuilder queueStatisticsDataBuilder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
677 FlowCapableNodeConnectorQueueStatisticsBuilder queueStatisticsBuilder = new FlowCapableNodeConnectorQueueStatisticsBuilder();
679 queueStatisticsBuilder.fieldsFrom(swQueueStats);
681 queueStatisticsDataBuilder.setFlowCapableNodeConnectorQueueStatistics(queueStatisticsBuilder.build());
683 DataModificationTransaction it = this.statisticsManager.startChange();
685 InstanceIdentifier<Queue> queueRef
686 = InstanceIdentifier.builder(Nodes.class)
687 .child(Node.class, key)
688 .child(NodeConnector.class, new NodeConnectorKey(swQueueStats.getNodeConnectorId()))
689 .augmentation(FlowCapableNodeConnector.class)
690 .child(Queue.class, new QueueKey(swQueueStats.getQueueId())).toInstance();
692 QueueBuilder queueBuilder = new QueueBuilder();
693 queueBuilder.addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, queueStatisticsDataBuilder.build());
694 queueBuilder.setKey(new QueueKey(swQueueStats.getQueueId()));
696 sucLogger.debug("Augmenting queue statistics {} of queue {} to port {}"
697 ,queueStatisticsDataBuilder.build().toString(),
698 swQueueStats.getQueueId(),
699 swQueueStats.getNodeConnectorId());
701 it.putOperationalData(queueRef, queueBuilder.build());
708 private static NodeRef getNodeRef(NodeKey nodeKey){
709 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
710 return new NodeRef(builder.toInstance());
713 public boolean flowEquals(Flow statsFlow, Flow storedFlow) {
714 if (statsFlow.getClass() != storedFlow.getClass()) {
717 if (statsFlow.getContainerName()== null) {
718 if (storedFlow.getContainerName()!= null) {
721 } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
724 if (statsFlow.getMatch()== null) {
725 if (storedFlow.getMatch() != null) {
728 } //else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
729 else if(!matchEquals(statsFlow.getMatch(), storedFlow.getMatch())) {
732 if (storedFlow.getPriority() == null) {
733 if (statsFlow.getPriority() != null && statsFlow.getPriority()!= 0x8000) {
736 } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
739 if (statsFlow.getTableId() == null) {
740 if (storedFlow.getTableId() != null) {
743 } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {
750 * Explicit equals method to compare the 'match' for flows stored in the data-stores and flow fetched from the switch.
751 * Flow installation process has three steps
752 * 1) Store flow in config data store
753 * 2) and send it to plugin for installation
754 * 3) Flow gets installed in switch
756 * The flow user wants to install and what finally gets installed in switch can be slightly different.
757 * E.g, If user installs flow with src/dst ip=10.0.0.1/24, when it get installed in the switch
758 * src/dst ip will be changes to 10.0.0.0/24 because of netmask of 24. When statistics manager fetch
759 * stats it gets 10.0.0.0/24 rather then 10.0.0.1/24. Custom match takes care of by using masked ip
760 * while comparing two ip addresses.
762 * Sometimes when user don't provide few values that is required by flow installation request, like
763 * priority,hard timeout, idle timeout, cookies etc, plugin usages default values before sending
764 * request to the switch. So when statistics manager gets flow statistics, it gets the default value.
765 * But the flow stored in config data store don't have those defaults value. I included those checks
766 * in the customer flow/match equal function.
774 public boolean matchEquals(Match statsFlow, Match storedFlow) {
775 if (statsFlow == storedFlow) {
778 if (storedFlow.getClass() != statsFlow.getClass()) {
781 if (storedFlow.getEthernetMatch() == null) {
782 if (statsFlow.getEthernetMatch() != null) {
785 } else if(!storedFlow.getEthernetMatch().equals(statsFlow.getEthernetMatch())) {
788 if (storedFlow.getIcmpv4Match()== null) {
789 if (statsFlow.getIcmpv4Match() != null) {
792 } else if(!storedFlow.getIcmpv4Match().equals(statsFlow.getIcmpv4Match())) {
795 if (storedFlow.getIcmpv6Match() == null) {
796 if (statsFlow.getIcmpv6Match() != null) {
799 } else if(!storedFlow.getIcmpv6Match().equals(statsFlow.getIcmpv6Match())) {
802 if (storedFlow.getInPhyPort() == null) {
803 if (statsFlow.getInPhyPort() != null) {
806 } else if(!storedFlow.getInPhyPort().equals(statsFlow.getInPhyPort())) {
809 if (storedFlow.getInPort()== null) {
810 if (statsFlow.getInPort() != null) {
813 } else if(!storedFlow.getInPort().equals(statsFlow.getInPort())) {
816 if (storedFlow.getIpMatch()== null) {
817 if (statsFlow.getIpMatch() != null) {
820 } else if(!storedFlow.getIpMatch().equals(statsFlow.getIpMatch())) {
823 if (storedFlow.getLayer3Match()== null) {
824 if (statsFlow.getLayer3Match() != null) {
827 } else if(!layer3MatchEquals(statsFlow.getLayer3Match(),storedFlow.getLayer3Match())) {
830 if (storedFlow.getLayer4Match()== null) {
831 if (statsFlow.getLayer4Match() != null) {
834 } else if(!storedFlow.getLayer4Match().equals(statsFlow.getLayer4Match())) {
837 if (storedFlow.getMetadata() == null) {
838 if (statsFlow.getMetadata() != null) {
841 } else if(!storedFlow.getMetadata().equals(statsFlow.getMetadata())) {
844 if (storedFlow.getProtocolMatchFields() == null) {
845 if (statsFlow.getProtocolMatchFields() != null) {
848 } else if(!storedFlow.getProtocolMatchFields().equals(statsFlow.getProtocolMatchFields())) {
851 if (storedFlow.getTunnel()== null) {
852 if (statsFlow.getTunnel() != null) {
855 } else if(!storedFlow.getTunnel().equals(statsFlow.getTunnel())) {
858 if (storedFlow.getVlanMatch()== null) {
859 if (statsFlow.getVlanMatch() != null) {
862 } else if(!storedFlow.getVlanMatch().equals(statsFlow.getVlanMatch())) {
868 protected static boolean layer3MatchEquals(Layer3Match statsLayer3Match, Layer3Match storedLayer3Match){
869 boolean verdict = true;
870 if(statsLayer3Match instanceof Ipv4Match && storedLayer3Match instanceof Ipv4Match){
871 Ipv4Match statsIpv4Match = (Ipv4Match)statsLayer3Match;
872 Ipv4Match storedIpv4Match = (Ipv4Match)storedLayer3Match;
875 verdict = compareNullSafe(
876 storedIpv4Match.getIpv4Destination(), statsIpv4Match.getIpv4Destination());
879 verdict = compareNullSafe(
880 statsIpv4Match.getIpv4Source(), storedIpv4Match.getIpv4Source());
883 Boolean nullCheckOut = checkNullValues(storedLayer3Match, statsLayer3Match);
884 if (nullCheckOut != null) {
885 verdict = nullCheckOut;
887 verdict = storedLayer3Match.equals(statsLayer3Match);
894 private static boolean compareNullSafe(Ipv4Prefix statsIpv4, Ipv4Prefix storedIpv4) {
895 boolean verdict = true;
896 Boolean checkDestNullValuesOut = checkNullValues(storedIpv4, statsIpv4);
897 if (checkDestNullValuesOut != null) {
898 verdict = checkDestNullValuesOut;
899 } else if(!IpAddressEquals(statsIpv4, storedIpv4)){
906 private static Boolean checkNullValues(Object v1, Object v2) {
907 Boolean verdict = null;
908 if (v1 == null && v2 != null) {
909 verdict = Boolean.FALSE;
910 } else if (v1 != null && v2 == null) {
911 verdict = Boolean.FALSE;
912 } else if (v1 == null && v2 == null) {
913 verdict = Boolean.TRUE;
920 * TODO: why don't we use the default Ipv4Prefix.equals()?
922 * @param statsIpAddress
923 * @param storedIpAddress
924 * @return true if IPv4prefixes equals
926 private static boolean IpAddressEquals(Ipv4Prefix statsIpAddress, Ipv4Prefix storedIpAddress) {
927 IntegerIpAddress statsIpAddressInt = StrIpToIntIp(statsIpAddress.getValue());
928 IntegerIpAddress storedIpAddressInt = StrIpToIntIp(storedIpAddress.getValue());
930 if(IpAndMaskBasedMatch(statsIpAddressInt,storedIpAddressInt)){
933 if(IpBasedMatch(statsIpAddressInt,storedIpAddressInt)){
939 private static boolean IpAndMaskBasedMatch(IntegerIpAddress statsIpAddressInt,IntegerIpAddress storedIpAddressInt){
940 return ((statsIpAddressInt.getIp() & statsIpAddressInt.getMask()) == (storedIpAddressInt.getIp() & storedIpAddressInt.getMask()));
943 private static boolean IpBasedMatch(IntegerIpAddress statsIpAddressInt,IntegerIpAddress storedIpAddressInt){
944 return (statsIpAddressInt.getIp() == storedIpAddressInt.getIp());
948 * Method return integer version of ip address. Converted int will be mask if
951 private static IntegerIpAddress StrIpToIntIp(String ipAddresss){
953 String[] parts = ipAddresss.split("/");
954 String ip = parts[0];
957 if (parts.length < 2) {
960 prefix = Integer.parseInt(parts[1]);
963 IntegerIpAddress integerIpAddress = null;
965 Inet4Address addr = (Inet4Address) InetAddress.getByName(ip);
966 byte[] addrBytes = addr.getAddress();
967 int ipInt = ((addrBytes[0] & 0xFF) << 24) |
968 ((addrBytes[1] & 0xFF) << 16) |
969 ((addrBytes[2] & 0xFF) << 8) |
970 ((addrBytes[3] & 0xFF) << 0);
972 int mask = 0xffffffff << 32 - prefix;
974 integerIpAddress = new IntegerIpAddress(ipInt, mask);
975 } catch (UnknownHostException e){
976 sucLogger.error("Failed to determine host IP address by name: {}", e.getMessage(), e);
979 return integerIpAddress;
982 static class IntegerIpAddress{
985 public IntegerIpAddress(int ip, int mask) {
992 public int getMask() {