[ONOS-3479] Add the implementation of ArpService interface.
Change-Id: Icb473decddab711dc506b186dcf8d4543156a0ac
Showing
2 changed files
with
118 additions
and
1 deletions
| ... | @@ -17,10 +17,13 @@ package org.onosproject.vtn.table; | ... | @@ -17,10 +17,13 @@ package org.onosproject.vtn.table; |
| 17 | 17 | ||
| 18 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
| 19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
| 20 | + | ||
| 20 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
| 22 | +import org.onosproject.net.driver.DriverHandler; | ||
| 21 | import org.onosproject.net.flowobjective.Objective; | 23 | import org.onosproject.net.flowobjective.Objective; |
| 22 | import org.onosproject.vtnrsc.SegmentationId; | 24 | import org.onosproject.vtnrsc.SegmentationId; |
| 23 | 25 | ||
| 26 | + | ||
| 24 | /** | 27 | /** |
| 25 | * ArpService interface providing the rules in ARP table which is Table(10). | 28 | * ArpService interface providing the rules in ARP table which is Table(10). |
| 26 | */ | 29 | */ |
| ... | @@ -32,13 +35,14 @@ public interface ArpService { | ... | @@ -32,13 +35,14 @@ public interface ArpService { |
| 32 | * Action: set arp_operation, move arp_eth_src to arp_eth_dst, set arp_eth_src, | 35 | * Action: set arp_operation, move arp_eth_src to arp_eth_dst, set arp_eth_src, |
| 33 | * move arp_ip_src to arp_ip_dst, set arp_ip_src, set output port. | 36 | * move arp_ip_src to arp_ip_dst, set arp_ip_src, set output port. |
| 34 | * | 37 | * |
| 38 | + * @param hander DriverHandler | ||
| 35 | * @param deviceId Device Id | 39 | * @param deviceId Device Id |
| 36 | * @param dstIP destination ip | 40 | * @param dstIP destination ip |
| 37 | * @param matchVni the vni of the source network (l2vni) | 41 | * @param matchVni the vni of the source network (l2vni) |
| 38 | * @param dstMac destination mac | 42 | * @param dstMac destination mac |
| 39 | * @param type the operation type of the flow rules | 43 | * @param type the operation type of the flow rules |
| 40 | */ | 44 | */ |
| 41 | - void programArpRules(DeviceId deviceId, IpAddress dstIP, | 45 | + void programArpRules(DriverHandler hander, DeviceId deviceId, IpAddress dstIP, |
| 42 | SegmentationId matchVni, MacAddress dstMac, | 46 | SegmentationId matchVni, MacAddress dstMac, |
| 43 | Objective.Operation type); | 47 | Objective.Operation type); |
| 44 | } | 48 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | +package org.onosproject.vtn.table.impl; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 20 | + | ||
| 21 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
| 22 | +import org.onlab.osgi.ServiceDirectory; | ||
| 23 | +import org.onlab.packet.EthType.EtherType; | ||
| 24 | +import org.onlab.packet.Ip4Address; | ||
| 25 | +import org.onlab.packet.IpAddress; | ||
| 26 | +import org.onlab.packet.MacAddress; | ||
| 27 | +import org.onosproject.core.ApplicationId; | ||
| 28 | +import org.onosproject.net.DeviceId; | ||
| 29 | +import org.onosproject.net.PortNumber; | ||
| 30 | +import org.onosproject.net.behaviour.ExtensionTreatmentResolver; | ||
| 31 | +import org.onosproject.net.driver.DriverHandler; | ||
| 32 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 33 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 34 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 35 | +import org.onosproject.net.flow.TrafficTreatment; | ||
| 36 | +import org.onosproject.net.flow.instructions.ExtensionTreatment; | ||
| 37 | +import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | ||
| 38 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
| 39 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 40 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 41 | +import org.onosproject.net.flowobjective.ForwardingObjective.Flag; | ||
| 42 | +import org.onosproject.net.flowobjective.Objective; | ||
| 43 | +import org.onosproject.net.flowobjective.Objective.Operation; | ||
| 44 | +import org.onosproject.vtn.table.ArpService; | ||
| 45 | +import org.onosproject.vtnrsc.SegmentationId; | ||
| 46 | +import org.slf4j.Logger; | ||
| 47 | + | ||
| 48 | +/** | ||
| 49 | + * ArpTable class providing the rules in ARP table. | ||
| 50 | + */ | ||
| 51 | +public class ArpServiceImpl implements ArpService { | ||
| 52 | + private final Logger log = getLogger(getClass()); | ||
| 53 | + | ||
| 54 | + private static final int ARP_PRIORITY = 0xffff; | ||
| 55 | + private static final short ARP_RESPONSE = 0x2; | ||
| 56 | + private static final EtherType ARP_TYPE = EtherType.ARP; | ||
| 57 | + | ||
| 58 | + private final FlowObjectiveService flowObjectiveService; | ||
| 59 | + private final ApplicationId appId; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Construct a ArpServiceImpl object. | ||
| 63 | + * | ||
| 64 | + * @param appId the application id of vtn | ||
| 65 | + */ | ||
| 66 | + public ArpServiceImpl(ApplicationId appId) { | ||
| 67 | + this.appId = checkNotNull(appId, "ApplicationId can not be null"); | ||
| 68 | + ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); | ||
| 69 | + this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public void programArpRules(DriverHandler hander, DeviceId deviceId, | ||
| 74 | + IpAddress dstIP, SegmentationId srcVni, | ||
| 75 | + MacAddress dstMac, Operation type) { | ||
| 76 | + TrafficSelector selector = DefaultTrafficSelector.builder() | ||
| 77 | + .matchEthType(ARP_TYPE.ethType().toShort()) | ||
| 78 | + .matchArpTpa(Ip4Address.valueOf(dstIP.toString())) | ||
| 79 | + .matchTunnelId(Long.parseLong(srcVni.segmentationId())).build(); | ||
| 80 | + | ||
| 81 | + ExtensionTreatmentResolver resolver = hander | ||
| 82 | + .behaviour(ExtensionTreatmentResolver.class); | ||
| 83 | + ExtensionTreatment ethSrcToDst = resolver | ||
| 84 | + .getExtensionInstruction(ExtensionTreatmentType.ExtensionTreatmentTypes | ||
| 85 | + .NICIRA_MOV_ETH_SRC_TO_DST.type()); | ||
| 86 | + ExtensionTreatment arpShaToTha = resolver | ||
| 87 | + .getExtensionInstruction(ExtensionTreatmentType.ExtensionTreatmentTypes | ||
| 88 | + .NICIRA_MOV_ARP_SHA_TO_THA.type()); | ||
| 89 | + ExtensionTreatment arpSpaToTpa = resolver | ||
| 90 | + .getExtensionInstruction(ExtensionTreatmentType.ExtensionTreatmentTypes | ||
| 91 | + .NICIRA_MOV_ARP_SPA_TO_TPA.type()); | ||
| 92 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
| 93 | + .extension(ethSrcToDst, deviceId) | ||
| 94 | + .setEthSrc(dstMac).setArpOp(ARP_RESPONSE) | ||
| 95 | + .extension(arpShaToTha, deviceId) | ||
| 96 | + .extension(arpSpaToTpa, deviceId) | ||
| 97 | + .setArpSha(dstMac).setArpSpa(dstIP) | ||
| 98 | + .setOutput(PortNumber.IN_PORT).build(); | ||
| 99 | + | ||
| 100 | + ForwardingObjective.Builder objective = DefaultForwardingObjective | ||
| 101 | + .builder().withTreatment(treatment).withSelector(selector) | ||
| 102 | + .fromApp(appId).withFlag(Flag.SPECIFIC) | ||
| 103 | + .withPriority(ARP_PRIORITY); | ||
| 104 | + | ||
| 105 | + if (type.equals(Objective.Operation.ADD)) { | ||
| 106 | + log.debug("PrivateArpRules-->ADD"); | ||
| 107 | + flowObjectiveService.forward(deviceId, objective.add()); | ||
| 108 | + } else { | ||
| 109 | + log.debug("PrivateArpRules-->REMOVE"); | ||
| 110 | + flowObjectiveService.forward(deviceId, objective.remove()); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | +} |
-
Please register or login to post a comment