Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.device.impl; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 17 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 20 | import static org.onlab.util.Tools.get; |
| 21 | import static org.onosproject.net.DeviceId.deviceId; |
| 22 | import static org.onosproject.net.Port.Type.COPPER; |
| 23 | import static org.onosproject.net.Port.Type.FIBER; |
| 24 | import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 25 | import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 26 | import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription; |
HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 27 | import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 28 | import static org.onosproject.openflow.controller.Dpid.dpid; |
| 29 | import static org.onosproject.openflow.controller.Dpid.uri; |
| 30 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.Collection; |
| 34 | import java.util.Collections; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 35 | import java.util.Comparator; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 36 | import java.util.Dictionary; |
| 37 | import java.util.HashMap; |
| 38 | import java.util.HashSet; |
| 39 | import java.util.List; |
Victor Silva | 7944d14 | 2016-07-08 00:14:55 -0300 | [diff] [blame] | 40 | import java.util.Properties; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 41 | import java.util.Set; |
sangyun-han | 07a572f | 2016-07-29 21:14:27 +0900 | [diff] [blame] | 42 | import java.util.Timer; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 43 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 44 | import org.apache.felix.scr.annotations.Activate; |
| 45 | import org.apache.felix.scr.annotations.Component; |
| 46 | import org.apache.felix.scr.annotations.Deactivate; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 47 | import org.apache.felix.scr.annotations.Modified; |
| 48 | import org.apache.felix.scr.annotations.Property; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 49 | import org.apache.felix.scr.annotations.Reference; |
| 50 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 51 | import org.onlab.packet.ChassisId; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 52 | import org.onlab.util.Frequency; |
| 53 | import org.onlab.util.Spectrum; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 54 | import org.onosproject.cfg.ComponentConfigService; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 55 | import org.onosproject.net.AnnotationKeys; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 56 | import org.onosproject.net.ChannelSpacing; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 57 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import org.onosproject.net.DefaultAnnotations; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 59 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 60 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 61 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.MastershipRole; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 63 | import org.onosproject.net.OchSignal; |
| 64 | import org.onosproject.net.OduSignalType; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 65 | import org.onosproject.net.OtuSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 66 | import org.onosproject.net.Port; |
| 67 | import org.onosproject.net.PortNumber; |
| 68 | import org.onosproject.net.SparseAnnotations; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 69 | import org.onosproject.net.behaviour.LambdaQuery; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 70 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 71 | import org.onosproject.net.device.DefaultPortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 72 | import org.onosproject.net.device.DefaultPortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 73 | import org.onosproject.net.device.DeviceDescription; |
| 74 | import org.onosproject.net.device.DeviceProvider; |
| 75 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 76 | import org.onosproject.net.device.DeviceProviderService; |
| 77 | import org.onosproject.net.device.PortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 78 | import org.onosproject.net.device.PortStatistics; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 79 | import org.onosproject.net.driver.DriverHandler; |
| 80 | import org.onosproject.net.driver.HandlerBehaviour; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 81 | import org.onosproject.net.provider.AbstractProvider; |
| 82 | import org.onosproject.net.provider.ProviderId; |
| 83 | import org.onosproject.openflow.controller.Dpid; |
| 84 | import org.onosproject.openflow.controller.OpenFlowController; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 85 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 86 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 87 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 88 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 89 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 90 | import org.onosproject.openflow.controller.RoleState; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 91 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp; |
| 93 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 95 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 96 | import org.projectfloodlight.openflow.protocol.OFErrorType; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.protocol.OFExpPort; |
| 98 | import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport; |
| 99 | import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry; |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 100 | import org.projectfloodlight.openflow.protocol.OFFactory; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 101 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 102 | import org.projectfloodlight.openflow.protocol.OFObject; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 103 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 104 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 105 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 106 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 107 | import org.projectfloodlight.openflow.protocol.OFPortMod; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 108 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 109 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass; |
| 110 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType; |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 111 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 112 | import org.projectfloodlight.openflow.protocol.OFPortState; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 113 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
| 114 | import org.projectfloodlight.openflow.protocol.OFPortStatsReply; |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 115 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 116 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 117 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 118 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 119 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 120 | import org.projectfloodlight.openflow.types.OFPort; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 121 | import org.projectfloodlight.openflow.types.PortSpeed; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 122 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 123 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 124 | import com.google.common.base.Strings; |
Ray Milkey | 3c4124a | 2016-08-31 12:09:06 -0700 | [diff] [blame] | 125 | import com.google.common.collect.ImmutableList; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 126 | import com.google.common.collect.Lists; |
| 127 | import com.google.common.collect.Maps; |
| 128 | import com.google.common.collect.Sets; |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 129 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 130 | /** |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 131 | * Provider which uses an OpenFlow controller to detect network |
tom | e06f855 | 2014-08-26 16:58:42 -0700 | [diff] [blame] | 132 | * infrastructure devices. |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 133 | */ |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 134 | @Component(immediate = true) |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 135 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 136 | |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 137 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 138 | |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 139 | //TODO consider renaming KBPS and MBPS (as they are used to convert by division) |
| 140 | private static final long KBPS = 1_000; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 141 | private static final long MBPS = 1_000 * 1_000; |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 142 | private static final Frequency FREQ50 = Frequency.ofGHz(50); |
| 143 | private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700); |
Sho SHIMIZU | 00762ee | 2016-01-05 16:32:24 -0800 | [diff] [blame] | 144 | private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 145 | |
| 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 147 | protected DeviceProviderRegistry providerRegistry; |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 148 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 149 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 150 | protected OpenFlowController controller; |
| 151 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 152 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 153 | protected ComponentConfigService cfgService; |
| 154 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 155 | private DeviceProviderService providerService; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 156 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 157 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); |
| 158 | |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 159 | private static final String POLL_PROP_NAME = "portStatsPollFrequency"; |
| 160 | private static final int POLL_INTERVAL = 5; |
| 161 | @Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL, |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 162 | label = "Frequency (in seconds) for polling switch Port statistics") |
| 163 | private int portStatsPollFrequency = POLL_INTERVAL; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 164 | |
Victor Silva | ff5871b | 2016-10-04 18:08:47 -0300 | [diff] [blame] | 165 | private final Timer timer = new Timer("onos-openflow-portstats-collector"); |
sangyun-han | 07a572f | 2016-07-29 21:14:27 +0900 | [diff] [blame] | 166 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 167 | private HashMap<Dpid, PortStatsCollector> collectors = Maps.newHashMap(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 168 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 169 | /** |
| 170 | * Creates an OpenFlow device provider. |
| 171 | */ |
| 172 | public OpenFlowDeviceProvider() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 173 | super(new ProviderId("of", "org.onosproject.provider.openflow")); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 174 | } |
| 175 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 176 | @Activate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 177 | public void activate(ComponentContext context) { |
| 178 | cfgService.registerProperties(getClass()); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 179 | providerService = providerRegistry.register(this); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 180 | controller.addListener(listener); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 181 | controller.addEventListener(listener); |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 182 | |
Victor Silva | 7944d14 | 2016-07-08 00:14:55 -0300 | [diff] [blame] | 183 | modified(context); |
| 184 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 185 | connectInitialDevices(); |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 186 | LOG.info("Started"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Deactivate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 190 | public void deactivate(ComponentContext context) { |
| 191 | cfgService.unregisterProperties(getClass(), false); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 192 | listener.disable(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 193 | controller.removeListener(listener); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 194 | providerRegistry.unregister(this); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 195 | collectors.values().forEach(PortStatsCollector::stop); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 196 | collectors.clear(); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 197 | providerService = null; |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 198 | LOG.info("Stopped"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 201 | @Modified |
| 202 | public void modified(ComponentContext context) { |
Victor Silva | 7944d14 | 2016-07-08 00:14:55 -0300 | [diff] [blame] | 203 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 204 | int newPortStatsPollFrequency; |
| 205 | try { |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 206 | String s = get(properties, POLL_PROP_NAME); |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 207 | newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim()); |
| 208 | |
| 209 | } catch (NumberFormatException | ClassCastException e) { |
| 210 | newPortStatsPollFrequency = portStatsPollFrequency; |
| 211 | } |
| 212 | |
| 213 | if (newPortStatsPollFrequency != portStatsPollFrequency) { |
| 214 | portStatsPollFrequency = newPortStatsPollFrequency; |
| 215 | collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency)); |
| 216 | } |
| 217 | |
| 218 | LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency); |
| 219 | } |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 220 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 221 | private void connectInitialDevices() { |
| 222 | for (OpenFlowSwitch sw : controller.getSwitches()) { |
| 223 | try { |
| 224 | listener.switchAdded(new Dpid(sw.getId())); |
| 225 | } catch (Exception e) { |
| 226 | LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); |
| 227 | LOG.debug("Error details:", e); |
| 228 | // disconnect to trigger switch-add later |
| 229 | sw.disconnectSwitch(); |
| 230 | } |
sangyun-han | 07a572f | 2016-07-29 21:14:27 +0900 | [diff] [blame] | 231 | PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 232 | psc.start(); |
| 233 | collectors.put(new Dpid(sw.getId()), psc); |
| 234 | } |
| 235 | } |
| 236 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 237 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 238 | public boolean isReachable(DeviceId deviceId) { |
| 239 | OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 240 | return sw != null && sw.isConnected(); |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 241 | } |
| 242 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 243 | @Override |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 244 | public void triggerProbe(DeviceId deviceId) { |
Madan Jampani | c332876 | 2015-05-31 12:39:27 -0700 | [diff] [blame] | 245 | LOG.debug("Triggering probe on device {}", deviceId); |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 246 | |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 247 | final Dpid dpid = dpid(deviceId.uri()); |
| 248 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 249 | if (sw == null || !sw.isConnected()) { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 250 | LOG.error("Failed to probe device {} on sw={}", deviceId, sw); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 251 | providerService.deviceDisconnected(deviceId); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 252 | return; |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 253 | } else { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 254 | LOG.trace("Confirmed device {} connection", deviceId); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 255 | } |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 256 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 257 | // Prompt an update of port information. We can use any XID for this. |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 258 | OFFactory fact = sw.factory(); |
| 259 | switch (fact.getVersion()) { |
| 260 | case OF_10: |
| 261 | sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); |
| 262 | break; |
| 263 | case OF_13: |
| 264 | sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); |
| 265 | break; |
| 266 | default: |
| 267 | LOG.warn("Unhandled protocol version"); |
| 268 | } |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 272 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 273 | switch (newRole) { |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 274 | case MASTER: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 275 | controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 276 | break; |
| 277 | case STANDBY: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 278 | controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 279 | break; |
| 280 | case NONE: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 281 | controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 282 | break; |
| 283 | default: |
| 284 | LOG.error("Unknown Mastership state : {}", newRole); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 285 | |
| 286 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 287 | LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 290 | @Override |
| 291 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 292 | boolean enable) { |
| 293 | final Dpid dpid = dpid(deviceId.uri()); |
| 294 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 295 | if (sw == null || !sw.isConnected()) { |
| 296 | LOG.error("Failed to change portState on device {}", deviceId); |
| 297 | return; |
| 298 | } |
| 299 | OFPortMod.Builder pmb = sw.factory().buildPortMod(); |
| 300 | OFPort port = OFPort.of((int) portNumber.toLong()); |
| 301 | pmb.setPortNo(port); |
| 302 | if (enable) { |
| 303 | pmb.setConfig(0x0); // port_down bit 0 |
| 304 | } else { |
| 305 | pmb.setConfig(0x1); // port_down bit 1 |
| 306 | } |
| 307 | pmb.setMask(0x1); |
| 308 | pmb.setAdvertise(0x0); |
| 309 | for (OFPortDesc pd : sw.getPorts()) { |
| 310 | if (pd.getPortNo().equals(port)) { |
| 311 | pmb.setHwAddr(pd.getHwAddr()); |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | sw.sendMsg(Collections.singletonList(pmb.build())); |
| 316 | } |
| 317 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 318 | private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 319 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
Ray Milkey | 3c4124a | 2016-08-31 12:09:06 -0700 | [diff] [blame] | 320 | Collection<PortStatistics> stats = |
| 321 | buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 322 | providerService.updatePortStatistics(deviceId, stats); |
| 323 | } |
| 324 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 325 | private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, |
| 326 | List<OFPortStatsEntry> entries) { |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 327 | HashSet<PortStatistics> stats = Sets.newHashSet(); |
| 328 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 329 | for (OFPortStatsEntry entry : entries) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 330 | try { |
Thomas Vachuska | 4e6025e | 2015-06-03 11:25:21 -0700 | [diff] [blame] | 331 | if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 332 | continue; |
| 333 | } |
| 334 | DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); |
| 335 | DefaultPortStatistics stat = builder.setDeviceId(deviceId) |
| 336 | .setPort(entry.getPortNo().getPortNumber()) |
| 337 | .setPacketsReceived(entry.getRxPackets().getValue()) |
| 338 | .setPacketsSent(entry.getTxPackets().getValue()) |
| 339 | .setBytesReceived(entry.getRxBytes().getValue()) |
| 340 | .setBytesSent(entry.getTxBytes().getValue()) |
| 341 | .setPacketsRxDropped(entry.getRxDropped().getValue()) |
| 342 | .setPacketsTxDropped(entry.getTxDropped().getValue()) |
| 343 | .setPacketsRxErrors(entry.getRxErrors().getValue()) |
| 344 | .setPacketsTxErrors(entry.getTxErrors().getValue()) |
| 345 | .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()) |
| 346 | .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()) |
| 347 | .build(); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 348 | |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 349 | stats.add(stat); |
| 350 | } catch (Exception e) { |
| 351 | LOG.warn("Unable to process port stats", e); |
| 352 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | return Collections.unmodifiableSet(stats); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener { |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 359 | |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 360 | private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 361 | private boolean isDisabled = false; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 362 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 363 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 364 | public void switchAdded(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 365 | if (providerService == null) { |
| 366 | return; |
| 367 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 368 | DeviceId did = deviceId(uri(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 369 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 370 | if (sw == null) { |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 371 | LOG.error("Switch {} is not found", dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 372 | return; |
| 373 | } |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 374 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 375 | ChassisId cId = new ChassisId(dpid.value()); |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 376 | |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 377 | SparseAnnotations annotations = DefaultAnnotations.builder() |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 378 | .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString()) |
| 379 | .set(AnnotationKeys.CHANNEL_ID, sw.channelId()) |
| 380 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]) |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 381 | .build(); |
| 382 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 383 | DeviceDescription description = |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 384 | new DefaultDeviceDescription(did.uri(), sw.deviceType(), |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 385 | sw.manufacturerDescription(), |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 386 | sw.hardwareDescription(), |
| 387 | sw.softwareDescription(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 388 | sw.serialNumber(), |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 389 | cId, annotations); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 390 | providerService.deviceConnected(did, description); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 391 | providerService.updatePorts(did, buildPortDescriptions(sw)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 392 | |
sangyun-han | 07a572f | 2016-07-29 21:14:27 +0900 | [diff] [blame] | 393 | PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 394 | stopCollectorIfNeeded(collectors.put(dpid, psc)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 395 | psc.start(); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 396 | |
| 397 | //figure out race condition for collectors.remove() and collectors.put() |
| 398 | if (controller.getSwitch(dpid) == null) { |
| 399 | switchRemoved(dpid); |
| 400 | } |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 403 | private void stopCollectorIfNeeded(PortStatsCollector collector) { |
| 404 | if (collector != null) { |
| 405 | collector.stop(); |
| 406 | } |
| 407 | } |
| 408 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 409 | @Override |
| 410 | public void switchRemoved(Dpid dpid) { |
Victor Silva | 03265dd | 2016-12-08 11:20:36 -0300 | [diff] [blame^] | 411 | stopCollectorIfNeeded(collectors.remove(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 412 | if (providerService == null) { |
| 413 | return; |
| 414 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 415 | providerService.deviceDisconnected(deviceId(uri(dpid))); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 416 | } |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 417 | |
| 418 | @Override |
| 419 | public void switchChanged(Dpid dpid) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 420 | LOG.debug("switchChanged({})", dpid); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 421 | if (providerService == null) { |
| 422 | return; |
| 423 | } |
| 424 | DeviceId did = deviceId(uri(dpid)); |
| 425 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 426 | if (sw == null) { |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 427 | LOG.error("Switch {} is not found", dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 428 | return; |
| 429 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 430 | final List<PortDescription> ports = buildPortDescriptions(sw); |
| 431 | LOG.debug("switchChanged({}) {}", did, ports); |
| 432 | providerService.updatePorts(did, ports); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 433 | } |
| 434 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 435 | @Override |
| 436 | public void portChanged(Dpid dpid, OFPortStatus status) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 437 | LOG.debug("portChanged({},{})", dpid, status); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 438 | PortDescription portDescription = buildPortDescription(status); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 439 | providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 442 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 443 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 444 | LOG.debug("receivedRoleReply({},{},{})", dpid, requested, response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 445 | MastershipRole request = roleOf(requested); |
| 446 | MastershipRole reply = roleOf(response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 447 | providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply); |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Translates a RoleState to the corresponding MastershipRole. |
| 452 | * |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 453 | * @param response role state |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 454 | * @return a MastershipRole |
| 455 | */ |
| 456 | private MastershipRole roleOf(RoleState response) { |
| 457 | switch (response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 458 | case MASTER: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 459 | return MastershipRole.MASTER; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 460 | case EQUAL: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 461 | return MastershipRole.STANDBY; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 462 | case SLAVE: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 463 | return MastershipRole.NONE; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 464 | default: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 465 | LOG.warn("unknown role {}", response); |
| 466 | return null; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 467 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 468 | } |
| 469 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 470 | /** |
| 471 | * Builds a list of port descriptions for a given list of ports. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 472 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 473 | * @return list of portdescriptions |
| 474 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 475 | private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { |
| 476 | final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size()); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 477 | if (!((Device.Type.ROADM.equals(sw.deviceType())) || |
| 478 | (Device.Type.OTN.equals(sw.deviceType())))) { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 479 | sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port))); |
| 480 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 481 | |
| 482 | OpenFlowOpticalSwitch opsw; |
| 483 | switch (sw.deviceType()) { |
| 484 | case ROADM: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 485 | case OTN: |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 486 | opsw = (OpenFlowOpticalSwitch) sw; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 487 | List<OFPortDesc> ports = opsw.getPorts(); |
| 488 | LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports); |
| 489 | // ODU client ports are reported as ETH |
| 490 | ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port))); |
| 491 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 492 | opsw.getPortTypes().forEach(type -> { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 493 | List<? extends OFObject> portsOf = opsw.getPortsOf(type); |
| 494 | LOG.debug("Ports Of{}", portsOf); |
| 495 | portsOf.forEach( |
| 496 | op -> { |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 497 | portDescs.add(buildPortDescription(type, op, opsw)); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 498 | } |
| 499 | ); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 500 | }); |
| 501 | break; |
| 502 | case FIBER_SWITCH: |
| 503 | opsw = (OpenFlowOpticalSwitch) sw; |
| 504 | opsw.getPortTypes().forEach(type -> { |
| 505 | opsw.getPortsOf(type).forEach( |
| 506 | op -> { |
| 507 | portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op)); |
| 508 | } |
| 509 | ); |
| 510 | }); |
| 511 | break; |
| 512 | default: |
| 513 | break; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 514 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 515 | |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 516 | return portDescs; |
| 517 | } |
| 518 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 519 | private PortDescription buildOduCltPortDescription(OFPortDesc port) { |
| 520 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 521 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && |
| 522 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 523 | Long portSpeedInMbps = portSpeed(port); |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 524 | CltSignalType sigType = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 525 | |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 526 | switch (portSpeedInMbps.toString()) { |
| 527 | case "1000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 528 | sigType = CltSignalType.CLT_1GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 529 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 530 | case "10000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 531 | sigType = CltSignalType.CLT_10GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 532 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 533 | case "40000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 534 | sigType = CltSignalType.CLT_40GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 535 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 536 | case "100000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 537 | sigType = CltSignalType.CLT_100GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 538 | break; |
| 539 | default: |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 540 | throw new RuntimeException("Un recognize OduClt speed: " + portSpeedInMbps.toString()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | SparseAnnotations annotations = buildOduCltAnnotation(port); |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 544 | return oduCltPortDescription(portNo, enabled, sigType, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) { |
| 548 | SparseAnnotations annotations = null; |
| 549 | String portName = Strings.emptyToNull(port.getName()); |
| 550 | if (portName != null) { |
| 551 | annotations = DefaultAnnotations.builder() |
| 552 | .set(AnnotationKeys.PORT_NAME, portName) |
| 553 | .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build(); |
| 554 | } |
| 555 | return annotations; |
| 556 | } |
| 557 | |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 558 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port, |
| 559 | OpenFlowOpticalSwitch opsw) { |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 560 | if (port instanceof OFPortOptical) { |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 561 | return buildPortDescription(ptype, (OFPortOptical) port, opsw); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 562 | } |
| 563 | return buildPortDescription(ptype, (OFExpPort) port); |
| 564 | } |
| 565 | |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 566 | private boolean matchingOtuPortSignalTypes(OFPortOpticalTransportSignalType sigType, |
| 567 | OduSignalType oduSignalType) { |
| 568 | switch (sigType) { |
| 569 | case OTU2: |
| 570 | if (oduSignalType == OduSignalType.ODU2) { |
| 571 | return true; |
| 572 | } |
| 573 | break; |
| 574 | case OTU4: |
| 575 | if (oduSignalType == OduSignalType.ODU4) { |
| 576 | return true; |
| 577 | } |
| 578 | break; |
| 579 | default: |
| 580 | break; |
| 581 | } |
| 582 | return false; |
| 583 | } |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 584 | /** |
| 585 | * Build a portDescription from a given a port description describing some |
| 586 | * Optical port. |
| 587 | * |
| 588 | * @param ptype description property type. |
| 589 | * @param port the port to build from. |
| 590 | * @return portDescription for the port. |
| 591 | */ |
| 592 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) { |
| 593 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 594 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 595 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 596 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 597 | |
| 598 | OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0); |
| 599 | OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType(); |
| 600 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 601 | PortDescription portDes = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 602 | switch (sigType) { |
| 603 | case OMSN: |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 604 | portDes = omsPortDescription(portNo, enabled, |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 605 | FREQ191_7, FREQ191_7.add(FREQ4_4), FREQ50, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 606 | break; |
| 607 | case OCH: |
| 608 | OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 609 | OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass(); |
| 610 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 611 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 612 | return null; |
| 613 | } |
| 614 | |
| 615 | // convert to ONOS OduSignalType |
| 616 | OduSignalType oduSignalType = OpenFlowDeviceValueMapper. |
| 617 | lookupOduSignalType((byte) entry.getSignalType()); |
| 618 | //OchSignal is needed for OchPortDescription constructor, |
| 619 | //yet not relevant for tunable OCH port, creating with default parameters |
| 620 | OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1); |
| 621 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 622 | portDes = ochPortDescription(portNo, enabled, |
| 623 | oduSignalType, true, |
| 624 | signalId, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 625 | |
| 626 | break; |
| 627 | case OTU2: |
| 628 | case OTU4: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 629 | entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 630 | layerClass = entry.getLayerClass(); |
| 631 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 632 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 633 | return null; |
| 634 | } |
| 635 | |
| 636 | // convert to ONOS OduSignalType |
| 637 | OduSignalType oduSignalTypeOtuPort = OpenFlowDeviceValueMapper. |
| 638 | lookupOduSignalType((byte) entry.getSignalType()); |
| 639 | if (!matchingOtuPortSignalTypes(sigType, oduSignalTypeOtuPort)) { |
| 640 | LOG.error("Wrong oduSignalType {} for OTU Port sigType {} ", oduSignalTypeOtuPort, sigType); |
| 641 | return null; |
| 642 | } |
| 643 | OtuSignalType otuSignalType = |
| 644 | ((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 : |
| 645 | OtuSignalType.OTU4); |
HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 646 | portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 647 | break; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 648 | default: |
| 649 | break; |
| 650 | } |
| 651 | |
| 652 | return portDes; |
| 653 | } |
| 654 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 655 | /** |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 656 | * Creates an annotation for the port name if one is available. |
| 657 | * |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 658 | * @param portName the port name |
| 659 | * @param portMac the port mac |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 660 | * @return annotation containing the port name if one is found, |
| 661 | * null otherwise |
| 662 | */ |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 663 | private SparseAnnotations makePortAnnotation(String portName, String portMac) { |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 664 | SparseAnnotations annotations = null; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 665 | String pName = Strings.emptyToNull(portName); |
| 666 | String pMac = Strings.emptyToNull(portMac); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 667 | if (portName != null) { |
| 668 | annotations = DefaultAnnotations.builder() |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 669 | .set(AnnotationKeys.PORT_NAME, pName) |
| 670 | .set(AnnotationKeys.PORT_MAC, pMac).build(); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 671 | } |
| 672 | return annotations; |
| 673 | } |
| 674 | |
| 675 | /** |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 676 | * Build a portDescription from a given Ethernet port description. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 677 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 678 | * @param port the port to build from. |
| 679 | * @return portDescription for the port. |
| 680 | */ |
| 681 | private PortDescription buildPortDescription(OFPortDesc port) { |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 682 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 683 | boolean enabled = |
| 684 | !port.getState().contains(OFPortState.LINK_DOWN) && |
| 685 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 686 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 687 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 688 | return new DefaultPortDescription(portNo, enabled, type, |
| 689 | portSpeed(port), annotations); |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 690 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 691 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 692 | /** |
| 693 | * Build a portDescription from a given a port description describing some |
| 694 | * Optical port. |
| 695 | * |
| 696 | * @param port description property type. |
| 697 | * @param port the port to build from. |
| 698 | * @return portDescription for the port. |
| 699 | */ |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 700 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port, |
| 701 | OpenFlowOpticalSwitch opsw) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 702 | checkArgument(port.getDesc().size() >= 1); |
| 703 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 704 | // Minimally functional fixture. This needs to be fixed as we add better support. |
| 705 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 706 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 707 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 708 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 709 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 710 | |
| 711 | if (port.getVersion() == OFVersion.OF_13 |
| 712 | && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { |
| 713 | // At this point, not much is carried in the optical port message. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 714 | LOG.debug("Optical transport port message {}", port.toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 715 | } else { |
| 716 | // removable once 1.4+ support complete. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 717 | LOG.debug("Unsupported optical port properties"); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 718 | } |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 719 | |
| 720 | OFPortDescPropOpticalTransport desc = port.getDesc().get(0); |
| 721 | switch (desc.getPortSignalType()) { |
| 722 | // FIXME: use constants once loxi has full optical extensions |
| 723 | case 2: // OMS port |
| 724 | // Assume complete optical spectrum and 50 GHz grid |
| 725 | // LINC-OE is only supported optical OF device for now |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 726 | Set<OchSignal> signals = null; |
| 727 | if (opsw instanceof HandlerBehaviour) { |
| 728 | DriverHandler driverHandler = ((HandlerBehaviour) opsw).handler(); |
| 729 | if (driverHandler != null && driverHandler.hasBehaviour(LambdaQuery.class)) { |
| 730 | try { |
| 731 | signals = driverHandler.behaviour(LambdaQuery.class).queryLambdas(portNo); |
| 732 | } catch (NullPointerException e) { |
| 733 | signals = null; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | Frequency minFreq; |
| 738 | Frequency maxFreq; |
| 739 | Frequency channelSpacing; |
| 740 | if (signals == null || signals.isEmpty()) { |
| 741 | minFreq = Spectrum.U_BAND_MIN; |
| 742 | maxFreq = Spectrum.O_BAND_MAX; |
| 743 | channelSpacing = Frequency.ofGHz(50); |
| 744 | } else { |
| 745 | Comparator<OchSignal> compare = |
| 746 | (OchSignal a, OchSignal b) -> a.spacingMultiplier() - b.spacingMultiplier(); |
| 747 | OchSignal minOch = Collections.min(signals, compare); |
| 748 | OchSignal maxOch = Collections.max(signals, compare); |
| 749 | minFreq = minOch.centralFrequency(); |
| 750 | maxFreq = maxOch.centralFrequency(); |
| 751 | channelSpacing = minOch.channelSpacing().frequency(); |
| 752 | } |
| 753 | return omsPortDescription(portNo, enabled, minFreq, |
| 754 | maxFreq, channelSpacing, annotations); |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 755 | case 5: // OCH port |
| 756 | OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 757 | return ochPortDescription(portNo, enabled, OduSignalType.ODU4, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 758 | true, signal, annotations); |
| 759 | default: |
| 760 | break; |
| 761 | } |
| 762 | |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 763 | return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 766 | /** |
| 767 | * Build a portDescription from a given port description describing a fiber switch optical port. |
| 768 | * |
| 769 | * @param port description property type. |
| 770 | * @param port the port to build from. |
| 771 | * @return portDescription for the port. |
| 772 | */ |
| 773 | private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) { |
| 774 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 775 | |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 776 | // Use the alias name if it's available |
| 777 | String name = port.getName(); |
| 778 | List<OFCalientPortDescProp> props = port.getProperties(); |
| 779 | if (props != null && props.size() > 0) { |
| 780 | OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0); |
| 781 | if (propOptical != null) { |
| 782 | name = propOptical.getInAlias(); |
| 783 | } |
| 784 | } |
| 785 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 786 | // FIXME when Calient OF agent reports port status |
| 787 | boolean enabled = true; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 788 | SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString()); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 789 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 790 | // S160 data sheet |
| 791 | // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 792 | return omsPortDescription(portNo, enabled, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 793 | Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(100), annotations); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 794 | } |
| 795 | |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 796 | private PortDescription buildPortDescription(OFPortStatus status) { |
| 797 | OFPortDesc port = status.getDesc(); |
| 798 | if (status.getReason() != OFPortReason.DELETE) { |
| 799 | return buildPortDescription(port); |
| 800 | } else { |
| 801 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 802 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 803 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 804 | return new DefaultPortDescription(portNo, false, type, |
| 805 | portSpeed(port), annotations); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 809 | private long portSpeed(OFPortDesc port) { |
| 810 | if (port.getVersion() == OFVersion.OF_13) { |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 811 | // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12) |
| 812 | return port.getCurrSpeed() / KBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | PortSpeed portSpeed = PortSpeed.SPEED_NONE; |
| 816 | for (OFPortFeatures feat : port.getCurr()) { |
| 817 | portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); |
| 818 | } |
Thomas Vachuska | 98eda53 | 2014-10-29 17:31:02 -0700 | [diff] [blame] | 819 | return portSpeed.getSpeedBps() / MBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 820 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 821 | |
| 822 | @Override |
| 823 | public void handleMessage(Dpid dpid, OFMessage msg) { |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 824 | if (isDisabled) { |
| 825 | return; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 826 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 827 | |
| 828 | try { |
| 829 | switch (msg.getType()) { |
| 830 | case STATS_REPLY: |
| 831 | if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { |
| 832 | OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; |
| 833 | List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); |
| 834 | if (portStatsReplyList == null) { |
Madan Jampani | 84382b9 | 2016-06-22 08:26:49 -0700 | [diff] [blame] | 835 | portStatsReplyList = Lists.newCopyOnWriteArrayList(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 836 | } |
| 837 | portStatsReplyList.addAll(portStatsReply.getEntries()); |
| 838 | portStatsReplies.put(dpid, portStatsReplyList); |
| 839 | if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
Charles Chan | b3ef0db | 2016-05-03 11:11:00 -0700 | [diff] [blame] | 840 | List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); |
| 841 | if (statsEntries != null) { |
| 842 | pushPortMetrics(dpid, statsEntries); |
| 843 | statsEntries.clear(); |
| 844 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 845 | } |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 846 | } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.EXPERIMENTER) { |
| 847 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 848 | if (sw == null) { |
| 849 | LOG.error("Switch {} is not found", dpid); |
| 850 | break; |
| 851 | } |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 852 | if (sw instanceof OpenFlowOpticalSwitch) { |
| 853 | // Optical switch uses experimenter stats message to update power |
| 854 | List<PortDescription> portDescs = |
| 855 | ((OpenFlowOpticalSwitch) sw).processExpPortStats(msg); |
| 856 | if (!portDescs.isEmpty()) { |
| 857 | providerService.updatePorts(DeviceId.deviceId(Dpid.uri(dpid)), portDescs); |
| 858 | } |
| 859 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 860 | } |
| 861 | break; |
| 862 | case ERROR: |
| 863 | if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { |
| 864 | LOG.error("port mod failed"); |
| 865 | } |
| 866 | default: |
| 867 | break; |
| 868 | } |
| 869 | } catch (IllegalStateException e) { |
| 870 | // system is shutting down and the providerService is no longer |
| 871 | // valid. Messages cannot be processed. |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | private void disable() { |
| 876 | isDisabled = true; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 877 | } |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 878 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 879 | |
| 880 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 881 | } |