blob: dc8e63710950b4c8de51534218667a1bb4e48903 [file] [log] [blame]
Andreas Wundsam40bca242013-11-19 09:45:28 -08001//:: from generic_utils import OrderedSet
2//:: from java_gen.java_model import model
Andreas Wundsambc679f72013-08-01 22:13:09 -07003 @Override
4 public <F extends OFValueType<F>> F get(MatchField<F> field)
5 throws UnsupportedOperationException {
Yotam Harchol98af7752013-08-22 14:59:38 -07006 if (!supports(field))
7 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
8
9 OFOxm<F> oxm = this.oxmList.get(field);
10
11 if (oxm == null || !field.arePrerequisitesOK(this))
12 return null;
13
14 return oxm.getValue();
Andreas Wundsambc679f72013-08-01 22:13:09 -070015 }
16
17 @Override
18 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
19 throws UnsupportedOperationException {
Yotam Harchol98af7752013-08-22 14:59:38 -070020 if (!supportsMasked(field))
21 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support masked matching on field " + field.getName());
22
23 OFOxm<F> oxm = this.oxmList.get(field);
24
25 if (oxm == null || !field.arePrerequisitesOK(this))
26 return null;
27
28 if (oxm.getMask() == null)
29 return null;
30
31 // TODO: Make OfOxm extend Masked and just return the OXM?
32 return Masked.of(oxm.getValue(), oxm.getMask());
33 }
34
35 private static boolean supportsField(MatchField<?> field) {
36 switch (field.id) {
Andreas Wundsam40bca242013-11-19 09:45:28 -080037 //:: for id_constant in sorted(set(id_constant for _, id_constant, _ in model.oxm_map.values())):
38 case ${id_constant}:
39 //:: #endfor
Yotam Harchol98af7752013-08-22 14:59:38 -070040 return true;
41 default:
42 return false;
43 }
Andreas Wundsambc679f72013-08-01 22:13:09 -070044 }
45
46 @Override
47 public boolean supports(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070048 return supportsField(field);
Andreas Wundsambc679f72013-08-01 22:13:09 -070049 }
50
51 @Override
52 public boolean supportsMasked(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070053 return supportsField(field);
Andreas Wundsambc679f72013-08-01 22:13:09 -070054 }
55
56 @Override
57 public boolean isExact(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070058 if (!supports(field))
59 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
60
61 OFOxm<?> oxm = this.oxmList.get(field);
62
63 return oxm != null && !oxm.isMasked();
Andreas Wundsambc679f72013-08-01 22:13:09 -070064 }
65
66 @Override
67 public boolean isFullyWildcarded(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070068 if (!supports(field))
69 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
70
71 OFOxm<?> oxm = this.oxmList.get(field);
72
73 return oxm == null;
Andreas Wundsambc679f72013-08-01 22:13:09 -070074 }
75
76 @Override
77 public boolean isPartiallyMasked(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070078 if (!supports(field))
79 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
80
81 OFOxm<?> oxm = this.oxmList.get(field);
82
83 return oxm != null && oxm.isMasked();
Andreas Wundsam2fdf99d2013-10-27 06:15:47 -070084 }
Rob Vaterlaus934b4ad2013-11-12 10:08:59 -080085
Andreas Wundsam411f8512014-05-15 19:10:03 -070086 private class MatchFieldIterator extends AbstractIterator<MatchField<?>> {
Rob Vaterlaus934b4ad2013-11-12 10:08:59 -080087 private Iterator<OFOxm<?>> oxmIterator;
88
89 MatchFieldIterator() {
90 oxmIterator = oxmList.iterator();
91 }
92
93 @Override
Andreas Wundsam411f8512014-05-15 19:10:03 -070094 protected MatchField<?> computeNext() {
95 while(oxmIterator.hasNext()) {
96 OFOxm<?> oxm = oxmIterator.next();
97 if(oxm.getMatchField().arePrerequisitesOK(OFMatchV3Ver13.this))
98 return oxm.getMatchField();
99 }
100 endOfData();
101 return null;
Rob Vaterlaus934b4ad2013-11-12 10:08:59 -0800102 }
103 }
104
105 @Override
106 public Iterable<MatchField<?>> getMatchFields() {
107 return new Iterable<MatchField<?>>() {
108 public Iterator<MatchField<?>> iterator() {
109 return new MatchFieldIterator();
110 }
111 };
112 }