Merge "L3: Add eth to br-ex"
[netvirt.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / providers / openflow13 / services / arp / ArpFlowFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.arp;
10
11 import org.opendaylight.controller.liblldp.EtherTypes;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
30
31 /**
32  * Contains methods creating flow part for ARP flow.
33  */
34 public class ArpFlowFactory {
35
36     private static final String HOST_MASK = "/32";
37
38     /**
39      * Creates {@link EthernetMatch} containing ARP ether-type and the given destination MAC address
40      */
41     public static EthernetMatch createEthernetMatch(MacAddress destinationMacAddress) {
42         return new EthernetMatchBuilder().setEthernetType(
43                 new EthernetTypeBuilder().setType(new EtherType((long) EtherTypes.ARP.intValue())).build())
44             .setEthernetDestination(new EthernetDestinationBuilder().setAddress(destinationMacAddress).build())
45             .build();
46     }
47
48     /**
49      * Creates {@link ArpMatch} containing Reply ARP operation, THA and TPA for the given target
50      * address and SPA for the given sender protocol address
51      */
52     public static ArpMatch createArpMatch(ArpMessageAddress targetAddress, Ipv4Address senderProtocolAddress) {
53         return new ArpMatchBuilder().setArpOp(ArpOperation.REPLY.intValue())
54             .setArpTargetHardwareAddress(
55                     new ArpTargetHardwareAddressBuilder().setAddress(targetAddress.getHardwareAddress()).build())
56             .setArpTargetTransportAddress(new Ipv4Prefix(targetAddress.getProtocolAddress().getValue() + HOST_MASK))
57             .setArpSourceTransportAddress(new Ipv4Prefix(senderProtocolAddress.getValue() + HOST_MASK))
58             .build();
59     }
60
61     /**
62      * Creates {@link Action} representing output to the controller
63      *
64      * @param order the order for the action
65      */
66     public static Action createSendToControllerAction(int order) {
67         return new ActionBuilder().setOrder(order)
68             .setKey(new ActionKey(order))
69             .setAction(
70                     new OutputActionCaseBuilder().setOutputAction(
71                             new OutputActionBuilder().setMaxLength(0xffff)
72                                 .setOutputNodeConnector(new Uri(OutputPortValues.CONTROLLER.toString()))
73                                 .build()).build())
74             .build();
75     }
76
77 }