Jovana Vuleta | 1de6126 | 2017-06-14 11:10:29 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.hp; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 21 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 22 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 23 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
| 24 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
| 25 | import org.projectfloodlight.openflow.protocol.OFGroupMod; |
| 26 | import org.projectfloodlight.openflow.protocol.OFGroupType; |
| 27 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 28 | import org.projectfloodlight.openflow.types.OFGroup; |
| 29 | import org.projectfloodlight.openflow.types.TableId; |
| 30 | import java.util.concurrent.atomic.AtomicBoolean; |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * HP switch handshaker. |
| 35 | * Possibly compliant with all HP OF switches but tested only with HP3800. |
| 36 | */ |
| 37 | public class HPSwitchHandshaker extends AbstractOpenFlowSwitch { |
| 38 | |
| 39 | private AtomicBoolean handshakeComplete = new AtomicBoolean(false); |
| 40 | |
| 41 | |
| 42 | @Override |
| 43 | public Boolean supportNxRole() { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void startDriverHandshake() { |
| 49 | if (startDriverHandshakeCalled) { |
| 50 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 51 | } |
| 52 | startDriverHandshakeCalled = true; |
| 53 | OFFlowMod fm = factory().buildFlowDelete() |
| 54 | .setTableId(TableId.ALL) |
| 55 | .setOutGroup(OFGroup.ANY) |
| 56 | .build(); |
| 57 | |
| 58 | sendMsg(ImmutableList.of(fm)); |
| 59 | |
| 60 | OFGroupMod gm = factory().buildGroupDelete() |
| 61 | .setGroup(OFGroup.ALL) |
| 62 | .setGroupType(OFGroupType.ALL) |
| 63 | .build(); |
| 64 | |
| 65 | sendMsg(ImmutableList.of(gm)); |
| 66 | |
| 67 | handshakeComplete.set(true); |
| 68 | |
| 69 | log.info("Handshake with device {} ended", super.getStringId()); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean isDriverHandshakeComplete() { |
| 75 | if (!startDriverHandshakeCalled) { |
| 76 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 77 | } |
| 78 | return handshakeComplete.get(); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void processDriverHandshakeMessage(OFMessage m) { |
| 83 | if (!startDriverHandshakeCalled) { |
| 84 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 85 | } |
| 86 | if (handshakeComplete.get()) { |
| 87 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | } |