Open Kilda Java Documentation
IofSwitchConverter.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.floodlight.converter;
17 
23 
24 import net.floodlightcontroller.core.IOFSwitch;
25 import net.floodlightcontroller.core.LogicalOFMessageCategory;
26 import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
27 
28 import java.net.InetSocketAddress;
29 import java.util.List;
30 import java.util.stream.Collectors;
31 
35 public final class IofSwitchConverter {
36 
44  public static SwitchInfoData buildSwitchInfoData(IOFSwitch sw, SwitchState eventType) {
45  SwitchId switchId = new SwitchId(sw.getId().getLong());
46  InetSocketAddress address = (InetSocketAddress) sw.getInetAddress();
47  InetSocketAddress controller = (InetSocketAddress) sw.getConnectionByCategory(
48  LogicalOFMessageCategory.MAIN).getRemoteInetAddress();
49 
50  return new SwitchInfoData(
51  switchId,
52  eventType,
53  String.format("%s:%d",
54  address.getHostString(),
55  address.getPort()),
56  address.getHostName(),
57  String.format("%s %s %s",
58  sw.getSwitchDescription().getManufacturerDescription(),
59  sw.getOFFactory().getVersion().toString(),
60  sw.getSwitchDescription().getSoftwareDescription()),
61  controller.getHostString());
62  }
63 
72  public static SwitchInfoExtendedData buildSwitchInfoDataExtended(IOFSwitch sw, SwitchState eventType,
73  OFFlowStatsReply flowStats) {
74  SwitchInfoData switchInfoData = buildSwitchInfoData(sw, eventType);
75 
76  List<FlowEntry> flows = flowStats.getEntries().stream()
78  .collect(Collectors.toList());
79 
80  return new SwitchInfoExtendedData(switchInfoData, flows);
81  }
82 
83  private IofSwitchConverter() {
84  }
85 }
static FlowEntry toFlowEntry(final OFFlowStatsEntry entry)
static SwitchInfoExtendedData buildSwitchInfoDataExtended(IOFSwitch sw, SwitchState eventType, OFFlowStatsReply flowStats)
Definition: FlowEntry.java:29
static SwitchInfoData buildSwitchInfoData(IOFSwitch sw, SwitchState eventType)
net
Definition: plan-b.py:46